0

I want to rename an MS-word file CEEMEA & LATAM.Docx into CEEMEA & LATAM 113018.Docx which includes today's date using cmd.

Both .Docx and .Bat files are in same folder. I start with following command and getting "system cannot find the path specificied".

ren "CEEMEA & LATAM.Docx" "CEEMEA & LATAM %date%.Docx"
double-beep
  • 5,031
  • 17
  • 33
  • 41
VBAbyMBA
  • 806
  • 2
  • 12
  • 30
  • What do you mean by that it doesn't seem to be working? What result do you expect to get and what result are you getting/not getting? Is there an error message? – notjustme Nov 30 '18 at 08:13
  • `system cannot find the path specificied` error but file is there with correct name – VBAbyMBA Nov 30 '18 at 08:18
  • 1
    Run `cd ` and try your `ren` again from that directory. Or you could include the full path directly, like `ren "C:\Users\MyUser\CEEMEA & LATAM.docx" "C:\Users\MyUser\CEEMEA & LATAM %date%.docx"` – notjustme Nov 30 '18 at 08:19
  • see [here how to get a valid date string](https://stackoverflow.com/questions/7727114/batch-command-date-and-time-in-file-name/18024049#18024049) for your filename. – Stephan Nov 30 '18 at 09:07

1 Answers1

1

Usually, date variable in batch file contains:

  • The first three letters of the day today (but in some systems this does not exist).

  • The date today (formats are different per system) [numbers are usually seperated by / symbol which is interpreted as directory separator].

This way creates a datestamp with mmddyy format IN CMD:

for /f "tokens=2 delims==" %A in ('wmic OS Get localdatetime /value') do set "dt=%A"
set "YY=%dt:~2,2%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
rem M=month D=day Y=Year
set datestamp=%MM%%DD%%YY%
rem Change datestamp variable as you want.
ren "CEEMEA & LATAM.Docx" "CEEMEA & LATAM %datestamp%.Docx"

Note: The above code is only for cmd. If you want it for a batch file double the percent signs (%) of the loop variables (%A should become %%A in both two cases).

double-beep
  • 5,031
  • 17
  • 33
  • 41