1

I need to rename files generated automatically, truncating a timestamp at the end.

Files are named "abcd_efgh_jklm_21.04.2015.csv", with the numbers being today's date in german culture spelling and the "abcd"-parts one or more plain text parts. German culture uses . to separate the date parts, and that makes creating the rename instruction a problem (I think). Target name should be "abcd_efgh_jklm.csv" - remove last underscore and everything following it.

A real life example for a name could be

CompanyA_Sales_Forecast_ThirdRevision_21.04.2015.csv

Here we have four word-parts, and the date part which should be zapped out. Result would be:

CompanyA_Sales_Forecast_ThirdRevision.csv

I read How does the Windows RENAME command interpret wildcards? and think I understood it mostly, but I cannot get it to work. Best I got is

ren *.csv *_.csv

creating "abcd_efgh_jklm_.csv". This is close, but I need to get the last underscore removed also. I cannot figure that out.

Any advicde?

Ralf
  • 111

1 Answers1

1

Command:

ren *.csv ????_????_????.csv

Sample:

>dir /b
abcd_efgh_ijkl_18.04.2015.csv
klmn_opqr_stuv_21.04.2015.csv
mnop_qrst_uvwx_19.04.2015.csv
yzab_cdef_ghij_20.04.2015.csv

>ren *.csv ????_????_????.csv

>dir /b
abcd_efgh_ijkl.csv
klmn_opqr_stuv.csv
mnop_qrst_uvwx.csv
yzab_cdef_ghij.csv

Hope this helps.

ozbek
  • 351