I know there exist quite a lot of script out there to do such tasks, but I couldn’t find any that can do what I am specifically searching for…
I am looking for a script that could read all files I have in a folder, separate all “_” and put them into subfolders.
The structure of the filenames look like this:
Clothes_Man_Citizen_Pants.png
Clothes_Man_Citizen_Top.png
The script would then create subfolders with this structure:
Clothes/Man/Citizen/Clothes_Man_Citizen_Pants.png
Clothes/Man/Citizen/Clothes_Man_Citizen_Top.png
I am asking this because I couldn’t find any photoshop script to export nested groups in photoshop… So I’m exporting all the layers into a folder and would like to create the nested folder structure with a batch or something like that.
Thanks for your answers !
EDIT:
In pseudo-code it would look like this:
InitialName = Clothes_Man_Citizen_Pants.png;
TempName = Clothes_Man_Citizen_Pants.png;
While (There is an underscore in TempName) {
-> Read name until underscore
-> Create folder with name
-> Get into created folder
-> Remove part from TempName
-> Repeat
}
When there are no underscores anymore in TempName paste the file with InitialName in the last created folder.
2
Answers
This takes the file name, replaces the underscores into backslashes and uses the generated string as a folder hierarchy to do all the operations.
The
setlocal / endlocal
are needed to handle the posibility of exclamations (!
) in the name/path of files. If it will never be the case, delayed expansion (needed in the code) can be enabled from the start and the previous code can be reduced tonote: in both codes you can find
%"%
, that is not needed. It is included only to correct the syntax hightlighting that fails because the""
in the code.Try this:
EDIT: The original code had a bug. It is fixed now…
This method will fail if the file names may include spaces, comma or semicolon. It also remove exclamation marks.