0

I have a large number of xls files with four digits at the start of the name, a generic body, a dynamic month, year, and extraction date at the end of the filename.

For example: 9999_Generic_Name_Here_Oct_2017_05102017.xls

I need to rename these files, replacing the first four digits with a corresponding three character alphanumeric code, but keep the rest of the filename and extension the same. Each month there will be a new batch of files with a different month and different extraction date.

I have been trying to manipulate the following code to work with -like and wildcards but I have been hitting brick walls.

Import-Csv "C:\data\Rename_Files.csv" | foreach { Rename-Item -Path $_.Path -NewName $_.NewName }

In the Rename_Files.csv I have two columns with the path / original name and new name.

How do I use the above code to do this, or is there a better way ?

6
  • Possible duplicate of Renaming file name in powershell Commented Oct 4, 2017 at 21:34
  • I'm not sure how $pattern will help @VenkataramanR If I use pattern = Generic_Name_Here I still don't know how I will keep the trailing mmm_yyyy and extraction date, nor how I work into it the renaming of the first four digits. Commented Oct 4, 2017 at 22:08
  • 1
    "I have been hitting brick walls." - like what? You have the original name and .. oh you say you have the original name but I guess you don't have it? How much of it do you have and in what form? Commented Oct 4, 2017 at 23:04
  • Only "Generic_Name_Here" and ".xls" extension will be constant and known. Commented Oct 4, 2017 at 23:29
  • Consider providing an MCVE (Minimal, Complete, and Verifiable Example). Commented Oct 5, 2017 at 1:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.