6

I have a script that I run from a GUI. The GUI is run in ArcGIS and basically, the first parameter can accept a file already embedded in ArcMap or I can use a explorer dialogue to navigate to the file locations.

If I use the option to choose the embedded file, then it only returns the file name:

i.e. 'SOIL_LINES'

If I use the navigation option, then it returns the file name and it's fill path:

C:\SOIL\SOIL_LINES.shp

I would like to test the input parameter to see if the file is just the file name or if it also includes the full path. I eventually need to parse out the path in option 2 to isolate the file name itself. That part I have figured out already.

I've used os.path.isfile but that will return the file in both scenarios because they are both considered a file.

Thanks, Mike

3 Answers 3

5

In addition to isabs() mentioned in another answer to test if it is a full path, you can use os.path.basename() and os.path.dirname() to find just the filename or just the directory path. No need to parse them out yourself.

There's lots of cool stuff in that library. I recommend reading the full documentation on it-- it's not long. http://docs.python.org/2/library/os.path.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. This pointed me in the right direction and I've managed to complete the test :)
4

You could probably use os.path.isabs for this ...

Comments

2

The pathlib alternative would be to do:

$ filename = "my/path/file.py"
$ Path(filename).name == filename
False
$ filename = "file.py"
$ Path(filename).name == filename 
True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.