user3057898
user3057898

Reputation: 11

For loop excluding defined file extensions

I'm trying to run a FOR loop in a batch file, but exclude a certain file extension from the action (as these are temporary files which will be renamed automatically by other program once they have downloaded).

My folder (which I have defined as %%landing_folder%% earlier in my batch file) could contain 6 files:

a.mov

b.wmv

c.avi

d.temporary

e.jpg

f.temporary

I want to use the command

for /f %%i IN ('dir %landing_folder% /b') do move %landing_folder%\%%i %ingest_folder% 

And have it move only the .mov, .wmv, .avi and .jpg to my %%ingest_folder%% but leave the .temporary files.

Hope I've made myself clear with what I'm trying to achieve here!

Upvotes: 1

Views: 292

Answers (3)

MC ND
MC ND

Reputation: 70933

The alternative. Instead of excluding not needed files, include needed files.

for %%x in (avi mov jpg wmv) do move "%landing_folder%\*.%%x" "%ingest_folder%"

Upvotes: 1

Aacini
Aacini

Reputation: 67216

for /f %%i IN ('dir %landing_folder% /b') do (
   if "%%~Xi" neq ".temporary" move %landing_folder%\%%i %ingest_folder%
)

Upvotes: 0

npocmaka
npocmaka

Reputation: 57262

for /f %%i IN ('dir %landing_folder% /b ^|  findstr /i /e  " .avi .mov .jpg"') do move %landing_folder%\%%i %ingest_folder% 

Upvotes: 0

Related Questions