Home > Software engineering >  How to use VB to selectively delete folder
How to use VB to selectively delete folder

Time:09-16

 
If Dir (integrated, vbDirectory) & lt; & gt; "" Then
The Shell "CMD/rd/s/q" c "" & amp; The integrated & amp; "" ""
End the If


This command is used to delete all folders and files under the integrated and how to keep the latest 2 months, other all delete



Under the integrated will be
.
The 2019-05
.
The 2019-09
.
The 2020-06
The 2020-07
The 2020-08
The 2020-09 (the current month)

How to keep the 2020-08 and 2020-09 it two months, delete all other folder

Thank you!!!!!!

CodePudding user response:

According to judge what is the latest two months? The folder name? The folder creation time? The modification time of the latest file folder?

If the folder name,
Year (Now) & amp; "-" & amp; Format (Day (Now), and "00")
you can get the current monthYear (Now) & amp; "-" & amp; Format (Day (DateAdd (" m ", 1, Now)), and "00") can get last month
Not these two, just delete

CodePudding user response:

reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
according to judge what is the latest two months? The folder name? The folder creation time? The modification time of the latest file folder?

If the folder name,
Year (Now) & amp; "-" & amp; Format (Day (Now), and "00")
you can get the current monthYear (Now) & amp; "-" & amp; Format (Day (DateAdd (" m ", 1, Now)), and "00") can get last month
Not these two, just delete


This I know, just don't know with what method, can eliminate these two folders, delete the other, in what order

CodePudding user response:

refer to the second floor waaoo response:
Quote: reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
according to judge what is the latest two months? The folder name? The folder creation time? The modification time of the latest file folder?

If the folder name,
Year (Now) & amp; "-" & amp; Format (Day (Now), and "00")
you can get the current monthYear (Now) & amp; "-" & amp; Format (Day (DateAdd (" m ", 1, Now)), and "00") can get last month
Not these two, just delete


This I know, just don't know with what method, can eliminate these two folders, delete the other, what command


To determine the

CodePudding user response:

reference 3 floor of guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
Quote: refer to the second floor waaoo response:
Quote: reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
according to judge what is the latest two months? The folder name? The folder creation time? The modification time of the latest file folder?

If the folder name,
Year (Now) & amp; "-" & amp; Format (Day (Now), and "00")
you can get the current monthYear (Now) & amp; "-" & amp; Format (Day (DateAdd (" m ", 1, Now)), and "00") can get last month
Not these two, just delete


This I know, just don't know with what method, can eliminate these two folders, delete the other, what command


Judgment under


I mean, I know that the two folders, I don't know what kind of code can eliminate these two, delete the other,
  • Related