There are some vaguely or similar questions around this which I tried to piece together to the best of my ability, but not sure if I did it correctly or not.
The goal of the batch file is to look for the date on the filenames, create a folder in which the month and year of this filename's date specifies with a "01 " prefix, and move it into there. The location of the created folder will be one level above where the current log files will reside in. If a folder name already exist with the prefix "01 " but is of a different month and year, it will create one with a prefix of "02 ", and if that already exist, then it will go on to create one with a prefix of "03 " and this goes on until it doesn't find any more folders with the prefix it's trying to create that's already taken and proceeds to create a month year folder with that unused prefix.
Now the code, this is what I have right now:
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.log) do (
if exist *-10-2017*.log (
if exist 01* && not *01*.log (
set "iter="
set /p iter=01
set /a iter+=1
set f1=!%inter%" October"!
md "..\!f1!"
move "%%a" "!f1!"
) else (
md "01 October 2017" 2>nul
move "%%a" "01 October 2017"
)
)
)
That's just for October 2017, so what that should do is check log filename's date, if it has "-10-2017" anywhere in the filename, create a folder "01 October 2017" in a directory above the current and move there, assuming there doesn't exist another folder called 01 May 2017 for example or any other folder starting with the name 01(except an already created destination folder in which case the batch would just move file over without needing to create a separate folder of the same month and year but with a different prefix which is unnecessary, so I don't want "01 October 2017" and "02 October 2017" folders if there already exist a 01 October 2017, for example), it should be cool and if there is, it'll iterate until it finds an unused number, going +01 each go, and then proceed to use that as the prefix.
But that doesn't work because I am stopped at:
E:\SteamCMD\KFServer\UserLogs\11\unread\test>SETLOCALENABLEDELAYEDEXPANSION
&& was unexpected at this time.
I have already found a working piece which is where I modded this from:
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.log) do (
set f=%%a
set g=!f:~92,10!
md "!g!" 2>nul
move "%%a" "!g!"
)
)
But it just moves them into their respect date folders, where I want them to be in month year naming convention and one level up as well and also to add the 01 prefix onto the folder names for easy sorting and searching for later.....also another problem with that is if another log of the same month and year but different day comes through(for example 15-10-2017.log and 10-10-2017.log), it will be in their own folder creating more clutter when I can just group logs by month year rather than individual days....
So I am left with two choices - throw my arms in the air with this or just use the working batch but manually do the additional tasks to finish it up.....so yes, preferrably I would like to let the computer do it all for me with the least amount of effort from me, so please help me with this or correct my code and explain why it's wrong or that it must be this way....
☺
Kind Regards, New(oo)b Coder