Solved! Go to Solution.
import os testdir = "C:\\test" for dir in os.listdir(testdir): dir = os.path.join(testdir,dir) if os.path.isdir(dir): print dir + " is a directory" elif os.path.isfile(dir): print dir + " is a file" else: print dir + " is not a directory"
import os prompt = "Please enter the directory path: " dirPath = raw_input(prompt) listing = os.listdir(dirPath) fileName = "C:\FileList.txt" s = "??" fileList = open(fileName, "w+") fileList.write(dirPath + "\n\n") fileList.write("DIRECTORIES:\n") for dir in listing: if os.path.isdir(dir): fileList.write(dir + "\n") s += dir.join("\n") fileList.write(s + "\n") listing = os.listdir(dirPath) fileList.write("\n") fileList.write("FILES:\n") for file in listing: if os.path.isfile(file): fileList.write(file + "\n") fileList.close() prompt = "File list created at: " + fileName + "\nPress Enter" ok = raw_input(prompt)
import os os.getenv("PYTHON")
fileName = "C:\FileList.txt"
Yup, definitely some system or environment setting throwing a wrench in things. What does this return?import os os.getenv("PYTHON")
Don't use backslashes in paths. It escapes the next character.
In the PythonWin interactive window[...]
s += "\n".join(dir)