-2

When I run this file:

xcopy .\*.odt .\source.zip

I am prompted to specify what source.zip is:

xcopy .\*.odt .\source.zip
Does .\source.zip specify a file name
or directory name on the target
(F = file, D = directory)?

In my case when it find the .odt file to copy the file and place in the same directory but with new name source.zip. Is there approach to avoid the prompting since I always want destination to be a file not directory.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Radoslaw Krasimirow
  • 1,833
  • 2
  • 18
  • 28
  • What are you trying to do? Do you want to copy a bunch of files into one file? In case you're trying to add all those files to one zipfile, `xcopy` is not the way to do it. – Dominique Nov 18 '15 at 09:04
  • No, there will be only one file with extention `.odt`. I want ot copy it into the same directory with the new name _source.zip_. Since the the .odt may have any name I want it with different name but to keep the original. – Radoslaw Krasimirow Nov 18 '15 at 09:10
  • The problem is that you can't use `xcopy` for renaming a file: you can use `xcopy` for copying bunches of files, but when you need to rename a file, you need the `copy` command. – Dominique Nov 18 '15 at 09:12
  • Whne I use `copy .\*.odt .\source.zip` the .zip is corrupted. But when I use: `copy .\*.odt .\*.zip` everything is fine, but the name of the `zip` is same as the name of the `odt` which is not desired in my case – Radoslaw Krasimirow Nov 18 '15 at 10:12
  • 1
    The problem is that you try to do everything within one single command. I'd propose you to search for the name of the *.odt file, put that filename into a variable, and then copy that filename into source.zip. – Dominique Nov 18 '15 at 10:39
  • @RadoslawKrasimirow, I am confused as to why you are not using the `RENAME` command? – Squashman Nov 18 '15 at 13:34
  • 1
    I guess you are looking for [this answer](http://stackoverflow.com/a/33770152/5047996); you can use `echo F|xcopy .\*.odt .\source.zip`, if, and _only_ if, `*.odt` matches a single file! – aschipfl Nov 18 '15 at 23:26

1 Answers1

0

Any .odt file (being in .zip format in fact) is a binary file, see OpenDocument Document Representation

  • As a collection of several sub-documents within a package, each of which stores part of the complete document. This is the common representation of OpenDocument documents. It uses filename extensions such as .odt, .ott, .ods, .odp ... etc. The package is a standard ZIP file with different filename extensions and with a defined structure of sub-documents. Each sub-document within a package has a different document root and stores a particular aspect of the XML document. All types of documents (e.g. text and spreadsheet documents) use the same set of document and sub-document definitions.

Therefore, you need to treat it as a binary file (read copy /?):

copy /B .\*.odt .\source.zip

Above command would work smoothly only if there will be only one file with extension .odt. Otherwise, it will prompt you for Overwrite .\source.zip? (Yes/No/All):. To stay on the safe side:

  • from command line for %G in (.\*.odt) do copy /B "%G" ".\source_%~nG.zip"
  • from a batch script for %%G in (.\*.odt) do copy /B "%%G" ".\source_%%~nG.zip"

%~nG (or in batch %%~nG) explanation: read Parameter Extensions.

JosefZ
  • 28,460
  • 5
  • 44
  • 83