Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: DOS Command to Move Image Files to another Folder ?

11 Aug 2015   #1

64 bit
DOS Command to Move Image Files to another Folder ?

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.

My System SpecsSystem Spec
13 Aug 2015   #2

Windows 7 Professional x64, RHEL 5,6,7

If I were you, I would seriously consider using something a bit more powerful like perl / powershell / VB etc.
Having said that, here is a quick and dirty way of doing this:

mkdir c:\temp\foo
move *_*.jpg c:\temp\foo
move *.jpg c:\temp\bar
move c:\temp\foo\* .
rmdir c:\temp\foo

this creates a folder (c:\temp\foo)
moves all jpg files which include an underscore into that folder
moves all the remaining jpg files into a folder (c:\temp\bar) - change this to your desired output folder
moves the underscored files back into the current folder
removes c:\temp\foo

This assumes the following:
you are running it from the directory containing the files and have permissions to write to that directory
you don't want any files with underscores rather than a set list of unwanted strings
that c:\temp exists

If you want something a bit more powerful, but insist on using DOS style commands, you would do well to have a look at the following batch file commands:
FOR (to loop through all the files in a folder)
FINDSTR (to filter out the files you want to move / keep)

If you require this to be all as one line, you can combine commands with an ampersand (&):
mkdir c:\temp\foo & move *_*.jpg c:\temp\foo & ... etc

If you have a huge amount of files, or they are really large, you are better off investigating something which doesn't require moving all the other files somewhere, then moving them back. This will take a long time in some instances.
My System SpecsSystem Spec
13 Aug 2015   #3

Microsoft Community Contributor Award Recipient

Windows 7 Home Premium SP1, 64-bit

Would a method within a GUI in Windows be OK or must this be a command line method?

Can you identify all the files you want to move (or not move) by simply looking at their file names on a scrollable list?

Roughly how many files on your hard drive with those 2 extensions need to be moved?

Roughly how many files on your hard drive with those 2 extensions don't need to be moved?
My System SpecsSystem Spec

14 Aug 2015   #4

Windows 10 Pro X64

Maybe the find command:

C:\WINDOWS\system32>find /?
Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
Use it to generate a list of files that do not contain _thumb ; _tiny ; _zoom ; _std

Yo would have to run it multiple times and direct the output to a single file then edit the file to add the necessary move and target directories.
My System SpecsSystem Spec
15 Aug 2015   #5

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan

Don't think OP is returning, but here's an answer.

:: th-378244.bat SourcePath DestinationPath
@echo off
setlocal EnableDelayedExpansion
REM For each file in 'SourcePath', move the file to 
REM 'DestinationPath' if it's filename does not contain a 
REM string mentioned in 'ignore_files_containing_string'.

set ignore_files_containing_string="_thumb";"_tiny";"_zoom";"_std"
set case_sensitive=FALSE
set recurse=FALSE

if not "%~3"=="" echo Error: unexpected arguments& exit /b
if "%~2"=="" echo Error: missing arguments& exit /b

if not exist "%~2"\* echo Error: the destination path could not be found& exit /b

if /i "%RECURSE%" equ "TRUE" ( set "recurse_=/s" ) else ( set "recurse_=" )
if /i "%CASE_SEN SITIVE%" equ "TRUE" ( set "case_sensitive_=" ) else ( set "case_sensitive_=/i" )

pushd "%~1"
for /f "delims=" %%I in (' dir /a:-d /b %RECURSE_% "*" ') do (
	set /a contains_string_counter=0
		echo.%%~nxI| find %CASE_SENSITIVE_% "%%~J" >NUL && (
			set /a contains_string_counter+=1
	if exist "%%~I" (
		if "!CONTAINS_STRING_COUNTER!"=="0" move "%%~I" "%~2" >NUL
My System SpecsSystem Spec

 DOS Command to Move Image Files to another Folder ?

Thread Tools

Similar help and support threads
Thread Forum
Can I move files from nested folders with a single command?
Is it possible to move files from a location that has files contained in many folder of witch many are deeply nested in layers of other folders using a single command or some software tool? I would rather not spend hours copy and pasting files and trying to keep track of what I have moved. Thank!
General Discussion
How to move/copy files together with it's folder
Hi everyone.. I am in a bit of trouble here. I have 1000+ collection of movies. All these movies are mixed, some are in SD format avi, and some in full HD mp4 format. All these movies are located under one folder, My Movies Collection. Underneath it, all the movies have their own respective...
General Discussion
Cannot move files and folder - need help
I burned a DVD with family genealogy folders and files from my old XP pc and want to move them to my new Win 7 Pro pc. When I attempt to move them I get a popup telling me I need permission to perform this action. I have never encountered this issue before and wonder why this happens and how to...
General Discussion
Move location of Macrium image XML files?
Hi. Been using macrium for imaging. I just noticed that the default location for the xml files it creates with each image is on my C:.... My Documents/Reflect. I always just let it choose until I came to the image, which is on an external drive. Should these be on my external drive, and...
Backup and Restore
Cannot move/copy files within folder
In Vista one could move files within a folder to whatever location manually simply by dragging the file to the desired location within the folder. In WIN7 everything seems to be locked and moving a file (for example image file) to the end of a row of other files within a folder won't work. How to...
General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 07:46.
Twitter Facebook Google+