Rename file if it has space and equal signs

June 17, 2009 at 09:20:06
Specs: Windows XP
Hello, I'm working on a batch file that is supposed to clean up a large folder of files based on certain criteria. My problem is that all the filenames have both spaces and equal signs in them. E.g.:

0001 - Sent (MsgNo=123456, MsgT=AB-C, MsgLayout=MM).xml

I've got my batch script working to the point where it will delete what it's supposed to delete if the filenames are in the proper format, but I can't figure out how to rename (with a batch script) the filenames to either delete the = and space characters or better yet replace them with something acceptable, like _.

I know there are free utilities out there that will do it for you, but the issue with those is that the batch script is supposed to run as a periodically scheduled task without any user input, and most of what I found uses a GUI to prompt the user to select the desired inputs/actions--so I can't use that.

Does anyone know how to code this?

See More: Rename file if it has space and equal signs

Report •

June 17, 2009 at 17:16:46
so do you want to rename the files or delete them? pls explain clearly. if you just want to delete them whether they have spaces and "=" or not, use del. If not, show us what's the error and your code.

GNU win32 packages | Gawk

Report •

June 17, 2009 at 22:38:43
<B>:: get = and space out of file names
:: noequal.bat  Thu 18-06-2009 10:52:51.91

@echo off & setLocal enableDELAYedexpansion

set /p work=which dir ? 
pushd !work!
if errorlevel 1 echo pushd failed && goto :eof

for /f "tokens=* delims=" %%a in ('dir/b/a-d *.txt') do (
  set str=
    for %%i in (%%a) do (
    set str=!str!%%i
  ren "%%a" "!str!"

If at first you don't succeed, you're about average.


Report •

Related Solutions

Ask Question