Robocopy syntax to copy single file in the same directory with new name?

18,339

Robocopy's primary use case is to mirror or migrate files from one path to a different path. It could be used to copy a single file to a different directory, but it does not rename files. Try the following powershell commands:

copy-item file1.txt file2.txt
get-acl file1.txt | set-acl file2.txt
Share:
18,339
Emil
Author by

Emil

Updated on September 18, 2022

Comments

  • Emil
    Emil over 1 year

    I need to make a copy of a file:

    1. with all the security (ACL) permissions - that's why I chose robocopy
    2. the copy must be in the same directory with new name obviously

    The Robocopy syntax is drastically different from any other command line tools and I don't even know if it is possible to acheive this with robocopy?

    What I have tried is:

    robocopy c:\temp\ c:temp\ file1.txt file2.txt
    

    however this does not work since this is the sintax to copy the two files listed but since the source & destination are the same the command is ignored... I am not sure it is possible...

  • Emil
    Emil over 6 years
    Thanks - great suggestion; I'll give it a try and accept your answer if it works well. I shied away from using powershell as I found it very slow and sometimes unreliable with low level stuff like file permissions, because it is using mainly .net framework under the covers...