How to use xcopy to copy a file into a non existing directory?

bits picture bits · Jul 29, 2010 · Viewed 7.7k times · Source

As a part of an automated script, I am trying to do achieve something like this in windows command prompt:

xcopy /I /Y resources\xyz\pqrs.txt %TEMP%\resources\xyz\pqrs.txt.bak

In %TEMP%, there is no resources directory.

This is the interactive output, that I get:

Does C:\Users\username\AppData\Local\Temp\resources\xyz\pqrs.txt.bak specify a file name
or directory name on the target
(F = file, D = directory)?

The whole thing is that I want to create a directory and copy file without interaction.

If I use a mkdir, I will have to extract the directory path out before using mkdir. I was just wondering if its possible to use xcopy to achieve mkdir+copy at the same time.

xcopy reference for all.

Thanks for the help.

Answer

Ricardo picture Ricardo · Jul 29, 2010

Try this:

echo d| xcopy /f C:\abc\file1 C:\abc\newfolder\file2