can i robocopy only specific folder

Xu, Tao 21 Reputation points
2021-10-09T19:44:43.24+00:00

my thing: i have 4 folder in temp

c:\temp\1
2
3
4
ther are 4 folders. i want copy folder 3 only.

if i robocopy c:\temp\3 . it only copy what within folder 3 , not folder 3 itself?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,411 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 95,411 Reputation points MVP
    2021-10-09T21:25:37.597+00:00

    Hi @Xu, Tao ,

    you could try the /xd option of robocopy to exclude folders.
    https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#file-selection-options

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. an mac 41 Reputation points
    2023-07-29T04:55:14.9033333+00:00

    Let's say your folder structure is like so:

    c:\temp
    c:\temp\1
    c:\temp\2
    c:\temp\3

    An easier method is to use /lev:1 :

    robocopy C:\temp\3 E:\test[folder name] /lev:1 /dcopy:T
    For example, [folder name] --> change the folder name to any name you want
    C:\temp\3 E:\test\3_copy /lev:1 /dcopy:T

    Therefore, '3_copy' is a copy of folder '3' preserving the original timestamp of '3'

    /dcopy:T (I'm assuming if you want to copy a folder, you also want to copy it's original timestamp to a different location)
    /lev:1 (only copy the '3' folder, no copying subfolders, or files under folder '3')

    I hope this makes sense to you, let me know if you need further clarification

    0 comments No comments