Bottom Page

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

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?
Quote
#2
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.
Quote
#3
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.
Quote
#4
I think this may be helpful:
https://stackoverflow.com/questions/3207...-directory

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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do I copy files faster with python? steckinreinhart619 3 129 Today, 08:36 AM
Last Post: DeaD_EyE
  Making a generalised CSV COPY script in Python Sandy7771989 3 156 Jul-05-2019, 11:02 PM
Last Post: Larz60+
  To Copy text values to Excel using Python ksasi2k3 15 771 Jun-26-2019, 01:23 PM
Last Post: ksasi2k3
  copy paste file and re-name it asheru93 1 222 May-24-2019, 10:43 AM
Last Post: heiner55
  Copy List Structure leoahum 2 204 Mar-22-2019, 05:40 PM
Last Post: leoahum
  Do objects get their own copy of the class methods? Charles1 1 248 Feb-02-2019, 04:40 PM
Last Post: ichabod801
  How can I copy specif cell from one csv to another csv zoe1111 5 317 Jan-13-2019, 11:24 PM
Last Post: ichabod801
  code copy from pep-3134 bluefrog 1 398 Aug-26-2018, 04:35 PM
Last Post: snippsat
  copy list into variable poroton 1 450 Aug-10-2018, 07:19 AM
Last Post: Gribouillis
  get all .exe files from folder and subfolder and then copy them to another location evilcode1 1 593 Jul-20-2018, 03:39 PM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)