Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
path.exists() problem
#1
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.
Error:
C:\proj\python\Handle_Final_Test_Logs_V_0.0.3_23_July_2018>Handle_FTLogs_TestProcessor C:\proj\python\Handle_Final_Test_Logs_V_0.0.3_23_July_2018>python "HFT_V_0.0.3.p y" -s "C:\proj\python\Handle_Final_Test_Logs\Test_Data\testSource" -d "C:\proj \python\Handle_Final_Test_Logs\Test_Data\testDest" Source C:\proj\python\Handle_Final_Test_Logs\Test_Data\testSource is not a folde r
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
23_07_2018_16:45:03 create folder C:\proj\python\Handle_Final_Test_Logs_V_0.0.3_23_July_2018\Test_Data\testDest\H180455
23_07_2018_16:45:03 move file H180455_2018_0718_165519_event_log.sorted.csv to folder H180455
23_07_2018_16:45:03 move file H180455_2018_0718_165519_periodic_log.sorted.csv to folder H180455
23_07_2018_16:45:03 create folder C:\proj\python\Handle_Final_Test_Logs_V_0.0.3_23_July_2018\Test_Data\testDest\H180456
23_07_2018_16:45:03 move file H180456_2018_0718_162618_event_log.sorted.csv to folder H180456
23_07_2018_16:45:03 move file H180456_2018_0718_162618_periodic_log.sorted.csv to folder H180456
check H180455
H180455_2018_0718_165519_event_log.sorted.csv
H180455_2018_0718_165519_periodic_log.sorted.csv
check H180456
H180456_2018_0718_162618_event_log.sorted.csv
H180456_2018_0718_162618_periodic_log.sorted.csv

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",

            ]
        },
Reply
#2
Use a forward slash in Python. A "\t" is translated as a tab, not as part of a directory string.
Reply
#3
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,149 Sep-09-2021, 01:25 PM
Last Post: Yoriz
Exclamation Path sacn problem lucky511 10 3,783 Jun-24-2021, 12:09 PM
Last Post: Axel_Erfurt
  path.exists returning True when it shouldn't natha18 0 1,456 Sep-21-2020, 01:04 PM
Last Post: natha18
  problem about maze path finder Simurg 2 1,905 Aug-16-2020, 01:10 PM
Last Post: Simurg
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,139 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  Problem with reading a path gkiller007 30 22,673 Jan-05-2019, 10:09 PM
Last Post: snippsat
  Anaconda problem about path Leloup 1 8,051 Nov-23-2018, 05:14 PM
Last Post: Larz60+
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,670 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Problem with absolute path to file (Mr.Stickman Problems) SheeppOSU 3 6,163 Jun-26-2018, 10:05 AM
Last Post: Larz60+
  Problem in a path finding algorithm (counter is not working) Kowalski 3 3,219 Feb-05-2018, 01:23 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020