DosTips.com

A Forum all about DOS Batch
It is currently 23 Aug 2016 19:28

All times are UTC-06:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 25 Apr 2012 04:36 
Offline

Joined: 25 Apr 2012 04:28
Posts: 66
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..)


Top
   
PostPosted: 25 Apr 2012 05:42 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3163
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.


Top
   
PostPosted: 25 Apr 2012 06:08 
Offline

Joined: 25 Apr 2012 04:28
Posts: 66
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.


Top
   
PostPosted: 25 Apr 2012 08:23 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5889
Try this on some sample files and folders (untested):

Code:
@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


Top
   
PostPosted: 26 Apr 2012 08:48 
Offline

Joined: 25 Apr 2012 04:28
Posts: 66
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?


Top
   
PostPosted: 26 Apr 2012 10:01 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5889
/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.


Top
   
PostPosted: 26 Apr 2012 10:10 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
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.


Top
   
PostPosted: 26 Apr 2012 23:14 
Offline

Joined: 25 Apr 2012 04:28
Posts: 66
Hi
Can you explain why or what is binary copy?


Top
   
PostPosted: 27 Apr 2012 06:08 
Offline

Joined: 08 Apr 2012 17:11
Posts: 187
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.


Top
   
PostPosted: 27 Apr 2012 06:19 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5889
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


Top
   
PostPosted: 27 Apr 2012 06:24 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3163
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.


Top
   
PostPosted: 27 Apr 2012 06:27 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5889
The problem is that with /b in this way it can embed EOF characters within the text file - if the text files have them.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited