Solved

Rename files in sub folders

Posted on 2014-03-30
6
870 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 54

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 54

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will show you how to use shortcut menus in the Access run-time environment.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

726 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