Sort and Move specific files by identifying a word inside.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Sort and Move specific files by identifying a word inside.

#1 Post by val5662 » 01 Oct 2014 07:07

Hi All...
I will explain what I need in as much detail as possible.
I need a batch file to move specific files into a separate folder,possibly by opening my hex editor,searching for the word "body" ( without the quotes ) and if found ,close hex editor,move file to a folder called "moved" ,then go on to the next one.If the word "body" is not found just close hex editor and ignore the file.
I have approx 900 files in a folder.One is a vehicle and one is a map for a game.They are mixed together and the only way of telling them apart is by opening each one with my hex editor and search for the word "body",which means it is a vehicle.If the "body" word is not found,it is a map.Example wording of the files: mapname.idf carname.idf
Manually this process would take hours,even days.
It would be a lot better if there is a way of doing this without using the hex editor/batch idea.
Here is a link to one map and one vehicle file if needed for an example:
http://vnovak.com/1nsane/2idf-files.zip
Thanks a bunch for your help! :)
Val

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Sort and Move specific files by identifying a word insid

#2 Post by ShadowThief » 01 Oct 2014 07:47

Try this. This assumes that the moved folder in inside the directory with all the other files and that they're all .idf files. Stick this script in that directory as well.

Code: Select all

@echo off
setlocal enabledelayedexpansion

for /f %%A in ('dir /b *.idf') do (
   findstr /L "body" %%A>nul
   if !errorlevel! equ 0 move %%A moved
)

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Sort and Move specific files by identifying a word insid

#3 Post by dbenham » 01 Oct 2014 07:57

FINDSTR can search binary files just fine, and the /M option lists the files where the search string was found.

You can run the following simple command from the command line - no batch script required.

Code: Select all

for /f "eol=: delims=" %F in ('findstr /m body *.idf') do @move "%F" moved >nul

Double up the percents if you use the command in a batch script.


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Sort and Move specific files by identifying a word insid

#4 Post by foxidrive » 01 Oct 2014 07:59

Download the free tool Swiss File Knife http://sourceforge.net/projects/swissfileknife/
and put it in the same folder as the IDF files and this batch file and launch the batch file.

Try it on some sample files first.

Code: Select all

@echo off
md "Moved" 2>nul
for %%a in (*.idf) do (
   echo processing "%%a"
   sfk find "%%a" body >nul || (echo --- moving "%%a"& move "%%a" "Moved">nul)
)
pause


EDIT: I didn't know that findstr can search binary files. D'oh!

I'll leave this here as another option.

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Sort and Move specific files by identifying a word insid

#5 Post by val5662 » 01 Oct 2014 22:24

Thanks ShadowThief,dbenham and foxidrive.
All your codes worked great.
Thanks again!
I appreciate it a bunch!
Consider this topic answered.
Val :D

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

NEW PROBLEM with Sort and Move specific files

#6 Post by val5662 » 02 Oct 2014 11:24

Hi all...
The code I used below worked but now I have a new problem.
@echo off
md moved
for /f "eol=: delims=" %%F in ('findstr /m body *.idf') do @move "%%F" moved >nul
pause

A lot of these idf files have the word body with caps like Body or BODY and the code below just ignores those files.
How can I modify this code to make it NOT case sensitive?
Thanks again!

Val

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

Re: Sort and Move specific files by identifying a word insid

#7 Post by Squashman » 02 Oct 2014 11:36

Code: Select all

C:\>findstr /?

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Sort and Move specific files by identifying a word insid

#8 Post by val5662 » 02 Oct 2014 11:50

Squashman...Thanks....

@echo off
md moved
for /f "eol=: delims=" %%F in ('findstr /m /I body *.idf') do @move "%%F" moved >nul
pause

This code works now.I am learning a bunch from you guys....
Thanks again!
Solved :D

Val

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

Re: Sort and Move specific files by identifying a word insid

#9 Post by Squashman » 02 Oct 2014 12:15

val5662 wrote:Squashman...Thanks....

Teach a man to fish......... :D

Post Reply