|
-
Jan 26th, 2009, 01:45 PM
#1
Thread Starter
Addicted Member
vb6 - Delete folder with yesterdays date
Hi everybody, can someone kindly tell me the most simple way to delete a specific folder with yesterdays date.
My code creates a test folder everyday with the current date.
fso.createfolder "c:\" & "Test" & Date$
what i want to do is to that before the code creates folder with current date, it should delete folder with the name "Test" alongwith yesterdays date...
if fso.folderexist("c:\" & "Test" & Date$-1) = True then
fso.deletfolder "c:\" & "Test" & Date$-1
fso.createfolder "c:\" & "Test" & Date$
But it doesn't delete and i know something wrong with the underlined code.
Thanx!!!!!!!!!!
-
Jan 26th, 2009, 01:52 PM
#2
Re: vb6 - Delete folder with yesterdays date
One problem is that Date$ does not return a date - it returns a String containing a formatted representation of a date.
You can use (Date - 1) to get yesterdays date, and when you append it to a String it will be formatted the same way as Date$
An important thing to note is that the formatting used in either of these cases is dependent on the options in "Control Panel"->"Regional Settings", so if that ever changes your code will not find the previous folder. It would probably be better to use the Format function to specify the formatting.
-
Jan 26th, 2009, 02:29 PM
#3
Re: vb6 - Delete folder with yesterdays date
I think you have to delete the files in the folder before deleting the folder
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Jan 26th, 2009, 03:50 PM
#4
Junior Member
Re: vb6 - Delete folder with yesterdays date
You have to strip the date from time. If you compare date to date they will never equal and this is for a simple reason. The date field has hours, minutes, seconds. So, compare only the date stripped from time in both cases and this should work.
-
Jan 26th, 2009, 03:59 PM
#5
Re: vb6 - Delete folder with yesterdays date
 Originally Posted by tfbasta
You have to strip the date from time. If you compare date to date they will never equal and this is for a simple reason. The date field has hours, minutes, seconds. So, compare only the date stripped from time in both cases and this should work.
or you could use the Format command
PHP Code:
Format(Date$,"mm-dd-yyyy")
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jan 26th, 2009, 05:13 PM
#6
Re: vb6 - Delete folder with yesterdays date
As I mentioned above, Date$ returns a formatted String - based on a quick check, the equivalent of Format(Date,"mm-dd-yyyy")
Passing a formatted String (such as Date$) to a function like Format is a very bad idea, as the way the value is interpreted varies based on Regional Settings - and would be the wrong value on my computer (UK date format is dd/mm/yyyy) if the day is 12 or less.
For more information, see the article Why are my dates not working properly? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)
-
Jan 27th, 2009, 10:10 AM
#7
Re: vb6 - Delete folder with yesterdays date
 Originally Posted by si_the_geek
As I mentioned above, Date$ returns a formatted String - based on a quick check, the equivalent of Format(Date,"mm-dd-yyyy")
Passing a formatted String (such as Date$) to a function like Format is a very bad idea, as the way the value is interpreted varies based on Regional Settings - and would be the wrong value on my computer (UK date format is dd/mm/yyyy) if the day is 12 or less.
For more information, see the article Why are my dates not working properly? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)
I tried a test. I changed the regional settings on my computer and set the date to 11-Jan-2009.
If I use a Format(Date$,"mm-dd-yyyy"), it screws up the output.
If I use Format$(Now,"mm-dd-yyyy"), the regional settings do not seem to affect the output.
Aren't both Now() and Date$ returning variants?
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jan 27th, 2009, 10:26 AM
#8
Junior Member
Re: vb6 - Delete folder with yesterdays date
Another way to do it is to convert the date to long. Here is an example.
Code:
fso.createfolder "c:\" & "Test" & CStr(CLng(Date))
'Will give you c:\test39480 for today's date January 26, 2009
'Then tomorrow you can use the following two lines to delete it
if fso.folderexist("c:\" & "Test" & CStr(CLng(Date) - 1))= True then
fso.deletfolder "c:\" & "Test" & CStr(CLng(Date) - 1)
This way no matter what date format or systemdate format you are using it will work.
Good luck,
tfbasta
Last edited by tfbasta; Jan 27th, 2009 at 10:37 AM.
-
Jan 27th, 2009, 10:43 AM
#9
Junior Member
Re: vb6 - Delete folder with yesterdays date
Or if you still want it to be "dd-mm-yyyy" you can do the following changes
Code:
fso.createfolder "c:\" & "Test" & CStr(Format(CDate(CLng(Date)), "DD-MM-YYYY"))
'Will give you c:\test39480 for today's date January 26, 2009
'Then tomorrow you can use the following two lines to delete it
if fso.folderexist("c:\" & "Test" & CStr(Format(CDate(CLng(Date) - 1), "DD-MM-YYYY")) = True then
fso.deletfolder "c:\" & "Test" & CStr(Format(CDate(CLng(Date) - 1), "DD-MM-YYYY"))
Please note that Date is a vb function that returns today's date.
-
Jan 27th, 2009, 12:35 PM
#10
Re: vb6 - Delete folder with yesterdays date
CDate(CLng(Date)) does more work than it needs to - just using Date by itself will give the same results (but if you use Now rather than Date, you would need that extra work to remove the time portion).
 Originally Posted by abhijit
I tried a test. I changed the regional settings on my computer and set the date to 11-Jan-2009.
If I use a Format(Date$,"mm-dd-yyyy"), it screws up the output.
If I use Format$(Now,"mm-dd-yyyy"), the regional settings do not seem to affect the output.
That is to be expected.
Aren't both Now() and Date$ returning variants?
As the FAQ article explains, no.
Now and Date (without a $) return Variant with a sub-type of Date, which is essentially the same thing as a Date.
Date$ (with a $) returns a String.
-
Jan 28th, 2009, 01:20 AM
#11
Thread Starter
Addicted Member
Re: vb6 - Delete folder with yesterdays date
Thanx to all!!!
Based on your suggestions i am trying to test and figure out the best possible solution for my code. Will update u guyz shortly...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|