Solved

Rename files in sub folders

Posted on 2014-03-30
6
851 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

828 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