Announcement

Collapse
No announcement yet.

Get file location from specified root directory

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get file location from specified root directory

    Please use the script to find file from specific folder

    Code:
    import os
    def getFileNameandTargetRootDirectory(fileName, rtDir):
        for root, dirs, files in os.walk(rtDir):
            
            for f in files:
                if f.lower() == fileName:
                    print 'Matched File Name: '+f
                    print('Path: '+os.path.join(root, f))
                    print '\n'
    def main():
        getFileNameandTargetRootDirectory('test.txt','c:\\users\\max')
    if __name__=='__main__':
        main()
    Sample Output:
    Click image for larger version

Name:	Get File's Path from a Given Root Directory.PNG
Views:	1
Size:	2.8 KB
ID:	4817

    Last edited by Purushothaman; 11-04-2016, 01:46 PM.
Working...
X