can't replace & in a batch rename of files

September 23, 2010 at 04:38:16
Specs: Windows XP
I'm trying to change the name of files to remove the & sign and replace it with the word and for literally thousands of files.. this code has always worked for me in the past and seems ok with pretyt much anything i try, except & where nothing seems to happen


@echo off
setlocal enabledelayedexpansion
for %%j in (*) do (
set filename=%%~nj
set filename=!filename:&=and!
if not "!filename!"=="%%~nj" ren "%%j" "!filename!%%~xj"
)

i'm not really sure what else to try.. basically i want to remove all & and replace with "and"

all # and replace with numbers etc to remove all the funny signs so i can upload folders into a sharepoint.

thanks a million in advance
manda


See More: cant replace & in a batch rename of files

Report •


#1
September 23, 2010 at 05:18:29
forgot to say

i've tried putting it in contect (it's mostly in files called H&S" "health&safety" and "P&ID"

so hoped that P*ID could do it, also tried putting the & in inverted commas etc

if it makes it any easier..... 99% of my workload would be gone by just changing the H&S, P&ID etc files..

i've separated all files with the ampesand in out inot a separate folder now.

thanks again
manda


Report •

#2
September 23, 2010 at 05:21:27
UNTESTED. Shooting from the hip.

Change this:

set filename=!filename:&=and!

to this:

set filename=!filename:^&=and!


=====================================
Helping others achieve escape felicity

M2


Report •

#3
September 23, 2010 at 05:49:10
fankoooooo
worked a treat

you are a star


Report •

Related Solutions


Ask Question