DOS Command to Move Image Files to another Folder ?


  1. Posts : 1
    64 bit
       #1

    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 Computer


  2. Posts : 16
    Windows 7 Professional x64, RHEL 5,6,7
       #2

    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


  3. Posts : 12,012
    Windows 7 Home Premium SP1, 64-bit
       #3

    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


  4. Posts : 6,285
    Windows 10 Pro X64
       #4

    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.
    [drive:][path]filename
    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 Computer


  5. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #5

    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


 

  Related Discussions
Our Sites
Site Links
About 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 19:26.
Find Us