Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Running a command-line tool on all the files of a directory and sub-folders (batch)

Featured Replies

  • Author
  • Localization

aluigi, posted Thu Nov 24, 2016 6:46 pm (19047)


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
  • Localization

AceK, posted Thu Nov 24, 2016 11:27 pm (19051)


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
  • Localization

aluigi, posted Fri Nov 25, 2016 8:51 am (19063)


You forgot the && between the md command and unxwb.
  • Author
  • Localization

AceK, posted Fri Nov 25, 2016 9:14 am (19066)


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
  • Localization

aluigi, posted Fri Nov 25, 2016 3:30 pm (19075)


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

alwayslookin2, posted Mon May 13, 2019 4:10 am (47739)


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
  • Localization

aluigi, posted Sun May 19, 2019 2:19 pm (47828)


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
  • Localization

aluigi, posted Thu Jun 20, 2019 11:23 am (48923)


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
  • Localization

Nameless32, posted Mon Jul 01, 2019 10:25 pm (49108)


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
  • Author
  • Localization

ExtractResponseUnit, posted Tue Sep 08, 2020 3:50 pm (58575)


As far as I understand is the method you are provide here exactly what I was looking for
a long time...

I can use this for every cmd-tool even the program don't support multiple file handling by itself right?

Edit:

Code:
for /r %%G in ("*.radp") do radp2wav.exe -l %%G


Any idea why it didn't work?
  • Author
  • Localization

aluigi, posted Mon Sep 14, 2020 6:48 pm (58674)


@ExtractResponseUnit
If you use that command from console (cmd.exe) replace %% with %
  • Author
  • Localization

ExtractResponseUnit, posted Tue Sep 15, 2020 12:06 am (58689)


Thanks for your responce aluigi

Actually I tried the command in a batch file. I also tried your suggestion above.

Same error log:
Code:
usage: radp2wav  
input file does not exist
File "C:\radp2wav\test\-a" not found.
usage: radp2wav
input file does not exist
File "C:\radp2wav\test\-a" not found.


By the way: I'm a big fan of your QuickBMS tool, many thanks for inventing it.
  • Author
  • Localization

aluigi, posted Wed Sep 16, 2020 6:41 pm (58722)


As far as I can see that tool requires different arguments.
Maybe try:
Code:
for /r %%G in ("*.radp") do radp2wav.exe %%G %%G.wav


There is also a comment here regarding radp2wav on all the files from the command-line:
http://blog.gib.me/2009/06/21/prototype/comment-page-3/
  • Author
  • Localization

ExtractResponseUnit, posted Sat Sep 19, 2020 12:47 am (58764)


Code:
usage: radp2wav  


How to go round, I've tried it with different arguments it results always the same error...

I guess you got much more of experience than me so if it don't bother you I could upload the programm or
even the source code if you prefer

radp2wav.rar

  • Author
  • Localization

ExtractResponseUnit, posted Sat Oct 10, 2020 12:56 am (59191)


I hope at least one of the 12 guys who downloaded the source find a solution
  • Author
  • Localization

nofakehappy, posted Tue Feb 09, 2021 12:15 am (62078)


I think adding quotes to the %%G and %%G.wav would help.

Example: for /r %%G in ("*.radp") do radp2wav.exe "%%G" "%%G.wav"
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.