Python file-io code listing current folder path instead of the specified
- by Tom Brito
I have the code:
import os
import sys
fileList = os.listdir(sys.argv[1])
for file in fileList:
if os.path.isfile(file):
print "File >> " + os.path.abspath(file)
else:
print "Dir >> " + os.path.abspath(file)
Located in my music folder ("/home/tom/Music")
When I call it with:
python test.py "/tmp"
I expected it to list my "/tmp" files and folders with the full path. But it printed lines like:
Dir >> /home/tom/Music/seahorse-gw2jNn
Dir >> /home/tom/Music/FlashXX9kV847
Dir >> /home/tom/Music/pulse-DcIEoxW5h2gz
This is, the correct file names, but the wrong path (and this files are not either in my Music folder).. What's wrong with this code?