Link to home
Start Free TrialLog in
Avatar of Chandra P
Chandra P

asked on

VB script to delete folders older than 7 days

Hello,

I would like to create a VB script to automatically clears the folders on a shared drive older than 7 days. I tried different codes but nothing deletes the folder all i can do is delete the files.
But i have multiple folder lying on the share path older than 7 days. Any suggestion on  this?


thanks in advance
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Hi,

Take a look at the FileSystemObject and Folder object:
https://msdn.microsoft.com/en-us/library/hww8txat%28v=vs.84%29.aspx
Avatar of Bill Prew
Bill Prew

What do you really want to do?  By that I meant, what do you mean by a folder "older than 7 days"?  Does that mean a folder that contains no files newer than 7 days?  Or something else?  And how would subfolders factor into this, when a folder has both files and folders underneath it, what is the logic/rules to be followed there?


»bp
Avatar of Chandra P

ASKER

I receive a folder contains 4 files everyday. So in the archive directory(shared) i have multiple folders contains 4 files each. Now i need to delete the folders that are older than 7 days.
Now i need to delete the folders that are older than 7 days.

Okay, and how exactly do you want to determine which folders can be deleted?

  • If all the files are older than 7 days?
  • If the folders Windows create date is older than 7 days?
  • Is the date of the folder part of the folder name that should be looked at?
  • Something else?


»bp
yes.. based on the each folder's modified date and no need to consider the folder name.

I did tried with objSubFolder.Delete True but nothing is getting deleted.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wooowwww!!!! Works like a magic!!! Thank you mate!!
Welcome, glad that was useful.


»bp