Solved

Command Line Rename files with # sign in the name.

Posted on 2011-03-03
3
413 Views
Last Modified: 2012-05-11
Some dufus named a bunch of files with #1, #2, #3 and it makes working with them programmatically a bit challenging. My DOS skills have gone really dull and they were not exactly ginsu to begin with.


How do I rename all files with this naming convention:

web_4.2. 2006 Aloha #5.JPG

to

web_4.2. 2006 Aloha 5.JPG (be nice to rename the " " to underscores too but I think I can figure dat one out...)


I tried: ren *#*.* to *.* but that didn't work ( no kidding ) but I had to try it.
0
Comment
Question by:rawinnlnx9
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 35031343
Something like this? It will currently only echo the rename commands it would otherwise run; remove the capitalized ECHO to run it for real:
@echo off
setlocal enabledelayedexpansion
for %%a in (*.jpg) do (
  set OldName=%%~nxa
  set NewName=!OldName:#=!
  set NewName=!NewName: =_!
  if /i not "!OldName!"=="!NewName!" ECHO ren "%%a" "!NewName!"
)

Open in new window

0
 
LVL 9

Author Comment

by:rawinnlnx9
ID: 35031447
Excellent!!! I love this place. I spend my time helping others and they spend their time helping me. What a perfect system.

Thanks a bunch. All points are yours for sure.
0
 
LVL 9

Author Closing Comment

by:rawinnlnx9
ID: 35031453
The dude is an expert for certain.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

18 Experts available now in Live!

Get 1:1 Help Now