Search code examples
variablesbatch-filedirectorymove

Batch Script, set multiple directories under variable?


Im building a file sorting script and I want it to search through multiple source folders using the same variable. How is this done?

Small example;

@echo off
SET "sourcedir=%a%"

SET "softdir=P:\=Programs"

SET "%a%=C:\downloads1"
SET "%a%=S:\downloads2"
SET "%a%=O:\downloads3"

:progs
IF EXIST "%a%\*.rar" (MOVE /-y "%a%\*.rar" "%softdir%\" )
IF EXIST "%a%\*.exe" (MOVE /-y "%a%\*.exe" "%softdir%\" )
IF EXIST "%a%\*.iso" (MOVE /-y "%a%\*.iso" "%softdir%\" )

Solution

  • that's, what for will do for you:

    for %%i in ("c:\downloads1" "s:\downloads2" "o:\downloads") do (
      echo processing %i ...
      if exist "%i\*.rar (MOVE /-y "%i\*.rar" "%softdir%\" )
    )