Home > OS >  List all directories in a folder and pass those each to another script
List all directories in a folder and pass those each to another script

Time:06-14

I am working on a deduplication script and decided it would be easier to hand it a parent directory and let it work on each child folder, rather than doing each folder separately. I was assuming this was going to be simple, but I can't seem to get this to work properly. This is roughly what I have now:

SET base_folder=%1

for /d %%d in ("%1\*") do (
    set current_dir=%%d
    -- here is where I want to call my script with current_dir as the %1 --
)

CodePudding user response:

You're don't appear to be using base_folder, so there's no need to set it.

You don't need to set current_dir; just use %%d directly. If the script you want to use to process each directory is also a batch file, you'll need to CALL it:

for /d %%d in ("%1\*") do (
    CALL myotherscript "%%d"
)

See SS64 on CALL.

  • Related