Batch script to archive directory older than N days












0















I have written a windows bat script to Archive the folders that are older than N days. Using this script I am able to Archive and move the files to the Archive folder but I am not able to delete the source folder from the source directory.
(After Archiving the folder and files inside the source is getting moved in the same tree structure to Archive but it is leaving empty folders in the source directory(files are getting deleted leaving empty folders behind))



Script



@echo off
setlocal
set SourceFolder=F:workscriptDestination
set ArchiveFolder=H:TESTArchived
set Age=5
set FileMask=*.*
set LogFile=H:TESTresult.log
>>"%LogFile%" echo ===== Archive job started: %Date% %Time%
==========================
>>"%LogFile%" echo ===== Moving files older than %Age% days.
robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOV /minage:%Age% /r:0
/w:0 /tee /np /log+:"%LogFile%"
>>"%LogFile%" echo =====Archive job done" %Date% %Time%
===============================


I need to modify this by deleting the folders in source after moving. Please suggest.










share|improve this question


















  • 1





    Use the del command to delete things.

    – SomethingDark
    Nov 20 '18 at 3:32






  • 1





    Did you try /move instead?

    – Squashman
    Nov 20 '18 at 3:38











  • robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

    – Ken White
    Nov 20 '18 at 3:40











  • It's in help your error. You are telling to move files only.

    – CatCat
    Nov 20 '18 at 4:25






  • 1





    but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

    – Gerhard Barnard
    Nov 20 '18 at 6:43


















0















I have written a windows bat script to Archive the folders that are older than N days. Using this script I am able to Archive and move the files to the Archive folder but I am not able to delete the source folder from the source directory.
(After Archiving the folder and files inside the source is getting moved in the same tree structure to Archive but it is leaving empty folders in the source directory(files are getting deleted leaving empty folders behind))



Script



@echo off
setlocal
set SourceFolder=F:workscriptDestination
set ArchiveFolder=H:TESTArchived
set Age=5
set FileMask=*.*
set LogFile=H:TESTresult.log
>>"%LogFile%" echo ===== Archive job started: %Date% %Time%
==========================
>>"%LogFile%" echo ===== Moving files older than %Age% days.
robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOV /minage:%Age% /r:0
/w:0 /tee /np /log+:"%LogFile%"
>>"%LogFile%" echo =====Archive job done" %Date% %Time%
===============================


I need to modify this by deleting the folders in source after moving. Please suggest.










share|improve this question


















  • 1





    Use the del command to delete things.

    – SomethingDark
    Nov 20 '18 at 3:32






  • 1





    Did you try /move instead?

    – Squashman
    Nov 20 '18 at 3:38











  • robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

    – Ken White
    Nov 20 '18 at 3:40











  • It's in help your error. You are telling to move files only.

    – CatCat
    Nov 20 '18 at 4:25






  • 1





    but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

    – Gerhard Barnard
    Nov 20 '18 at 6:43
















0












0








0








I have written a windows bat script to Archive the folders that are older than N days. Using this script I am able to Archive and move the files to the Archive folder but I am not able to delete the source folder from the source directory.
(After Archiving the folder and files inside the source is getting moved in the same tree structure to Archive but it is leaving empty folders in the source directory(files are getting deleted leaving empty folders behind))



Script



@echo off
setlocal
set SourceFolder=F:workscriptDestination
set ArchiveFolder=H:TESTArchived
set Age=5
set FileMask=*.*
set LogFile=H:TESTresult.log
>>"%LogFile%" echo ===== Archive job started: %Date% %Time%
==========================
>>"%LogFile%" echo ===== Moving files older than %Age% days.
robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOV /minage:%Age% /r:0
/w:0 /tee /np /log+:"%LogFile%"
>>"%LogFile%" echo =====Archive job done" %Date% %Time%
===============================


I need to modify this by deleting the folders in source after moving. Please suggest.










share|improve this question














I have written a windows bat script to Archive the folders that are older than N days. Using this script I am able to Archive and move the files to the Archive folder but I am not able to delete the source folder from the source directory.
(After Archiving the folder and files inside the source is getting moved in the same tree structure to Archive but it is leaving empty folders in the source directory(files are getting deleted leaving empty folders behind))



Script



@echo off
setlocal
set SourceFolder=F:workscriptDestination
set ArchiveFolder=H:TESTArchived
set Age=5
set FileMask=*.*
set LogFile=H:TESTresult.log
>>"%LogFile%" echo ===== Archive job started: %Date% %Time%
==========================
>>"%LogFile%" echo ===== Moving files older than %Age% days.
robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOV /minage:%Age% /r:0
/w:0 /tee /np /log+:"%LogFile%"
>>"%LogFile%" echo =====Archive job done" %Date% %Time%
===============================


I need to modify this by deleting the folders in source after moving. Please suggest.







batch-file






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 3:27









Ebison JEbison J

12




12








  • 1





    Use the del command to delete things.

    – SomethingDark
    Nov 20 '18 at 3:32






  • 1





    Did you try /move instead?

    – Squashman
    Nov 20 '18 at 3:38











  • robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

    – Ken White
    Nov 20 '18 at 3:40











  • It's in help your error. You are telling to move files only.

    – CatCat
    Nov 20 '18 at 4:25






  • 1





    but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

    – Gerhard Barnard
    Nov 20 '18 at 6:43
















  • 1





    Use the del command to delete things.

    – SomethingDark
    Nov 20 '18 at 3:32






  • 1





    Did you try /move instead?

    – Squashman
    Nov 20 '18 at 3:38











  • robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

    – Ken White
    Nov 20 '18 at 3:40











  • It's in help your error. You are telling to move files only.

    – CatCat
    Nov 20 '18 at 4:25






  • 1





    but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

    – Gerhard Barnard
    Nov 20 '18 at 6:43










1




1





Use the del command to delete things.

– SomethingDark
Nov 20 '18 at 3:32





Use the del command to delete things.

– SomethingDark
Nov 20 '18 at 3:32




1




1





Did you try /move instead?

– Squashman
Nov 20 '18 at 3:38





Did you try /move instead?

– Squashman
Nov 20 '18 at 3:38













robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

– Ken White
Nov 20 '18 at 3:40





robocopy /? from a command prompt will show you the options available. Make an effort to figure it out yourself using that information.

– Ken White
Nov 20 '18 at 3:40













It's in help your error. You are telling to move files only.

– CatCat
Nov 20 '18 at 4:25





It's in help your error. You are telling to move files only.

– CatCat
Nov 20 '18 at 4:25




1




1





but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

– Gerhard Barnard
Nov 20 '18 at 6:43







but you are using /MOV which only moves and deletes files after copying, rather use /MOVE you can also look at /PURGE so try this instead. robocopy.exe "%SourceFolder%" "%ArchiveFolder%" /s /MOVE /minage:%Age% /r:0

– Gerhard Barnard
Nov 20 '18 at 6:43














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385784%2fbatch-script-to-archive-directory-older-than-n-days%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385784%2fbatch-script-to-archive-directory-older-than-n-days%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?