Another advanced batch script request

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Another advanced batch script request

#1 Post by Andrius » 13 Jul 2012 16:48

Not sure if this is possible. I have lets say "1000" file I need to go through. These 1000 files are broken down and categorized into subfolders

eg:
Item
Item/texture


The folder "texture" will always be named "texture" however the folder called item will be randomly named "Item1, Character2,etc" So the bat script will have to utilize some sort of wildcard acceptance for drilling through the structures so that I dont have to give it the root folder name. To clarify I want the bat file to recognize that the root folders will be random but to still go into each one and look through.

eg:
Item1/texture
02393_Dave/texture


The texture files within these folders will have preset names in front of their individual names.
Meaning if the texture is for a face it might be called:
item_character_face_02393_Dave.PSD

The following filename presets will be on the files and never change:
item_character_body
item_character_face
item_character_hand
item_character_head
item_character_neck
item_character_feet


I need to go through EVERY single item and make sure that there is both a PNG file and a PSD file within the "texture" folder. If there is NO PNG within this directory I would like the PSD file copied into a container folder on my desktop "NEEDS_PNG". If the "texture" folder has both the PNG and the PSD file then skip it do nothing and move on.

Once I have the files that need processing I will run a Photoshop script (already made this) to open and resize and create the required PNG files.

I will then put these PNG files into another folder and would like a secondary batch script to go place these back into their appropriate directories. This is the tough part I think however Im hoping it's possible. Im hoping the bat file can read the texture filename (ignoring the prefixes "item_character_face" etc and reading everything after that as that will match the filename to the folder

eg:
"item_character_face_02393_Dave.PSD" will be placed in "02393_Dave/texture"


The first part of the script is the main portion I am after. I dont mind moving everything back by hand if I need to but I put it in here as a wish.

I also realize that this is pushing the limits as to what I can do with bat files and that I am asking a LOT for help... Please know that if this is indeed possible and you can assist me with this script you are saving me MANY MANY man hours and I will be forever thankful to you and this community. If some of this doesn't make sense please feel free to ask as many questions as needed as well I will do my best to answer them without giving away any confidential company or product info.

Thanks everyone!! :roll:

-Dave

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Another advanced batch script request

#2 Post by foxidrive » 13 Jul 2012 17:10

Launch this from the root folder containing all the random folder names.
You imply above that there will always be a PSD file but there may not be a PNG file associated with it, and this is the assumption my script makes.

Note that it's just as easy to create a text file containing the path\filename to the .PSD files and then a script can generate the .png files in place.

Code: Select all

@echo off
for /f "delims=" %%a in ('dir /ad /b') do (
pushd "%%a\texture"
for %%b in (*.psd) do if not exist "%%~nb.png" copy /b "%%b" "%userprofile%\desktop"
popd
)


Here's the secondary batch file (also untested).

Modify the target path and it will echo the copy commands.
If they look right then remove the 'echo' and 'pause' keywords.


Code: Select all

@echo off
for %%a in (*.png) do (
for /f "tokens=3,* delims=_" %%b in ("%%a") do echo copy /b "%%a" "c:\root folder of directories\%%~nc\texture"
pause
)

Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Re: Another advanced batch script request

#3 Post by Andrius » 16 Jul 2012 09:38

Ok this is bloody amazing! THANK YOU!!!!!!!
The first script works and the secondary one looks like its trying to work but nothing is being moved.

Where it says my.username that is a personal edit.. The script actually outputs my username I just dont like to share company PC info on forums :)

This is the output

Code: Select all

copy /b "item_character_hand_0145_moneybag.png" "C:\Users\my.username\Desktop\test\0145_moneybag\texture"
Press any key to continue...


I press a key and it moves to the next item but for each item nothing seems to actually move. I can't see anything wrong with the output however the script is another story as Im not sure what does what within it haha.

Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Re: Another advanced batch script request

#4 Post by Andrius » 16 Jul 2012 09:50

Im an idiot. I missed the "echo copy" echo. Removed and works PERFECT!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Another advanced batch script request

#5 Post by foxidrive » 16 Jul 2012 10:34

Glad to hear it.

Andrius
Posts: 37
Joined: 26 Jun 2012 15:15

Re: Another advanced batch script request

#6 Post by Andrius » 16 Jul 2012 10:40

I can't thank you guys and this forum enough. Thanksssss!!!!

Post Reply