ZenHAX
https://zenhax.com/

Running a command-line tool on all the files of a directory and sub-folders (batch)
https://zenhax.com/viewtopic.php?f=4&t=3434
Page 1 of 1

Author:  aluigi [ Thu Nov 24, 2016 6:46 pm ]
Post subject:  Running a command-line tool on all the files of a directory and sub-folders (batch)

Just a quick tutorial for who wants to run any command-line tool in batch mode on all the files of a folder instead of running it manually for every single file.
So, for example, if you have 1000 fsb or xwb archives and you want to run fsbext and unxwb on them with a single command, that's the trick.

Create a file called file.bat in the target folder containing the following syntax:
Code:
for /r %%G in ("*") do COMMAND %%G

Where COMMAND must be replaced with the full command-line tool and argument you want to run, for example
Code:
for /r %%G in ("*.xwb") do unxwb -l %%G
As you can see I replaced also the * (for ANY file) with *.xwb for running the tool only on the files with XWB extension.
It's even possible to run multiple commands in sequence by appending &&:
Code:
for /r %%G in ("*.xwb") do md %%G_output && unxwb -d %%G_output %%G


You can also use this method from the cmd.exe console, you have only to replace %%G with %G.

Please note that the G in %%G can be anything, so if you prefer %%a you can use it too.

This topic is for anyone who wants to add other methods, tips, suggestions, examples and questions.
It's something that is often asked by users so it's very important to have a topic about it.

P.S.: a good link about this topic http://ss64.com/nt/for_r.html

Author:  AceK [ Thu Nov 24, 2016 11:27 pm ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

Thanks for the insight.

When I tried the last script, I get unsatisfactory results sadly.

Image

Each .xwb file that gets applied with unxwb.exe results in a 00000000.wav file, so it would lead to override requests. I tried to apply this batch to see how it goes, and it results in a request for an override to the new "00000000.wav" files, without change in file name (or replicate using the original file name with the new .wav extension).

Code:
for %%G in (*.xwb) do unxwb.exe "%%G"

Author:  aluigi [ Fri Nov 25, 2016 8:51 am ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

You forgot the && between the md command and unxwb.

Author:  AceK [ Fri Nov 25, 2016 9:14 am ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

Ah okay, tried it now and it gave 00000000.wav files in their respective generated folders as needed:

Code:
for %%G in ("*.xwb") do md %%G_output && unxwb.exe -d %%G_output %%G


Now to try and figure how to rename the files inside the folder to match with the folder name...

Thanks aluigi <3!!!

Edit: Got everything done for this rip, working on .pos modifications. This may seem off-topic, but do you know if unxwb will support loop pointer extraction in the future? The ADPCM format seems to play fine (in P4 Ultimax's case, offset 0xA4 ~ 0xA7 = Loop Start... offset 0xA8 ~ 0xAB = Loop Length starting from string "WBND"). I haven't looked at the other format types of .xwb files out there, but I'd guess that it would be different.

Author:  aluigi [ Fri Nov 25, 2016 3:30 pm ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

No, there will be no support for these loops.
It extracts files from the XWB archives, that's it.

Author:  alwayslookin2 [ Mon May 13, 2019 4:10 am ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

aluigi wrote:
No, there will be no support for these loops.
It extracts files from the XWB archives, that's it.


I found some batch code on stackoverflow. Is there a way to run this code, and have it extract to the folder the .tex file is in (even if it ends up overwriting the file).

Currently this script asks if I want to create a new folder for every file with a Y/N question which is difficult when there are thousands of files to process, and it would create too many folders rather than leaving the folder/file structure as it is (I found out about the -Y option but it is still preferable to just overwrite the files)

Code:
for /R %%i in (*.tex) DO quickbms.exe -o script.bms "%%~i" "%%~dpni"

Author:  aluigi [ Sun May 19, 2019 2:19 pm ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

I just reply on the fly so I may be wrong.
quickbms has 2 options, -d and -D that automatically create folders for the destination files.
Not sure if that's what you mean but you can try.

Author:  aluigi [ Thu Jun 20, 2019 11:23 am ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

Two examples about how to run offzip on multiple files in the current folder:
Code:
for %%G in ("*.ext") do md %%G_output && offzip -a %%G %%G_output

Code:
for %%G in ("*.zip") do md %%G_output && offzip -a -z -15 -Q %%G %%G_output

I didn't use /r because it forces the command to run on all the extracted files too... yeah very useless and annoying in most cases, except if you specify a different output folder:
Code:
for /r %%G in ("*") do md c:\output%%~pG%%~nG%%~xG && offzip -z -15 -Q -a %%G c:\output%%~pG%%~nG%%~xG


If you are interested in the additional syntax for %%G:
Code:
%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file


P.S.: my original example in the first post missed the "&&" for some unknown reasons, now fixed.

Author:  Nameless32 [ Mon Jul 01, 2019 10:25 pm ]
Post subject:  Re: Running a command-line tool on all the files of a directory and sub-folders (batch)

aluigi wrote:
Two examples about how to run offzip on multiple files in the current folder:
Code:
for %%G in ("*.ext") do md %%G_output && offzip -a %%G %%G_output

Code:
for %%G in ("*.zip") do md %%G_output && offzip -a -z -15 -Q %%G %%G_output

I didn't use /r because it forces the command to run on all the extracted files too... yeah very useless and annoying in most cases, except if you specify a different output folder:
Code:
for /r %%G in ("*") do md c:\output%%~pG%%~nG%%~xG && offzip -z -15 -Q -a %%G c:\output%%~pG%%~nG%%~xG


If you are interested in the additional syntax for %%G:
Code:
%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file


P.S.: my original example in the first post missed the "&&" for some unknown reasons, now fixed.


you can use " /f " with some tricks...


for /f "delims=* tokens=*" %%a in ('dir /b /s *.zip *.rar') do ......

you can set a folder or concatenate another commands too

for /f "delims=* tokens=*" %%a in ('dir /b /s *.zip *.rar ^| findstr "english"') do echo %%~nxa

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/