0

Every month I recieve a file with changing file name. It is a csv-file but due to the export system it has a changing file name every time it gets exported. Some examples:

XXXX.Traevbme
XXXX.Traevbme.XXXX
XXX.Traevbme.csv

The "Traevbme" is the only identifier that it is the right file and there are a lot of files with a similiar structure but a different identifier. I want to push this file to our MariaDB using pandas.to_sql. But that requires a fix path and file name. I tried to renaming it via a batch file but that only catched half the files. Is there any possible solutions using the os libarary or anything similiar? We only have a restricted amount of packages available to use, so maybe more common packages are suited best.

Furthermore, all of the exported files are placed in the same folder and its important to always take the newest of the "traevbme"-file so using the change or creation date as an extra identifier but my python skills are too poor to properly code this.

Because other files are exported to the same folder with varying export cylcles only using the latest file won't work

Thanks !

Burak
  • 1
  • 1
  • What is `XXX`? Is "Traevbme" literal? – mozway Jun 23 '23 at 12:39
  • This sounds like you got shitty environment. Can you rely on file modification time? – Marcin Orlowski Jun 23 '23 at 12:42
  • Follow the top answer in the duplicate using `glob.glob('/path/to/folder/*Traevbme*')` – mozway Jun 23 '23 at 12:44
  • XXX is a random string the station the file got exported from or a random number in which the file got exported. Wdym with literal? @mozway – Burak Jun 23 '23 at 12:44
  • 1
    Unfortunately glob is not a package we have installed. The enviroment is very strict due to company restrictions and safety issues. – Burak Jun 23 '23 at 12:45
  • You can most probably mimic the behavior of `glob` using the `re` module and `os.walk`. In any case you must provide your own attempt, not request a fully coded answer from scratch. Note that `glob` is not an external module but part of the python standard library. – mozway Jun 23 '23 at 13:05
  • That is no problem, I want to learn better file handling on the way. Just giving me suggestions of methods or other ways are hekpful enough! – Burak Jun 23 '23 at 13:08
  • Ok I didnt know that. Then I will try to incorporate glob. Thank you ! – Burak Jun 23 '23 at 13:09

0 Answers0