Search code examples
attributesbatch-processingarchivefile-managementorganizer

Move non-archived files and set their attribute to archived in destinaton directory


I am doing an autoorganizing CMD that puts all desktop files into their respective folders. I wish a code that moved files from a folder to it's parent only if they weren't archived (archived attribute), and then archived the files in the other dir. In the least lines possible.

An example of unfinished code, replace "only move files if archived" with the code I need...

"only move files if archived"
attrib +a ..\*.*

Solution

  • Use robocopy.

    • /ia: processes files with the specified attributes only:

      robocopy "source-folder" "destination-folder1" /ia:a /move
      
    • /xa: excludes files with the specified attributes:

      robocopy "source-folder" "destination-folder2" /xa:a /move 
      

    To get the desktop folder into %desktop% variable:

    for /f "skip=2 tokens=2*" %%a in (
        'reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
        ^ /v Desktop'
    ) do call set desktop=%%b