i download file names like this.. batchengine-6099-1283555555-60054_20100910_0006.era and want to rename them to 60054_20100910_0006.era. The names change but format same, need for statement to rename of all big files ending in .era
+1
A:
I don't have access to a Windows box, but something like:
SETLOCAL EnableExtensions EnableDelayedExpansion
FOR %%I IN (batchengine-*.era) DO (
SET NAME=%%~nI
RENAME "%%I" "!NAME:~28!%%~xI"
)
ENDLOCAL
Type FOR /?
, SET /?
, and SETLOCAL /?
in the console for all of the details on the syntax. Hopefully I have something pretty close. You need to introduce new variables within the loop so that you can access the extended syntax to subscript - e.g., !NAME:~28!
selects the substring starting at character 28. The !NAME!
is a delayed expansion reference. The need for this is explained in one of the command synopsis pages.
D.Shawley
2010-09-13 15:28:57
Curt Black
2010-09-14 22:34:56
If I left the ~28!.%% with the . the file name i could see as it ran was 6066..era not 6066.era?
Curt Black
2010-09-14 22:36:16
[NAME=[batchengine1-6099-12705488236217491.GP010698_61101_20100406_000217]][NEWNAME=[NAME:~28.era]
Curt Black
2010-09-20 18:10:28
after running the batch i gave the set command. this is the result of running the set command. it looks like the newname portion is not working. the batch file cannot find the file....? this is what my batch looks like echoSETLOCAL EnableExtensions EnableDelayedExpansion FOR %I IN (batchengine*.era) DO ( SET [NAME=[%~nI]] SET [NEWNAME=[NAME:~28.era] RENAME !NAME! !NEWNAME! ) ENDLOCAL
Curt Black
2010-09-20 18:12:36
I think that I see the problem. I forgot that `%%~xI` includes the `.` from the extension. I corrected my answer with one that I actually tested this on my Windows box.
D.Shawley
2010-09-22 18:35:00