I am looking for help with a batch script which can help me remove specific subfolders from all directories that are in the same place as the batch file. But instead of deleting everything in the subdirectory, I want to move the contents outside of the subdirectory first.
To elaborate, I receive files which are always nested inside folders with a very specific pattern:
- Every request I receive is in a uniquely named folder which follows no specific pattern (the Job Folder).
- Inside every Job Folder, there are two things:
- A folder denoting the language the file is in (Lang Folder).
- An xml file named "Manifest.xml" which contains instructions and metadata.
- There is a folder inside every Lang Folder denoting the brand of the file (Brand Folder).
- Inside every Brand Folder is a random assortment of subfolders containing JSON files with various degrees of nesting inside different subfolders.
So a typical request would contain the following structure: Job Folder/Lang Folder/Brand Folder/...
And I want to transform all folders to follow this structure: Job Folder/Brand Folder/...
You can see an example below of how the folder structure currently looks and how I would like it to look in the end.
Structure of the folders and files before running the batch file:
- French_Job1373
- French
- BrandA
- Subfolder
- Example.json
- Subfolder
- BrandA
- Manifest.xml
- French
- German_Job1374
- German
- BrandB
- Subfolder1
- Subfolder2
- Subfolder3
- ExampleFile.json
- Subfolder3
- Subfolder2
- Subfolder1
- BrandB
- Manifest.xml
- German
- Japanese_Job1375
- Japanese
- BrandC
- Subfolder1
- Example.json
- Subfolder1
- BrandC
- Manifest.xml
- Japanese
- Korean_Job1376
- Korean
- BrandC
- Subfolder1
- Subfolder13
- ExampleSrc.json
- Subfolder13
- Subfolder1
- BrandC
- Manifest.xml
- Korean
Structure of the folders and files as it should be after running the batch file:
- French_Job1373
- BrandA
- Subfolder
- Example.json
- Subfolder
- Manifest.xml
- BrandA
- German_Job1374
- BrandB
- Subfolder1
- Subfolder2
- Subfolder3
- ExampleFile.json
- Subfolder3
- Subfolder2
- Subfolder1
- Manifest.xml
- BrandB
- Japanese_Job1375
- BrandC
- Subfolder1
- Example.json
- Subfolder1
- Manifest.xml
- BrandC
- Korean_Job1376
- BrandC
- Subfolder1
- Subfolder13
- ExampleSrc.json
- Subfolder13
- Subfolder1
- Manifest.xml
- BrandC
I would like to have a batch file which essentially removes the Lang Folder, pulling everything from inside the Lang Folder one level up.
Following should be taken into consideration:
- The file
Manifest.xml
should not be touched. It should remain inside the Job Folder level. - Everything from the Brand Folder level including the Brand Folder itself should be moved one level up (to the same level where the file
Manifest.xml
is). - The Language Folder (which at this point should be empty) should be deleted.
- There is a finite list of possible languages after which the Lang Folder is named. If required to specify all possible languages in the batch file, I would like the option to add new languages to the list in the future.
So far, I have managed to get the batch file below to work as expected, but I need to run as many times as there are Job Folders and I have to place it inside the Language Folder to have it work as expected. If I place it anywhere else, it just deletes the Lang Folder with all of its contents and does not move anything. I am looking to have the batch file check all folders that are next to it and perform the operation as many times as needed.
What I have so far:
@echo off
if -%1==- echo No parameters! You must add %%P parameter! & pause & goto :EOF
cd /d %1
move * ..
for /d %%f in (*) do move %%f ..
cd ..
"%commander_path%\totalcmd.exe" /o /s %1\..
rd %1
FOR /d /r . %%d IN (Russian) DO @IF EXIST "%%d" rd /s /q "%%d"
FOR /d /r . %%d IN (French) DO @IF EXIST "%%d" rd /s /q "%%d"
FOR /d /r . %%d IN (German) DO @IF EXIST "%%d" rd /s /q "%%d"
FOR /d /r . %%d IN (Japanese) DO @IF EXIST "%%d" rd /s /q "%%d"