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?

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.

  • Sorry, no, this does not help. The bits abcd_efgh are placeholders for real-life company names and objects. They are not 4 letters long and also more or less than 3 groups. – Ralf Apr 22 '15 at 11:09
  • Oh well, that was not mentioned in the OP. Please update your question accordingly. – ozbek Apr 22 '15 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.