script to separation of data according to picture number

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

script to separation of data according to picture number

#1 Post by mor.bas » 25 Apr 2012 04:36

Hi
I need a script that will help me copy gif files from one folder to another according to picture number.
I have a single folder containing ~200,000 files including many ubc images.
The filename of the images is built like this:
WeInput_du185_wu.110.303.3.1_picture340_frame303_ref303_Det_InImage1.gif
Manual Input: slice number, source folder, destination folder (I can change the input in text editor, or any other way you specify).
I wrote this script
@echo off
set /p file="Enter search cretiria:"
set /p source="Enter Source folder (c:\folder name):"
set /p dest=" Enter destnation folder (c:\folder name:)"
forfiles /p %source% /m *%file%*.gif /c "cmd /c copy @file %dest%"

It's work find on Win7
but not working in XP
any suggestion or alternative ?
(I try to dowwnload from http://www.petri.co.il/download_free_reskit_tools.htm but it's doest work good..)

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

Re: script to separation of data according to picture number

#2 Post by Squashman » 25 Apr 2012 05:42

mor.bas wrote:It's work find on Win7
but not working in XP
any suggestion or alternative ?
(I try to dowwnload from http://www.petri.co.il/download_free_reskit_tools.htm but it's doest work good..)

That's because that link is for the Windows 2000 resource tools. Forfiles had a different syntax in Windows 2000. You need to download Forfiles that come with Windows 2003.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: script to separation of data according to picture number

#3 Post by mor.bas » 25 Apr 2012 06:08

Hi
From where I get 2003 ver?
or
Can you post another alternative script that I don't need to copy this file to sys32 and it will work fine also in XP.

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

Re: script to separation of data according to picture number

#4 Post by foxidrive » 25 Apr 2012 08:23

Try this on some sample files and folders (untested):

Code: Select all

@echo off
:loop
set /p "file=Enter gif file search criteria:"
if not exist "%source%\*%file%*.gif" echo filespec doesn't exist error - try again &goto :loop
set /p "source=Enter Source folder (c:\folder name):"
if not exist "%source%\" echo source doesn't exist error - try again &goto :loop
set /p "dest=Enter destination folder (c:\folder name:)"
if not exist "%dest%\" echo destination doesn't exist error - try again &goto :loop

for /f "delims=" %%a in ('dir "%source%\*%file%*.gif" /b /a-d') do (
echo copying "%source%\%%a"
copy /b /y "%source%\%%a" "%dest%" >nul
)
echo done
pause

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: script to separation of data according to picture number

#5 Post by mor.bas » 26 Apr 2012 08:48

Hi
thanks nice script
but I have question to understand it good..
1. why you need dir /b /a-d?
(/b give you the bare files and its quite good)
2.why you need copy /b /y
/b for binary?
/y - why exacly?

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

Re: script to separation of data according to picture number

#6 Post by foxidrive » 26 Apr 2012 10:01

/a-d stops any folder that might match the filespec from causing errors. It's possible, as folders can have extensions.

/b /y allows the batch file to overwrite existing files, to stop the batch file from halting if files already exist. /b is for a binary copy.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: script to separation of data according to picture number

#7 Post by Fawers » 26 Apr 2012 10:10

mor.bas wrote:(...)
1. why you need dir /b /a-d?
(...)
2.why you need copy /b /y
(...)
/y - why exacly?


The /a-d switch will show you everything in the directory but the directories themselves.
And the /y switch stands for yes; it will suppress any "overwrite file?" prompt.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: script to separation of data according to picture number

#8 Post by mor.bas » 26 Apr 2012 23:14

Hi
Can you explain why or what is binary copy?

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: script to separation of data according to picture number

#9 Post by Fawers » 27 Apr 2012 06:08

mor.bas wrote:Hi
Can you explain why or what is binary copy?


Wikipedia wrote:A binary file is a computer file which may contain any type of data, encoded in binary form for computer storage and processing purposes; for example, computer document files containing formatted text. Many binary file formats contain parts that can be interpreted as text; binary files that contain only textual data—without, for example, any formatting information—are called plain text files. In many cases, plain text files are considered to be different from binary files because binary files are made up of more than just plain text.

This is the definition of binary file. COPY command needs /binary copying because of these binary files.

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

Re: script to separation of data according to picture number

#10 Post by foxidrive » 27 Apr 2012 06:19

The reason why you need /b is that in past versions of Microsoft OS the copy command stops copying when it encounters an EOF byte/character, and many non-text files contain these bytes.

These days I think the copy command has been enhanced and it will automatically switch to binary copy mode on some filetypes - but probably not all. It's still prudent to use /b to be sure.

The amusing thing is that it is safe to use /b even on text files so there is no reason not to use it all of the time

(except when concatenating several text files in this format)

copy file1.txt + file2.txt + file3.txt fileout

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

Re: script to separation of data according to picture number

#11 Post by Squashman » 27 Apr 2012 06:24

foxidrive wrote:The amusing thing is that it is safe to use /b even on text files so there is no reason not to use it all of the time

(except when concatenating several text files in this format)

copy file1.txt + file2.txt + file3.txt fileout


I use /B even in that instance. The reason being is because it will put an EOF character at the end of the combined file if you don't.

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

Re: script to separation of data according to picture number

#12 Post by foxidrive » 27 Apr 2012 06:27

The problem is that with /b in this way it can embed EOF characters within the text file - if the text files have them.

Post Reply