0

I'm trying to set a daily process to locate a file, rename it and insert the previous date in the file name. I want the file to be named "Filename_MMddyyyy.csv" with MMddyyyy being the previous day. I managed to rename the file but I'm a total noob and I don't know how to calculate the previous day date and insert it in the file name. Here is what I managed to do so far:

cd C:\

set file= \\pathtothefile\*.CSV
if exist %file% (
    ren \\pathtothefile\*.CSV Filenamehere_%date:~10,4%%date:~7,2%%date:~4,2%.CSV
)
Dave M
  • 4,494
  • 21
  • 30
  • 30
  • 1
    Drop the antiquated command prompt and [use powershell](https://serverfault.com/questions/776666/rename-files-to-add-date-modified-to-filename-with-windows-cmd-or-simple-txt/1018749#1018749) – Gerald Schneider Apr 20 '21 at 15:19

1 Answers1

0

I can offer you perl solution, if you have one.

#!env perl

$FN = "Filename_11223333.csv";

$_ = $FN;
m/(.*)_(..)(..)(....)\.csv/;
$a = $1; # FN
$b = $2; # MM
$c = $3; # dd
$d = $4; # yyyy
$c = $c-1;

$FN2="$b$c$d";

system("ren "."$FN"." "."$FN2");

that will run following command:

$ ren Filename_11223333.csv 11213333
tansy
  • 141
  • 3