?
Solved

Rename files in sub folders

Posted on 2014-03-30
6
Medium Priority
?
968 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

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

for example..
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 2000 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
Independent Software Vendors: 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!

 

Author Comment

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

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

765 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