0

For example, I have:

1) text.txt file in D:\Test folder

2) text.txt file in D:\x64_this-is-my-test_54321_99.88.77.555_folder_n12345 folder

How can I copy with replacement (xcopy /o /y)

text.txt file from Test folder to the x64_this-is-my-test_54321_99.88.77.555_folder_n12345 folder

by using command line (FOR /R [[drive:]path] %%parameter IN (set) DO command )

if I know only that the second folder name starts with x64_this-is-my-test, and the other part of the folder's name is unknown?

4
  • Have you tried using wildcard for the destination? x64_this-is-my-test* Commented May 12, 2015 at 4:22
  • Yes I tried using command: xcopy D:\Test\text.txt "D:\x64_this-is-my-test*\text.txt" /o /y And it's not working. Commented May 12, 2015 at 4:37
  • 1
    Seems this link has some relevant info - check it out once - sevenforums.com/backup-restore/… Commented May 12, 2015 at 4:50
  • Thanks, but it's a little bit different. Commented May 12, 2015 at 5:44

1 Answer 1

1
for /d %%# in ("D:\x64_this-is-my-test*") do copy /y "D:\Test\text.txt" "%%~f#\test.txt"

using xcopy for single files is bad idea .Better use copy.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you! Your command is that what I need. xcopy has very nice parameter /o little change your solution: for /d %%f in ("D:\x64_this-is-my-test*") do xcopy /o /y "D:\Test\text.txt" "%%f"
@VldGrdv to change file permissions you can use CACLS command
yes, I know. But change file(folder) permissions and user to VldGrdv, then back to Admin use more commands. For me, better to copy with permissions (xcopy /o).
@VldGrdv - here's a trick how xcopy can be used for a single file - but is language dependent echo F| XCOPY C:\utils\MyFile.txt D:\Backup\CopyFile.txt
Imho, this trick is more useful for text files?! But I also need to copy image files and programs, where the owner is TrustedInstaller. In the first question I use txt-file, just for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.