I am trying to run the following command in Windows CLI:

XCOPY Z:\.vimrc %USERPROFILE%\_vimrc /H

The /H part needs to be there because Z:\.vimrc is a hidden file.

When I run the command above, I get the following message:

Does C:\Users\Matt\_vimrc specify a file name
or directory name on target
(F = file, D = directory)?

This command will eventually be part of a BAT file and I don't want that prompt. The answer to it is always "F".

If .vimrc and _vimrc were named the same, I could just run one of these commands and be done with it:

XCOPY Z:\.vimrc %USERPROFILE%\ /H
XCOPY Z:\.vimrc %USERPROFILE% /H /I

But they are not, so I can't. How do I suppress that message?

I know I could copy it with the same file name and then move it, but c'mon, does this really have to be two commands? I'm just copying a file.

Note: When there is already a %USERPROFILE%\_vimrc file, the message does not appear.

link|improve this question

feedback

3 Answers

up vote 1 down vote accepted

Ugh.

echo F | XCOPY Z:\.vimrc %USERPROFILE%\_vimrc /H
link|improve this answer
feedback

Hack:

type Z:\.vimrc > "%USERPROFILE%\_vimrc"
link|improve this answer
feedback

I really cannot see the problem with renaming afterwards

xcopy Z:\.vimrc %USERPROFILE%\ /H && ren %USERPROFILE%\.vimrc _vimrc

If there is a possibility of the file existing already:

if NOT EXIST %USERPROFILE%\_vimrc (
    xcopy Z:\.vimrc %USERPROFILE%\ /H && ren %USERPROFILE%\.vimrc _vimrc
) ELSE (
    del %USERPROFILE%\_vimrc
    xcopy Z:\.vimrc %USERPROFILE%\ /H && ren %USERPROFILE%\.vimrc _vimrc
)
link|improve this answer
Seems really kludgy. Also, what if %USERPROFILE%\.vimrc existed already? – mattalexx Apr 12 '11 at 17:04
@mattalexx: I just edited my answer. I'm not sure what you want to do if the file exists, but you get the drift. I don't think it's kludgy, as one has to do stuff like that all the time with CMD – paradroid Apr 12 '11 at 17:18
You are duplicating the same xcopy && ren line in both "if" and "else" blocks. This could be changed to if exist ... del ... and xcopy ... && ren ..., which is much shorter. – grawity Apr 12 '11 at 21:12
@grawity: Fair point, but if you look at the edits, you'll see why I was not thinking of that. I wasn't really sure what he wanted to when the file exists already. – paradroid Apr 12 '11 at 21:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.