I want to index all the USB files in a dictionary with the path to them and the name of the file. I know I'll have to use recursion to analyse all the nested folders. I'm just not sure how to list those files, and access the USB drive. I looked around and found how to write to a USB but not how to list all the files in it. Thanks in advance.
2 Answers
Sure, you can use a script like this (filling in your own path to the USB):
import subprocess
def main():
cmd = 'find /Path/To/Your/USB/Here'
p = subprocess.Popen(cmd, shell=True)
print p.communicate()[0]
if __name__ == '__main__':
main()
Now to run this, e.g. in unix/mac:
$ python nameOfThisPythonScript.py > somefile.txt
Then you should see the contents of the USB listed in somefile.txt.
find .from the USB drive itself then write this list to a file. Let me know if you'd like details on that.