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
Solved

Command Line Rename files with # sign in the name.

Posted on 2011-03-03
3
434 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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