How to perform conditional copy?

  • Thread starter Thread starter Galop
  • Start date Start date
G

Galop

I want to perform COPY from a remote folder (Network
mapped) to a local folder on my W2K system. The copy
should be excuted only if there are files in the remote
folder (else go to exit the batch executeion). To acheive
this, how should I script my commands in the batch file?
Thanks.
Galop.
 
Galop said:
I want to perform COPY from a remote folder (Network
mapped) to a local folder on my W2K system. The copy
should be excuted only if there are files in the remote
folder (else go to exit the batch executeion). To acheive
this, how should I script my commands in the batch file?
Thanks.
Galop.

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>demo\HowManyFiles
Please specify the directory

C:\cmd>demo\HowManyFiles c:\junkdir
Directory c:\junkdir contains 21 files.

C:\cmd>demo\HowManyFiles c:\snarf
Directory c:\snarf doesn't contain any files.

C:\cmd>qblist demo\HowManyFiles.cmd
===== begin file C:\cmd\demo\HowManyFiles.cmd =====
01. @echo off
02. if [%1]==[] echo Please specify the directory&goto :EOF
03. for /f "tokens=1" %%a in (
04. 'dir %1 ^| find "File(s)"'
05. ) do set /a number_of_files=%%a
06. if %number_of_files% EQU 0 (
07. echo Directory %1 doesn't contain any files.
08. ) else (
09. echo Directory %1 contains %number_of_files% files.
10. )
===== end file C:\cmd\demo\HowManyFiles.cmd =====
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
 
Something like this:

====================================================
@echo off
set SERVER=\\server\share

if not exist %SERVER%\filename.ext goto NO_FILES
xcopy %SERVER%\filename.ext c:\myfiles /y
goto END

:NO_FILES
echo No files found. . .

:END
====================================================

Something like that. There is better ways to do it, I like using a program
called XXCOPY, search google for it.
It's free and powerful....
 
Thanks for your response. I need it slightly different.
Not interactive way as you have exampled. It should be
something like this..

(The following is within a scheduled batch job)
Check the contents of J:\INPUT
If the folder is empty go to EOF
else copy J:\INPUT to D:\LOCAL
Do some other normal commands
Do some other normal command
EOF

-----Original Message-----
Galop said:
I want to perform COPY from a remote folder (Network
mapped) to a local folder on my W2K system. The copy
should be excuted only if there are files in the remote
folder (else go to exit the batch executeion). To acheive
this, how should I script my commands in the batch file?
Thanks.
Galop.

- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
C:\cmd>demo\HowManyFiles
Please specify the directory

C:\cmd>demo\HowManyFiles c:\junkdir
Directory c:\junkdir contains 21 files.

C:\cmd>demo\HowManyFiles c:\snarf
Directory c:\snarf doesn't contain any files.

C:\cmd>qblist demo\HowManyFiles.cmd
===== begin file C:\cmd\demo\HowManyFiles.cmd =====
01. @echo off
02. if [%1]==[] echo Please specify the directory&goto :EOF
03. for /f "tokens=1" %%a in (
04. 'dir %1 ^| find "File(s)"'
05. ) do set /a number_of_files=%%a
06. if %number_of_files% EQU 0 (
07. echo Directory %1 doesn't contain any files.
08. ) else (
09. echo Directory %1 contains %number_of_files% files.
10. )
===== end file C:\cmd\demo\HowManyFiles.cmd =====
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
.
 
Galop said:
Thanks for your response. I need it slightly different.
Not interactive way as you have exampled. It should be
something like this..

(The following is within a scheduled batch job)
Check the contents of J:\INPUT
If the folder is empty go to EOF
else copy J:\INPUT to D:\LOCAL
Do some other normal commands
Do some other normal command
EOF
Why don't you simply copy and in case of no success goto :eof ?

copy J:\INPUT\*.* D:\LOCAL\ 2>NUL ||goto :eof
echo do other normal commands

HTH
 
Galop said:
Thanks for your response.

You're welcome!
I need it slightly different.
Not interactive way as you have exampled. It should be
something like this..

(The following is within a scheduled batch job)
Check the contents of J:\INPUT
If the folder is empty go to EOF
else copy J:\INPUT to D:\LOCAL
Do some other normal commands
Do some other normal command
EOF

Should be quite easy for you to modify my example to match
your specifications. :-)
-----Original Message-----
Galop wrote:


remote

acheive

file?


- - - - - - - - - - begin screen capture Win2000 - - - -

- - - - - -
C:\cmd>demo\HowManyFiles
Please specify the directory

C:\cmd>demo\HowManyFiles c:\junkdir
Directory c:\junkdir contains 21 files.

C:\cmd>demo\HowManyFiles c:\snarf
Directory c:\snarf doesn't contain any files.

C:\cmd>qblist demo\HowManyFiles.cmd
===== begin file C:\cmd\demo\HowManyFiles.cmd =====
01. @echo off
02. if [%1]==[] echo Please specify the

directory&goto :EOF
03. for /f "tokens=1" %%a in (
04. 'dir %1 ^| find "File(s)"'
05. ) do set /a number_of_files=%%a
06. if %number_of_files% EQU 0 (
07. echo Directory %1 doesn't contain any files.
08. ) else (
09. echo Directory %1 contains %number_of_files%
files.

10. )
===== end file C:\cmd\demo\HowManyFiles.cmd =====
- - - - - - - - - - end screen capture Win2000 - - - -

- - - - - -
--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m

a i l
 
Back
Top