Renaming a File Using Wildcards RRS feed

  • Question

  • Good morning, all -

    I'll be tackling some ETL tasks using Excel and I've discovered that our data provider does not use unique names for their files.

    We take a dump of their files and each file past the first has "_" and a number appended to the name. Like so...


    These are daily files, with each subsequent file being the one for the following day.

    My plan is to use the Last Modified date and append it in the form "YYYY-MM-DD" to the end of each file, replacing the "_#" value.

    Unfortunately, the number of files can vary as the time window for the data dump can be from one to several days. So, I'll never know how many files will be received in a dump. Probably usually a week's worth, but if there are holidays or other reasons, it may vary.

    I was thinking of using My.Computer.FileSystem.RenameFile(), but I'm at a loss on how to code in the Source filenames. I can't use a loop, because of the variable nature of the number of files.

    Any ideas?

    Thanx in advance for any assistance!

    Tuesday, January 7, 2020 5:18 PM


  • Found it.

    I just have to manipulate Dir(FileName) > "" in a Do loop.

    Gads, that was simple. Embarrassed to find out how simple...

    • Marked as answer by Adam Quark Tuesday, January 7, 2020 8:39 PM
    Tuesday, January 7, 2020 8:39 PM