xcopy to file without extension

Sony Crash bash (psx)
December 4, 2009 at 04:32:32
Specs: Linux/Unix, n/a
How do you perform an XCOPY of one file, without getting asked whether or not you want to create a file or a directory ? Isn't this a bug ? I mean, if you take an existing file, and you tell it to copy (to a non-existant name, either as file or directory) how would that be a directory ? Does not make any sense.

C:\>echo x > test

C:\>xcopy test test2
Does test2 specify a file name
or directory name on the target
(F = file, D = directory)? f
C:test
1 File(s) copied

C:\>xcopy test test3 /I
Does test3 specify a file name
or directory name on the target
(F = file, D = directory)? f
C:test
1 File(s) copied

C:\>xcopy test test4.txt
Does test4.txt specify a file name
or directory name on the target
(F = file, D = directory)? f
C:test
1 File(s) copied

C:\>


See More: xcopy to file without extension

Report •


#1
December 4, 2009 at 05:02:55
... just tried it with the file extension aswell "worked"

C:\>xcopy test.txt newfilename.txt

or

C:\>xcopy test.txt D:\destination\path\newfilename.txt

... is this what you mean?

.

.

... Posting is provided "AS IS" with no warranties
http://img515.imageshack.us/img515/...
Grrrr... ....more


Report •

#2
December 4, 2009 at 05:09:32
No, source is always a file, without extension
Actually, I need the command to work, to create a file with extension, but I do not want to use MOVE because the file is locked by the OS.

Report •

#3
December 4, 2009 at 05:25:21
... oops just reread the name of your post!

C:\>xcopy test.* newfilename.*

... sorry! .....nope!

... not my day just reread the name of poster without realizing the above (Response Number 2) was (s)he!


...ZZZZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzz

.

.

... Posting is provided "AS IS" with no warranties
http://img515.imageshack.us/img515/...
Grrrr... ....more


Report •

Related Solutions

#4
December 4, 2009 at 05:27:00
What about plain old copy? Sure the directory has to exist but it won't ask.

Xcopy seems to have been created to deal with directory names and/or multiple files, while copy still exists it doesn't make much sense to have a single file option.

If you insist on using xcopy simply echo "f" to select the option file without user input.

echo f|xcopy test test2


Batch Variable how to


Report •

#5
December 4, 2009 at 09:09:24
Yes, the old COPY command is an option, but then COPY does not understand other parameters which I need, like /D

Report •

#6
December 4, 2009 at 09:24:16
Why not use ROBOCOPY it has way more functionality than XCOPY.

It comes free with the server tool kit...

http://www.microsoft.com/downloads/...

http://www.xxcopy.com/xxcopy30.htm


Report •

#7
December 4, 2009 at 09:27:29
Fair enough, does "echo f|xcopy ...." solve you problem?

Edit: Ninja'd with robocopy, probably a good idea.


Batch Variable how to


Report •

#8
December 4, 2009 at 13:28:39
Judago,
echo f|xcopy test test2


Indeed works ... would be nicer using parameters, but what the heck
------------------------------------------
I know of XXCOPY and ROBOCOPY, but I'm asking the question here if XCOPY is buggy or not, XCOPY being a basic MS command ... Agreed that XXCOPY and ROBOCOPY are much superior, but do I also need to abandon XCOPY when I want to copy 1 file ?
I can use COPY, but then I can't use the advanced features of XCOPY. Don't forget : COPY and XCOPY are default XP commands, neither XXCOPY or ROBOCOPY are.

C:\>echo x > x

C:\>echo x > x.txt

C:\>xcopy x test1.txt
Does test1.txt specify a file name
or directory name on the target
(F = file, D = directory)? f
C:x
1 File(s) copied

C:\>xcopy x.txt test2.txt
Does test2.txt specify a file name
or directory name on the target
(F = file, D = directory)? f
C:x.txt
1 File(s) copied

C:\>


Report •

#9
December 4, 2009 at 19:04:38
I have seen at least one bug in xcopy and error messages can be a little cryptic.

If you get an "out of memory error" it means your trying to copy to a path over 255 chars long, which windows normally limits the paths to.

I can't remember how to reproduce it but I remember a bug that made the copied file have hidden attributes even though the /k switch was present and the original file wasn't hidden.

It's been a while but I *think* it was triggered by coping a folder(non root) from one drive to a root of another. It's a pretty rare circumstance, but annoying.....

As for it displaying c:x, it isn't being copied to the root, it just seems to display drive + filename, it's deceptive but /f will remove the ambiguity.

I had a look into the nt file escape syntax(\\.\c:\blah\blah) to try to avoid the question, but xcopy doesn't support it.

Other than that it's generally pretty good, but if you want to avoid inconsistencies you should have a look at other utilities or a proper programming language. Even then there aren't any guarantees....


Batch Variable how to


Report •

#10
December 5, 2009 at 04:27:42
That's nice, but that is another bug then ...

When you ask XCOPY to copy a FILE to a non-existant name, ex.:

C:\>del /Q test02.txt
Could Not Find C:\test02.txt

C:\>echo x > test01.txt

C:\>xcopy test01.txt test02.txt
Does test02.txt specify a file name
or directory name on the target
(F = file, D = directory)?

... well, in that case he should not ask for this above question. Does he think test02.txt should be a directory ? Why ? He can check and see that test01.txt is a file. If you copy a file, to a non-existant name, that should be to another file ... in most cases. Yes, you can copy a file to a directory that does not exist yet, creating that directory, then putting the directory in there. But what bothers me, is that there is NO parameter to tell XCOPY that, so he needs to ask everytime. These are the XCOPY params :

C:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:file1[+file2][+file3]...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

C:\>


Particularly since there IS a parameter (parameter "/I") which CAN handle something similar, being the fact then when your first parameter is something with wildcards, he can assume that the destination would be a folder. In fact, when your source parameter contains wildcards, I cannot see how your target can be a filename, must always be a folder. Then you have something like this (which makes no sense at all):

C:\>xcopy test* nonexistant
Does nonexistant specify a file name
or directory name on the target
(F = file, D = directory)? f
C:test
Overwrite C:\nonexistant (Yes/No/All)? y
C:test.txt
Overwrite C:\nonexistant (Yes/No/All)? y
C:test01.txt
Overwrite C:\nonexistant (Yes/No/All)? y
C:test1.txt
Overwrite C:\nonexistant (Yes/No/All)? y
C:test2
Overwrite C:\nonexistant (Yes/No/All)? y
C:test2.txt
Overwrite C:\nonexistant (Yes/No/All)? y
C:test3
Overwrite C:\nonexistant (Yes/No/All)? y
C:test3.txt
Overwrite C:\nonexistant (Yes/No/All)?


Clearly, something is messed up there, Bill didn't really grasp the concept of copying one or more files ?!


Report •

#11
December 5, 2009 at 05:10:49
I think your absolutely right about the problem, to be honest I don't really use xcopy that much, when I do it's normally multiple files with /i, so haven't really noticed before. It's definitely counter intuitive to say the least.

The windows command line and batch files in general do have quite a few "special cases", glaring omissions and bugs. Here's a nice trick from the command line(doesn't work in batch files) "cmd<nul 3>nul", I've seen it work in nt4, xp and vista.

In the end the only thing that can really be done is either work around it or move on to other tools.......

Edit: Microsoft bug reporting....
http://connect.microsoft.com/


Batch Variable how to


Report •


Ask Question