DOS Command to Move Image Files to another Folder ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mave27
Posts: 4
Joined: 11 Aug 2015 06:48

DOS Command to Move Image Files to another Folder ?

#1 Post by mave27 » 11 Aug 2015 06:57

I have numerous image files (JPG/PNG format) stored in a folder. I would like to filter out (move to another folder) images that does NOT contain any of the following text :

_thumb ; _tiny ; _zoom ; _std

Example: image_thumb.jpg ; image_tiny.jpg ; image_zoom.jpg ; image_std.jpg ; image.jpg

Output: image.jpg should be moved to another Folder

Anyone care to share DOS Command prompt to achieve this :?:

Thanks in Advance.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: DOS Command to Move Image Files to another Folder ?

#2 Post by Squashman » 11 Aug 2015 07:20

This question also posted on Computer Hope.
http://www.computerhope.com/forum/index ... 784.0.html

mave27
Posts: 4
Joined: 11 Aug 2015 06:48

Re: DOS Command to Move Image Files to another Folder ?

#3 Post by mave27 » 11 Aug 2015 07:31

Sorry about, i am desperate to get an answer pretty soon. :|

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: DOS Command to Move Image Files to another Folder ?

#4 Post by Aacini » 11 Aug 2015 09:20

Try this:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem Define the list of parts of names to exclude
set numNames=0
for %%a in (_thumb _tiny _zoom _std) do (
   set /A numNames+=1
   set "exclude[!numNames!]=%%a"
)

for %%a in (*.jpg *.png) do (
   set "filename=%%a"
   set rightName=true
   for /L %%i in (1,1,%numNames%) do (
      for /F %%b in ("!exclude[%%i]!") do (
         if "!filename:%%b=!" neq "!filename!" set "rightName="
      )
   )
   if defined rightName move "!filename!" C:\other\folder
)

Antonio

mave27
Posts: 4
Joined: 11 Aug 2015 06:48

Re: DOS Command to Move Image Files to another Folder ?

#5 Post by mave27 » 11 Aug 2015 10:39

Thanks Antonio.

How do I execute the command?

Where should I place the source folder containing the images ? Is it root folder c:\folder ?

And what is the destination folder path ?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: DOS Command to Move Image Files to another Folder ?

#6 Post by Squashman » 11 Aug 2015 11:50

This is why I don't like seeing help on two different forums. You end up asking the same questions and now we have two competing scripts that we need to try and explain too you.

Put the batch file in the folder with all your images and execute it.

The output folder is defined in the very last line of code.

Code: Select all

if defined rightName move "!filename!" C:\other\folder

Change it to your liking but make sure that folder exists before you execute the batch file.

mave27
Posts: 4
Joined: 11 Aug 2015 06:48

Re: DOS Command to Move Image Files to another Folder ?

#7 Post by mave27 » 11 Aug 2015 12:13

Thanks - working !!

Post Reply