Curt Black
Curt Black

Reputation: 11

Batch file to reduce length of file name

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

Upvotes: 1

Views: 2226

Answers (1)

D.Shawley
D.Shawley

Reputation: 59563

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.

Upvotes: 1

Related Questions