locked
Adding files to archives RRS feed

  • General discussion

  • Hi Expert,

    I wanted to move the files to archive folder except the max time stamp in system date modified available in the file and wanted to do it for four different folder like folder 3 will go to folder4 and folder 5 to folder 6 i.e.folderfile1 has system date modified 12:00 AM and file 2 has 12:21 AM then file 1 will archive in this way it has to archive all remaining file which is less than latest date modified.

    i tried

    @Echo Off
    Set "dirSrc=C:\App\Folder1"
    Set "dirDst=C:\App\Folder2"
    Set "extSrc=*.txt"
    If Exist "%dirSrc%\%extSrc%" (CD /D "%dirSrc%" 2>Nul || Exit /B
    ) Else Exit /B
    If Not Exist "%dirDst%\" (MD "%dirDst%" 2>Nul || Exit /B)
    For /F "Skip=1 Delims=" %%A In ('Dir /B/A-D-H-L-S/O-D/TW "%extSrc%"'
    ) Do Move /Y "%%A" "%dirDst%">Nul 2>&1


    • Edited by shree3 Wednesday, May 16, 2018 5:59 AM
    • Changed type Bill_Stewart Tuesday, July 10, 2018 7:57 PM
    • Moved by Bill_Stewart Tuesday, July 10, 2018 7:57 PM This is not "scripts on demand"
    Wednesday, May 16, 2018 5:59 AM

All replies

  • What errors are you getting from your script? its hard to know how to fix something when we don't know what's broken :)


    Learn PowerShell                     Script Requests

    -Remember to mark the correct response as the answer-

    Wednesday, May 16, 2018 9:22 AM
  • can you help me with fresh script for moving file

    just wanted to move folder1 to folder2 except the max time stamp in system date modified available

    Wednesday, May 16, 2018 12:30 PM
  • We do not write ready to use code or scripts on request.

    Please read this first: This forum is for scripting questions rather than script requests.

    Also find scripts here: PowerShell Gallery or here: TechNet Gallery - resources for IT professionals.

    Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell.

    Script requests: Microsoft Technet Script Center - Requests.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, May 16, 2018 12:56 PM
  • @Echo Off Set "dirSrc=C:\App\Folder1" Set "dirDst=C:\App\Folder2" Set "extSrc=*.txt" If Exist "%dirSrc%\%extSrc%" (CD /D "%dirSrc%" 2>Nul || Exit /B ) Else Exit /B If Not Exist "%dirDst%\" (MD "%dirDst%" 2>Nul || Exit /B) For /F "Skip=1 Delims=" %%A In ('Dir /B/A-D-H-L-S/O-D/TW "%extSrc%"' ) Do Move /Y "%%A" "%dirDst%">Nul 2>&1

    ok tested this script is working...i wanted add for 6 more folders..can you helpe with logic

    Wednesday, May 16, 2018 2:45 PM
  • ok tested this script is working...i wanted add for 6 more folders..can you helpe with logic

    This isn't the right forum to ask for people to update/fix scripts to specifications.

    In any case we would greatly recommend PowerShell rather than cmd.exe shell script (batch). PowerShell script code is much easier to read and update. You can get started by using the Learn link at the top of this forum.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, May 16, 2018 3:27 PM