0

I have a File that needs to be moved by my python script with shutil but I don't know where the origin location is, how do I find the origin location?

import shutil
import os

name = os.getlogin()

shutil.move(./file.foo, 'C:/Users/'+name+'/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup')

the "file.foo" is in the same directory as my python script

I have searched everywhere but I cant get a good result even with os.path and others.

  • similar question https://stackoverflow.com/questions/8858008/how-to-move-a-file-in-python – Mario Abbruscato Dec 12 '22 at 17:55
  • Possible duplicate of [How to reliably open a file in the same directory as the currently running script](https://stackoverflow.com/questions/4060221/how-to-reliably-open-a-file-in-the-same-directory-as-the-currently-running-scrip) – tripleee Dec 12 '22 at 18:00

1 Answers1

0

use shutil.move method to move a file shutil.move(src, dst, copy_function=copy2)

Recursively move a file or directory (src) to another location (dst) and return the destination. refer

source = 'path/to/file'
destination = 'path/to/file'
dest = shutil.move(source, destination, copy_function = shutil.copytree)
Sidharth Mudgil
  • 1,293
  • 8
  • 25