I am new to scripting, can some please assist me,
I have batch file that
1- Looks at the first 8 characters in the file name, creates and moves those files to new folder with first 8 characters as folder name.
2- Then looks at folder created in step 1 for next four series of character (9,10,11,12)and create and move to another subfolder with next 4 characters as folder name.
3- Then looks at folder created in step 2, for extension of every file and create and move to a new folder with extension as folder name.
For example, I have files that look like this
ABCEFGHI0703xyz.pdf
STUVWXYZ0805xyz.pptx
Move to folder
ABCEFGHI\0703\PDF
STUVWXYZ\0805\PPTX
Keeping in mind first 8 characters are random, next 4 character are year and month, and 9 types of extensions.
I am using this batch script to create these folders:-
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=C:\2BW00885"
SET "destdir=C:\2BW00885"
FOR /f "delims=" %%a IN (
'dir /b /a-d "%sourcedir%\*" '
) DO (
SET name=%%~na
SET ext=%%~xa
SET name=!name:~0,8!\!name:~8,4!\!ext:~1!
MD "!name!" 2>nul
MOVE "%sourcedir%\%%a" "!name!\" >nul
)
GOTO :EOF
This will result in creating many subfolders folders like doc, pdf, txt…
Now I want to create an archive script to search any folder called pdf within destination folders and archive it. I am using this command to archive in DOS:
winrar A -ep1 -df "C:\ ABCEFGHI\0703\PDF" " C:\ ABCEFGHI\0703\PDF\*"
-df to delete the parent folder, - ep1 and * to ignore the folder directory just the content within.
I am thinking to add this
FOR /F "DELIMS==" %%D in ('search for destination folder) DO (
"C:\Program Files\WinRAR\WinRAR.EXE" A -ep1 -df "destination.rar" "%%D"
)
Issue is destination folder directory is unknown and random depending on the first script it will create them, I need to script it in such a way that it will search for all destination folders for any folder called pdf and archive it.
Any help is greatly appreciated.
Abdul