OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Move a file with python with a partially matching name

  • Thread starter Thread starter Jayson Roberts
  • Start date Start date
J

Jayson Roberts

Guest
Admitted newby here so forgive me if this is incredibly simple, I just can't find a solution that works.

There is a file generated in my environment every day which I want to move from one place to another. Every day the filename is appended with the day's date, so each day the filename is different. I want to automate the process of moving the file, via a cron schedule, but as I mentioned, the filename changes every day. Is there any way I can have a partial match or wildcard match with the (src)?

Current Code is:

Code:
import shutil

shutil.move("/Users/Me/LocationA/filename_20240621.txt", "/Users/Me/LocationB/nameofmyfile.txt")

This works if the src matches exactly, but I would like to figure out how to match anything that matches /Users/Me/LocationA/filename_*. Any help is appreciated!
<p>Admitted newby here so forgive me if this is incredibly simple, I just can't find a solution that works.</p>
<p>There is a file generated in my environment every day which I want to move from one place to another. Every day the filename is appended with the day's date, so each day the filename is different. I want to automate the process of moving the file, via a cron schedule, but as I mentioned, the filename changes every day. Is there any way I can have a partial match or wildcard match with the (src)?</p>
<p>Current Code is:</p>
<pre><code>import shutil

shutil.move("/Users/Me/LocationA/filename_20240621.txt", "/Users/Me/LocationB/nameofmyfile.txt")
</code></pre>
<p>This works if the src matches exactly, but I would like to figure out how to match anything that matches /Users/Me/LocationA/filename_*. Any help is appreciated!</p>
 

Latest posts

Online statistics

Members online
0
Guests online
3
Total visitors
3
Top