obaqueiro
obaqueiro

Reputation: 982

Batch file to remove substring from list of files

Given a list of files (50,000 files)

1_data.csv
2_data.csv
3_data.csv

...

How would you rename them to 1.csv 2.csv 3.csv ... using a Batch file?

Upvotes: 2

Views: 1485

Answers (1)

marapet
marapet

Reputation: 56566

If I had to use a batch file, this works on my machine (though not tested with 50000 files):

FOR /F "tokens=1,* delims=_" %%i IN ('dir /b %~dp0*.csv') DO (
    ren %%i_data.csv %%i.csv
)

Upvotes: 3

Related Questions