AnsweredAssumed Answered

Interpreting "freeform" file paths?

Question asked by desertsp on Jun 29, 2018
Latest reply on Jul 5, 2018 by bixb0012

I am writing a standalone Python script which involves exporting a geodatabase table to a CSV at a location specified by the user. The script will be called via the command line, and the location is one of the arguments.

Ideally, the user would be able to specify the location in a way that's familiar to them. They are not Python coders, and the script is non-interactive so I can't present a dialog box where they select the location. Most likely, they will copy-paste a location from Windows Explorer.


There are three areas where I'm seeking assistance:


  1. How to pass the location argument if it include spaces. The below approach does not work in this scenario. Shall I enclose the arguments in some delimiter? If so, how do I parse the arguments then? Note that there are other arguments as well.
  2. How to split apart outFile into the path and the filename. These will be used by arcpy.TableToTable_conversion(), which requires these as separate parameters.
  3. How to reformat the path such that it includes proper escaping such as the double-backlashes.



# retrieve outFile from the command line (2nd argument)
outFile = sys.argv[2] # represents a filename and path
                      # example:  c:\temp\output file.csv
                      # could contain spaces, UNC paths, etc.

# split outFile into a pathway and a filename
outPath =
outFileName =

# export targetTable to the file specified in outFile
# note: targetTable is created elsewhere