Re: Copying silently.
- From: "pmj" <post@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Mar 2007 02:04:38 GMT
"Frederick Williams" <Frederick_Williams@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:45F70F18.F1F4A497@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
copy /y x y >> nul:
will copy x to y and not tell me that it's done so, nor will it ask me
to confirm that y should be copied over if it already exists. Good,
that (so far as it goes) is what I want.
Unfortunately if x doesn't exist I won't see the message "The system
cannot find the file specified.". I could test errorlevel if my copy
command was in a batch file, but I'd like it to be one command on the
command line. So my question is this:
Is there a switch to copy that means "Keep quite unless the source
doesn't exist."?
If I do have to use errorlevel I assume that if copy /y x y works
then it is 0 and if it fails then it is > 0, where (and this is
important) working includes the case where y already exists.
Can you clarify what you mean by "if copy /y x y works"
means, when "working" includes the case where y already exists?
Do you want (or need/expect) the Copy to continue (i.e. overwrite)
the existing file "y"? (Which I assume is why you want to use the "/y"
Switch, so as to ensure that it *does* overwrite it if it already
exists).
The output of the Copy Command, in that case is just the Text:
"1 file(s) copied."
Do you need to know (differentiate between) whether it succeeded by
overwriting an existing File or by Creating a new File?
You could pass the Output of the "copy" Command to the "find" Command,
perhaps & act on that, in the next part of the Command Line - it's
prolly more suited than trying to rely on the "errorlevel" as the
only means of determining what happened.
Maybe you could use some kind of thing like:
FOR %variable IN (set) DO command [command-parameters]
Where "set" is a (Space delimited) List of Files (& can include
Wildcards) & the "do ..." bit could be further Command(s) which Read
(&/or Parse?) the Output & then continue with other Commands?
Have a look at the Help/Syntax for/of the "for" Command - use:
for /?
or:
help for
If you have "Command Extensions" Enabled, then the "for" Command
has a whole load of useful extra Versions & Parameters available,
for doing all sorts of Loops & Iterations over various things, based
on lots of different Conditions.
& it uses loads of things such as "Delimiters" & "Tokens"
& (if I read it right) can use Brackets & stuff to Run Multiple
Commands Sequentially/Conditionally.
I don't claim to know all that much about all those sort of things,
but from the looks of the Help Files & Syntax (& from my limited
use/experience of the "for" Command) it may very well help you with
what you want to do.
You could also do a lot of that sort of stuff with Batch Files,
but also, using JScript &/or VBScript - both of those come with
windoze & enable you to call up all sorts of Operating (& File)
System Commands & Functions & you can have whatever testing
& Conditions in them that you want & you can Run them from
a Command Line, passing in Arguments, Switches & Parameters
& even accepting/Processing User Input (& giving some Output)
if that might Help.
Perl is also available (for Free) for windoze & that can certainly
do what you want.
HTH
--
pmj
.
- Follow-Ups:
- Re: Copying silently.
- From: Frederick Williams
- Re: Copying silently.
- References:
- Copying silently.
- From: Frederick Williams
- Copying silently.
- Prev by Date: Re: Chair
- Next by Date: Re: Covert Photography to Snare Smokers
- Previous by thread: Re: Copying silently.
- Next by thread: Re: Copying silently.
- Index(es):
Relevant Pages
|