1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB Code to look in all directories

Discussion in 'Software Development' started by gmoukled, Nov 30, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. gmoukled

    gmoukled Thread Starter

    Joined:
    Oct 17, 2011
    Messages:
    33
    I am new to VB 6.0, and I need a code that looks for specific folders and files in my C drive and delete all the files that are older than 2 years.

    My C drive has a lot of folders and sub folders...

    I would like my code to go through the first folder and keep drilling in all the subfolders until it hits the end, and then go back to second folder and do the same etc..., looking for any folder or file older than 2 years.

    Now i do not want the code to delete the folder or file according to the date it was modified , but according to its name.
    The names are of 2 different forms: "yyyy-mm-dd" and "yyyy_mm_dd" ( note the difference between the dash and the underscore)

    for example: today is 2011-11-30, so my code will look for anything earlier than 2009-11-30 and delete it.


    I know this is a bit complicated, I tried to do some research but i did not succeed!

    Your help is appreciated.

    Thanks
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    So you are saying the created date is in the file name?
    Wouldn't the created date in the file name be the same as the created date within the file attribute?
    VB6 is last Century. Why are you still using that?
     
  3. gmoukled

    gmoukled Thread Starter

    Joined:
    Oct 17, 2011
    Messages:
    33
    Let me make this clearer.
    Say a file was originally created 3 years ago, so its name would be 2008-11-30. But some one might modified its content say a year after. So its name would be still 2008-11-30 but the date it was modified would change to 2009-11-30. That is why i want to go according to the names not to the dates they were originally generated.

    I hope this is clearer now!

    Thanks
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    You do realize Windows Keeps track of the Modified Date and Created Date. If you modify a file it doesn't change the Created date within the file attributes. It changes the modified date within the file attributes.
     
  5. gmoukled

    gmoukled Thread Starter

    Joined:
    Oct 17, 2011
    Messages:
    33
    Yes you are right!
    But there are some folders and files in the drive that have some random names ( not a date) and are older than 2 years, but I do not want to delete them ! So if i make the code look for created dates in the attributes and delete the files according to that, it is going to delete everything and not just the files that have dates as names.
     
  6. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    I think your best bet would be to find all the files that are older than two years with the file attributes, then use a regular expression to find the date in the file name. If it has a date then delete. I am not a VB6 guy so I don't know how to code it which is why I asked you why you were doing it in VB6 which for the most part is outdated.
     
  7. gmoukled

    gmoukled Thread Starter

    Joined:
    Oct 17, 2011
    Messages:
    33
    Thank you!

    Can someone else help please?
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1029072

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice