What's wrong with this Python file-read test?
import os
import sys
fileList = os.listdir(sys.argv[1])
count = 0
for file in fileList:
try:
count += 1
print os.path.isfile(file)
if os.path.isfile(file)
print "File >> " + file
else
print "Dir >> " + file
except err:
print "ERROR: " + err
print ">> in file: " + file
gives:
File "test.py", line 10 if os.path.isfile(file) ^ SyntaxError: invalid syntax
why?
enumerate. - user395760list(enumerate(["a", "b"]))returns[(0, 'a'), (1, 'b')]. So you would need to use the count variable. You could usefor count, file in enumerate(fileList):- Nonecontinue. It's also a matter of using the existing solution instead of doing it yourself. And how is this "more complicated"? - user395760