Answers for "python script to recursively scan subdirectories"

0

python script to recursively scan subdirectories

AnsByIsaaco
Posted by: Guest on December-24-2020
-1

how to scan directory recursively python

import os
import sys

rootdir = sys.argv[1]

for root, subFolders, files in os.walk(rootdir):

    for folder in subFolders:
        outfileName = rootdir + "/" + folder + "/py-outfile.txt" # hardcoded path
        folderOut = open( outfileName, 'w' )
        print "outfileName is " + outfileName

        for file in files:
            filePath = rootdir + '/' + file
            f = open( filePath, 'r' )
            toWrite = f.read()
            print "Writing '" + toWrite + "' to" + filePath
            folderOut.write( toWrite )
            f.close()

        folderOut.close()
Posted by: Guest on October-09-2020

Python Answers by Framework

Browse Popular Code Answers by Language