0

Not sure how to phrase the question.

What I'm trying to do is print the currently opened directory/file name using an exe built with command "pyinstaller -F main.py" even if that directory/file is outside of where the .exe is located.

My current process of elimination has been:

First I tried

print(os.path.basename(sys.argv[0]))

but this simply prints the directory where the exe is located and not when I access a new one. So I figured its a problem with where the exe is located, so if I move it to a lower level directory it would tell me files opened out of that directory. Ie: if I move main.exe to C:\Users\User , it would tell me files opened out of User.

So I tried this:

dir_path = os.path.dirname(os.path.realpath(sys.executable))
print(dir_path) #where exe is located now
track = 0
n_path = ''
# rudimentary just for testing purposes
for i in dir_path:
    n_path += i
    if i == "\\":
        track += 1
    if track == 3:
        break
print(n_path)
src_path = dir_path
dst_path = n_path
shutil.move(src_path, dst_path)

But once I do this I get permission denied errors. I've tried a couple other methods which are just some code added to this snippet like os.close(src_path_handle) but that doesn't work either.

So I just want to figure out if what Im trying to achieve is possible and how might I go about figuring out how to do this?

(to clarify, I want to print any accessed directory using an exe)

Notmyname
  • 65
  • 1
  • 1
  • 5
  • Permission denied error is most likely because you are performing this operation on the C drive which Is the OS directory. I think there are flags available that would let you do it – Shisui Otsutsuki Sep 02 '22 at 11:47
  • Have a look [here](https://stackoverflow.com/questions/41910583/errno-13-permission-denied-python) – Shisui Otsutsuki Sep 02 '22 at 11:49

0 Answers0