path.exists() problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: path.exists() problem (/thread-11735.html) |
path.exists() problem - CAHinton - Jul-23-2018 I can't get Python to recognize a folder as existing from a batch file or command line. However it works fine within the debugger. Thanks in advance for help. here's an example of the batch file failing. The folder is not a symbolic link or on a network drive. here's the output from the script executing within the debugger:Quote:process C:\proj\python\Handle_Final_Test_Logs_V_0.0.3_23_July_2018\Test_Data\testSource here's the relevant portions of the script: import os, sys, shutil, datetime, time, argparse, keyboard from pathlib import Path # globals folders = [] # list of new folders sourceFolder = '' destFolder = '' parser = argparse.ArgumentParser(description = 'Handle Final Test Logs') parser.prog = 'Handle Final Test Logs, V0.0.2' parser.add_argument('-s', '--src', help="source folder, default current") parser.add_argument('-d', '--dest', help="dest folder, default current") parser.add_argument('-w', '--watch', default = False, help="watch source, default process source") args = parser.parse_args() # other stuff omitted # check source folder. sourceFolder = args.src if (sourceFolder == None): sourceFolder = os.getcwd() if os.path.exists(sourceFolder): if os.path.isdir(sourceFolder): pass else: print ('Source %s is not a folder' % sourceFolder) sys.exit(1) else: print ('Source %s does not exist' % sourceFolder) sys.exit(1)finally, here's the relevant portion of my json file: { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "stopOnEntry": true, "args": [ "-sC:\\proj\\python\\Handle_Final_Test_Logs_V_0.0.3_23_July_2018\\Test_Data\\testSource", "-dC:\\proj\\python\\Handle_Final_Test_Logs_V_0.0.3_23_July_2018\\Test_Data\\testDest", ] }, RE: path.exists() problem - woooee - Jul-24-2018 Use a forward slash in Python. A "\t" is translated as a tab, not as part of a directory string. RE: path.exists() problem - CAHinton - Jul-24-2018 Thanks! I belatedly forgot to menton I was using 3.7 in vscode on Windows 7. I resolved the issue by adding a space between the option and string in the command line arguments. : works: python "HFT_V_0.0.3.py" -s "C:\proj\python\HFT_0.0.3\Test_Data\testSource" doesn't: python "HFT_V_0.0.3.py" -s"C:\proj\python\HFT_0.0.3\Test_Data\testSource" |