Solved

Command Line Rename files with # sign in the name.

Posted on 2011-03-03
3
441 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 84

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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