Batch script to rename folders from a list

1

I am trying to write a batch script that will rename folders that are defined in a list.txt file.

FOR /F %%a IN (C:\SCRIPTS\list.txt) DO RENAME "%%a" "%%a_delete" && EVENTCREATE /T INFORMATION /L APPLICATION /SO BLERG /ID 200 /D "MOVE %%a to %%a_old

In my list.txt file, I have the full paths defined.

C:\FolderA\Folder1
C:\FolderA\Folder9
C:\FolderB\Folder8
C:\RECYCLER\S-1-5-yn8o2-0p\6n2x-0p\n\Folder99

When I run the batch file, I get an error "THE SYNTAX OF THE COMMAND IS INCORRECT."

Funny thing is, this tested fine on an in-house server (both are Windows Server 2003 R2 Standard x64 SP2)

Jerry Sweeton

Posted 2013-05-14T19:18:31.977

Reputation: 127

1Are you sure the batch files are identical on both servers? No missing spaces or extra newlines? – Nifle – 2013-05-14T19:23:31.077

I have no insight apart from my previous comment. But all my fellow sysadmins working with windows tell me that learning PowerShell is well worth it. – Nifle – 2013-05-14T19:27:15.547

You're missing an ending quote on the Description argument (/D) for EventCreate, but I'm guessing that's a paste error. ;) – Ƭᴇcʜιᴇ007 – 2013-05-14T19:39:07.583

Answers

1

try this:

FOR /F "usebackqdelims=" %%a IN ("C:\SCRIPTS\list.txt") DO RENAME "%%~a" "%%~nxa_delete"

Endoro

Posted 2013-05-14T19:18:31.977

Reputation: 2 036