Qlik Community

QlikView Deployment

Discussion Board for collaboration related to QlikView Deployment.

Not applicable

Batch file script to remove older folders automatically

Hi,

I need to remove older folders  automatically after a specific period  in my directory,

I need to execuit the batch script to remove the older folders,can any one help me regarding the same

Regards,

Kiruthiga

5 Replies
jsn
Honored Contributor

Batch file script to remove older folders automatically

Hey,

Here's a vbscript example for removing a folder:

dim filesys, demofolder

set filesys = CreateObject ("Scripting.FileSystemObject")

set demofolder = filesys.GetFolder("c:\projects\")

demofolder.Delete

This can be run from a batch file or from a QV macro with System access privilege.

Not applicable

Batch file script to remove older folders automatically

Hi Johannes,

        Thanks for your reply,actually I need a batch file that keeps the 3 latest folder dates and deletes the rest.

        The folder format is YYYYMMDD
Thanks again,
Kiruthiga
jsn
Honored Contributor

Batch file script to remove older folders automatically

Hey,

That additional info raises further questions.

1. How often do you run the script?

2. How often are new folders created? Daily? Weekends as well?

If it's always one folder a day, even on weekends, and you run the batch daily, you can just tell it to delete the folder from 4 days ago.

Otherwise you'll need to program some logic in there.

One example can be found at the bottom here where you create an array of all folders available and add the three latest ones to the exclusion list:

http://www.visualbasicscript.com/VBS-to-delete-all-empty-subfolders-in-a-directory-except-what39s-in...

Not applicable

Re: Batch file script to remove older folders automatically

hi,

Why overcomplicate things? Can you just delete files and folders older than X days ?

http://blog.stevienova.com/2007/02/27/forfiles-delete-files-older-than-x-amount-of-days/

FORFILES /P C:\MyPath\ /S /M log*.xml /D -30 /C "cmd /c del @file"

/S – look at subdirectories

log*.xml – that is the file pattern, you could have it be like *.txt for example

/D -30 = files greater than 30 days

/C – thats the command you want to run

this is pretty much a one line command that could replace a ton of vbScripts, batch files, and other apps I have seen over the years to clean up files. Something for every sys admin’s toolbelt.

-Alex

http://www.snowflakejoins.com

Not applicable

Batch file script to remove older folders automatically

Hi,

I have tried the following comments in a batch file,

mkdir c:\temp\OldDirectoriesGoHere

robocopy c:\logs\SoManyDirectoriesToDelete\ c:\temp\OldDirectoriesGoHere\ /move /minage:3

rmdir /s /q c:\temp\OldDirectoriesGoHere

but the problem with the above script is that all the files got deleted irrespective of the time span,I need to remove the files  which are older than 3 days only

In my case the new files get added daily,so I need to execuit the batch file daily to remove the older once

Thanks again,

Kiruthi

Community Browser