Jump to content

[PYTHON] Problem to retrieve PATH


Recommended Posts

Hello,

 

I have a little script in python that simply check if a file exists.

 

like this:

 


 

import os


def myfunction():
	jpg = "Volumes/mydrive/image.jpg"
	png = "Volumes/mydrive/image.png"

	if os.path.isfile(jpg):
    	 return jpg
    elif os.path.isfile(png):
	      return png
    else:
   		  return "none"  

 

The problem is that, if I call this script from command line works perfectly. But if I launch this same script from a Script Filter in Alfred it always give me "none".

 

What is my mistake?

 

Thanks

 

 

Link to comment
25 minutes ago, Daniele said:

if I call this script from command line works perfectly


If you run it in the correct directory, it

works.

 

You're using relative paths, so the script looks for “Volumes/...” relative to the working directory. Use “/Volumes/...” with the leading slash.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...