Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have been using the code below to rename a folder character.
The problem is the folder contains the "&" (Ampersand) I have used the caret ^ symbol in a part of the code to try and over come this problem.
setLocal EnableDelayedExpansion
Set Source=C:\Test
CD %Source%
for /f "tokens=* delims= " %%a in ('dir/b/s/ad ^| find "&"') do (
set str=%%~NXa
set str=!str:^&=x!
echo rename %%a !str!
)The Code appears to have changed "&" to "x" when it is echoed back, although when you check the folder name, it was unsuccessful.
Is anyone able to help?

It works on w2k, which is more like XP than anything I know of.
=====================================
Helping others achieve escape felicityM2

The code does work on my XP system as I have replaced other folder characters fine. It just will not work with "&" (Possibly other batch reserved symbols too.)
Any Ideas?

Why is there an "echo" before the "rename"?
Is that just for display?
Try taking it out.Also, place ["] before and after the Variables.
(Rename doesn't like spaces in names.)
If I use this on XP Pro, it changes [Me & You] to [Me x You]:setLocal EnableDelayedExpansion
Set Source=C:\Test
CD %Source%
for /f "tokens=* delims= " %%a in ('dir/b/s/ad ^| find "&"') do (
set str=%%~NXa
set str=!str:^&=x!
rename "%%a" "!str!"
)

Thanks for your Help. The "Quotes" Definately did it.
Left the Echo in on the last line by mistake when deleting a line, this stopped the hole thing from working.
All good now!

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |