Jaff
Jaff

Reputation: 185

passing an argument to python that is a directory location

I would like to pass an argument to a script but keep getting the following error:

Traceback (most recent call last):
  File "C:\Users\me\Desktop\s\script.py", line 58, in <module>
    for item in os.listdir(loc):
WindowsError: [Error 123] The filename, directory name, or volume label   syntax i
s incorrect: "['C:\\\\Users\\\\me\\\\Desktop\\\\s\\\\script.py', '
//Gp-002/SfX/lat/data/info/2.2.2/Info12', 'Release/2017-02-07']/*
.*"

the directory i would like to pass is this:

\\Gp-002\SfX\lat\data\info\2.2.2\Info12 Release\2017-02-07

The above directory is a valid one and opens fine in windows explorer.

I have tried the following methods to try and maybe make the directory understandable to python but to no avail.

os.path.abspath(path)
os.path.normpath(path)

Edit - This is a snippet of the code

loc = str(sys.argv)
for item in os.listdir(loc):
path = os.path.join(loc, item)
    print path

I am not sure what else to try. any help would be appreciated.

Thank you

Upvotes: 0

Views: 2789

Answers (1)

At least one problem is that you need:

    # Need to check argc is large enough
    loc = sys.argv[1]   # loc is first argument to command

not

    loc = str(sys.argv) # loc is a list, including script name and
                        # all arguments, converted to a string.

Upvotes: 2

Related Questions