Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

Change filenames with command line in Windows 7

I have a bunch of files that I need to change the names, and I want to be able to do this through a command line,

What I have are

01 - Filename 1.txt
08 - This file.txt
15 - That filename.txt
27 - Randome file.txt
32 - This name is.txt

and so on.  I want to replace the leading #'s in front of the "hyphen" with the words "Folder Name" then "hyphen" and the rest stay as is.  The command I've used

REN "* - *.*" ""Folder Name" - *.*"

but what it did was putting the "Folder Name" and "hyphen" in place, and removed the rest of the text.  How could I achive what I want with this simple command?  Please advise.  Thanks.
0
swgit
Asked:
swgit
  • 3
  • 3
1 Solution
 
Evan CutlerVolunteer Chief Information OfficerCommented:
I use this...
has preview window and everything.
It's perfect for me.
Hope it's good for you too:

http://www.bulkrenameutility.co.uk/Screenshots.php

oh...it's free...I like free ;)
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
If I understand you, then this command should do the trick:

for /f "tokens=1* delims=-" %a in ('dir /b /a-d') do @ren "%a -%b" "Folder Name -%b"

Test in a sample directory first and if it doesn't work, post a screen shot.
0
 
swgitAuthor Commented:
@arcee123 - i'm still testing this, will let you know soon
@leew - please see attached screenshot screenshot.
0
Industry Leaders: 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!

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Silly mistake on my part - take out the space after %a in the ren command:

for /f "tokens=1* delims=-" %a in ('dir /a-d /b') do @ren "%a-%b" "Folder name -%b"

And in the future (I didn't mention this before), but when executing a command in a for loop and you have problems, echo it back - example, in debugging this, I simply added "echo " to see what command WOULD have been run and from there it was obvious what the problem was:

for /f "tokens=1* delims=-" %a in ('dir /a-d /b') do @echo ren "%a-%b" "Folder name -%b"
0
 
swgitAuthor Commented:
@leew - that works perfectly.  thank you.

@arcee123 - thank you for your help on this.  your utility works okay.  however, i needed something that i could include in a batch.  and the utility doesn't work so well if the leading numbers, in front of the hyphen, are not the same total group, i.e. file 1 has 1 # before hyphen, file 2 has 3 #'s, file 3 has 6 #'s, etc., there's not a way to remove them correctly without trimming other parts of the name.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Reminder - in a batch file, you need to double the % -
for /f "tokens=1* delims=-" %%a in ('dir /a-d /b') do @ren "%%a-%%b" "Folder name -%%b"
0
 
swgitAuthor Commented:
yes, i did do that from noting the instructions through "for /?" :)
0

Featured Post

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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now