Solved

Rename files in sub folders

Posted on 2014-03-30
6
832 Views
Last Modified: 2014-03-30
Hello All,

I have a main folder: C:\mainThisCCC

within this main  folder- there are multiple subfolders
Each subfolder has multiple .xlsm files in them

Now how do i do a script or batch script so that it loops through all the files within the subfolders and adds a "_New" to all the file names
0
Comment
Question by:Rayne
  • 3
  • 2
6 Comments
 

Author Comment

by:Rayne
ID: 39965197
so fileA.xlsm is renamed to fileA_New.xlsm

for example..
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39965218
Here's a small BAT script that should do the job, it finds all XLSM files under the base directory (including in subfolders), and adds the _NEW to them.

@echo off
set BaseDir=c:\mainThisCCC
for /f "tokens=*" %%A in ('dir /b /a-d /s "%BaseDir%\*.xlsm"') do ren "%%~A" "%%~nA_new%%~xA"

Open in new window

~bp
0
 
LVL 7

Expert Comment

by:Delete
ID: 39965227
Try the below PowerShell script.  It will find all .xlsm files and rename them "Name_NEW.xlsm".  I highly recommend testing first before running it against all of your files.  I also attached the script (change the file extension from .txt to .ps1), which to run you can right click and select "Run with PowerShell".

$Source = "C:\mainThisCCC"
Get-ChildItem -Path $Source -Include *.xlsm -Recurse |ForEach-Object { $_ | Rename-Item -NewName {$_.Basename + "_NEW" + $_.Extension}}

Open in new window

FileRename.txt
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Rayne
ID: 39965235
Awesome, Bill Awesome
thank you a million :)
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 39965238
Welcome, glad that helped.

~bp
0
 

Author Comment

by:Rayne
ID: 39965243
Justin,

I apologize, When I awarded the point, I didn't see your comment. And then refreshed the page and saw your comment. Looks it happened at the same time.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now