1
I have a folder that every day thousands of log files are saved and when you need to search a file by date and time is a sacrifice.
I have to do a routine to save the current files in a folder named with the date, example (20180425), I need to do the same for the old files, only to do this I would like to create a routine that went searching for files with the current date -365 days and was saving the files with current date -365 days that would be a folder with the name (20170425).
Is there any way to save the current date -X days in a variable so I can achieve this goal?
I need to do this in a batch, it can even be an executable that can be called by placing the parameter of the number of days ago so that it returns what was the date.
To save the current date in YYYYMMDD format I use this command:
SET date=
for /F "tokens=1-3 delims=/ " %%a in ('date /T') do set date=%%c%%b%%a
To move the files I want to this folder I use this one:
forfiles -s -d -0 -m *.log -c "cmd /c move "@path" "%date%" "
Let’s see if I got it, do you want to take the file creation date and separate by folders? Example: 26-04-2018 18:06 will create a folder 20180426
– Don't Panic
Exactly that.
– Laércio Lopes
Let me see if I understand, you want for example a file with creation date 13/12/2016 to be played inside a folder called 20161213 ?
– user82136
Recovers file date as ? in name saved by file creation date ?
– SachaDee
@Cristianmota, that’s right.
– Laércio Lopes
@Sachadee, I edited the question by placing the commands I use to get the current date and move the current files to the folder.
– Laércio Lopes
Okay, hold on a second, I’ll set up the script for you.. I’m at work, before 10:00 I do it.
– user82136