DOS Command to Move Image Files to another Folder ?

mave27

New member
Local time
7:36 PM
Messages
1
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 ? :rolleyes:

Thanks in Advance.
 

My Computer

Computer type
PC/Desktop
OS
64 bit
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 Computer

Computer type
PC/Desktop
OS
Windows 7 Professional x64, RHEL 5,6,7
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Ignatz Special; 4 speed manual gearbox; factory air conditioning; one of one
OS
Windows 7 Home Premium SP1, 64-bit
CPU
Intel Skylake i5-6600K, not overclocked
Motherboard
AsRock Z170M Extreme 4, micro ATX
Memory
8 GB HyperX DDR4-2666 (2 x 4 GB)
Graphics Card(s)
none; graphics are integrated on CPU
Sound Card
onboard: Realtek ALC1150; external: USB Behringer UF0-202
Monitor(s) Displays
Dell S2340M 23 inch IPS
Screen Resolution
1600 x 900
Hard Drives
System: Crucial MX100 series SSD, 128 GB;
Data: Samsung Spinpoint 103SJ, 1 TB;
Backup: WD Caviar Green WD30EZRX-00D8PB0, 3 TB
PSU
Rosewill SilentNight 500 watt fanless, semi-modular
Case
Antec Solo II
Cooling
Noctua NH-U12S; Noctua F12 intake, Noctua S12A exhaust
Keyboard
Microsoft 200 6JH-00001 USB
Mouse
Dell or Microsoft optical wired; USB
Antivirus
Microsoft Security Essentials and Malwarebytes Premium
Browser
Pale Moon
Other Info
All fans PWM; speeds at idle: CPU circa 500 rpm; intake circa 600 rpm; exhaust circa 600 rpm; CPU temps 27 idle and 47 C load in a warm room (27 C/81 F) when running Intel Extreme Tuning Utility stress test.
Maybe the find command:

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

FIND [/V] [/C] [/N] [/I] [/OFF

 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Lenovo IdeaCenter 450
OS
Windows 10 Pro X64
CPU
Intel Quad Core i7-4770 @ 3.4Ghz
Memory
16.0GB PC3-12800 DDR3 SDRAM 1600 MHz
Graphics Card(s)
Intel Integrated HD Graphics
Sound Card
Realtek HD Audio
Monitor(s) Displays
HP 22" LCD
Screen Resolution
1680 x 1050
Hard Drives
250GB Samsung EVO SATA-3 SSD
2TB Seagate ST2000DM001 SATA-2
1.5TB Seagate ST3150041AS SATA
Keyboard
Dell USB
Mouse
Lenovo USB
Internet Speed
Cable via Road Runner 3MB Upload, 30MB Download
Antivirus
Windows Defender, MBAM Pro, MBAE
Browser
Seamonkey
Other Info
UEFI/GPT
PLDS DVD-RW DH16AERSH
Don't think OP is returning, but here's an answer.


Code:
:: 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
	for %%J in (%IGNORE_FILES_CONTAINING_STRING%) do (
		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
	)
)
popd
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
Back
Top