Re: Copying silently.



"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


.



Relevant Pages

  • Re: System call not acting as expected
    ... You seem to be expecting the latter behaviour, ... Why are you using commas there ... all sorts of fun problems, like having to sort out terminal escape ... > The result of this line confirms that it is generating exactly the command ...
    (comp.lang.perl.misc)
  • Re: Ruled text
    ... defining a command to lay out examples in the form of text (perhaps ... containing all sorts of stuff beyond simple paragraphs) set off by ...
    (comp.text.tex)
  • Re: How to change the information in audio files?
    ... information and/or the sound format in audio files? ... I'd prefer command line ... is a library for editing all sorts of metadata on all sorts of audio ...
    (uk.comp.os.linux)
  • Re: How to change the information in audio files?
    ... information and/or the sound format in audio files? ... I'd prefer command line ... is a library for editing all sorts of metadata on all sorts of audio ...
    (uk.comp.os.linux)
  • RE: Save As / Overwrite
    ... I am using macros in an Excel file perform sorts on data and save each sort ... If I use the Workbook.SaveAs command, I am constantly prompted whether to ... overwrite the existing file. ...
    (microsoft.public.excel.misc)