Page 1 of 1

script to separation of data according to picture number

Posted: 25 Apr 2012 04:36
by mor.bas
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..)

Re: script to separation of data according to picture number

Posted: 25 Apr 2012 05:42
by Squashman
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.

Re: script to separation of data according to picture number

Posted: 25 Apr 2012 06:08
by mor.bas
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.

Re: script to separation of data according to picture number

Posted: 25 Apr 2012 08:23
by foxidrive
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

Re: script to separation of data according to picture number

Posted: 26 Apr 2012 08:48
by mor.bas
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?

Re: script to separation of data according to picture number

Posted: 26 Apr 2012 10:01
by foxidrive
/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.

Re: script to separation of data according to picture number

Posted: 26 Apr 2012 10:10
by Fawers
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.

Re: script to separation of data according to picture number

Posted: 26 Apr 2012 23:14
by mor.bas
Hi
Can you explain why or what is binary copy?

Re: script to separation of data according to picture number

Posted: 27 Apr 2012 06:08
by Fawers
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.

Re: script to separation of data according to picture number

Posted: 27 Apr 2012 06:19
by foxidrive
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

Re: script to separation of data according to picture number

Posted: 27 Apr 2012 06:24
by Squashman
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.

Re: script to separation of data according to picture number

Posted: 27 Apr 2012 06:27
by foxidrive
The problem is that with /b in this way it can embed EOF characters within the text file - if the text files have them.