1

i have more than 200 files in a folder

JOB1_CostReport.xlsx
JOB2_CostReport.xlsx
JOB4_CostReport.xlsx
JOB3_CostReport.xlsx
JOB7_CostReport.xlsx
....
JOB196_CostReport.xlsx
JOB200_CostReport.xlsx

I want to reanme all these files with a suffix like this : JOB1_CostReport_Aug_2020.xlsx

I have tried : Get-ChildItem | rename-item -NewName { $_.Name + "_Aug_2020" }

the result was like this :

JOB1_CostReport.xlsx_Aug_2020
JOB2_CostReport.xlsx_Aug_2020
JOB4_CostReport.xlsx_Aug_2020
JOB3_CostReport.xlsx_Aug_2020
JOB7_CostReport.xlsx_Aug_2020
JOB196_CostReport.xlsx_Aug_2020
JOB200_CostReport.xlsx_Aug_2020

what I want is more like :

JOB1_CostReport_Aug_2020.xlsx
JOB2_CostReport_Aug_2020.xlsx
JOB4_CostReport_Aug_2020.xlsx
JOB3_CostReport_Aug_2020.xlsx
JOB7_CostReport_Aug_2020.xlsx
JOB196_CostReport_Aug_2020.xlsx
JOB200_CostReport_Aug_2020.xlsx

3 Answers 3

2

try this:

Get-ChildItem | rename-item -NewName { $_.BaseName + "_Aug_2020" + $_.Extension}
Sign up to request clarification or add additional context in comments.

Comments

1

Besides @Brumor's excellent answer in powershell, and as you have tagged this question Cmd, so try this in a batch file:

for %%a in (*) do ren "%%~a" "%%~na_Aug_2020%%~xa"

PS when running in Cmd replace the %% to %.

Comments

1

All the given answers rename the files multiple times(rename the file for 100 times if there are 100 files in the folder and it will add the prefix 100 times).

Use the following command in cmd:

for /f "tokens=*" %a in ('dir /b') do ren "%a" "%%~na_Aug_2020%%~xa"

Comments

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.