Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Copy File with Varied Name

I'm a newbie and trying to learn the language. I'm trying to run a script to copy an Excel file that is downloaded to my Dropbox folder each day with different file name based on the date, such as MyFileName 20190506.xlsx, and copy to a folder that will remain a fixed name. Since this folder I will only have one Excel file in it, which copy and paste method should I use so that it would copy an Excel extension and paste it to another location and name it MyNewFileName.xlsx?
You can use
import shutil
shutil.copyfile(src, dst)
The arguments src and dst need to be path names given as strings to the source file and the destination file. According to the documentation, dst must be the complete traget file name.
The problem I have is that the source file name will change daily. In the same folder, it will contain similar files with different names, differentiated by dates. Example: MyFileName_20190506_xxxxxx.xlsx, MyFileName_20190507_xxxxxx.xlsx, MyFileName_20190508_xxxxxx.xlsx...

I have not figured out the pattern of the _xxxxxx. I believe it's the hour, minute, and second the file is saved.
I think this may be helpful:

Then you can use something like:
if file_name.startswith("MyFileName"):
    # copy file_name to somewhere or something
Or use datetime library to get todays' date automatically.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Copy a File & Increment File Count xingfang 1 117 Oct-29-2019, 03:58 PM
Last Post: DeaD_EyE
  copy paste file and re-name it asheru93 1 343 May-24-2019, 10:43 AM
Last Post: heiner55
  Need help to copy content of the text file into the body of the email as html mohaneraj 0 622 Feb-23-2018, 05:04 PM
Last Post: mohaneraj
  read python and php from a file and copy them to their own files to execute Myersj281 10 2,472 Aug-31-2017, 07:39 AM
Last Post: Myersj281
  "are the same file" error in shutil.copy valtih 1 5,881 Aug-07-2017, 11:55 AM
Last Post: DeaD_EyE
  How to "copy" a file in python? tannishpage 4 2,994 Mar-29-2017, 10:24 AM
Last Post: tannishpage
  Copy file and rename it Filthy_McNasty 10 3,329 Feb-16-2017, 07:57 PM
Last Post: wavic

Forum Jump:

Users browsing this thread: 1 Guest(s)