A question for you...
Well here are my scenario...
User is suppose to enter starting date: dd-mm-yyyy into a textbox provided and enter ending date: dd-mm-yyyy into respective textbox. The program would have to trace the path, dir based on the date entered.
My problems are how am I suppose to let my vb program to create folders consisting of all files from starting date to the ending date? pls advise..thanks
Not really...the user will have to enter 2 dates: one for start date and another for end date.
The path and directory for both date folders are located at
start date: C:\PG\CW\01-01-2001\ and
end date: C:\PG\CW\20-01-2001\ respectively.
I need to save all *.dat files from 01-01-2001 folder until 20-01-2001 folder into a A:\ drive. The A:\ will have to generate the sample output as shown below
A:\PG\CW\01-01-2001\a.dat
A:\PG\CW\01-01-2001\b.dat
A:\PG\CW\01-01-2001\c.dat
A:\PG\CW\02-01-2001\a.dat
A:\PG\CW\03-01-2001\a.dat
A:\PG\CW\04-01-2001\a.dat
......until
A:\PG\CW\20-01-2001\a.dat
A:\PG\CW\20-01-2001\b.dat
A:\PG\CW\20-01-2001\c.dat
Is it clear now? How am I suppose to tackle this problem?
'Search for PG\CW directory
Do While BckDir <> ""
If BckDir <> "." And BckDir <> ".." Then
If GetAttr(InitPath & BckDir) = vbDirectory Then
If BckDir = "CW" Then
DirFlag = "Y"
End If
End If ' it represents a directory.
End If
BckDir = Dir
Loop
' Create CW if not found
If DirFlag = "N" Then
MkDir "A:\PG\CW"
End If
End Sub
--------------------------------------------------------------------------------
Thanks!
For the error handling on creating the folders there are two main methods - the one you have, and ignoring all errors (by having an extra line just before this code: On Error Resume Next ). In this case I think that your method would be better. (you would be better of making a function to do the Dir bit and MkDir if needed).
You will probably need to make use of the FSO, so add a reference to Microsoft Scripting Runtime.
You will need a process something like:
Code:
Set up and validate YourStartDate
Set up and validate YourEndDate
Set up the FSO
Set FolderBase to "C:\pg\cw"
For each thisFolder in FolderBase.Folders
If thisFolder > YourStartDate
If thisFolder < YourEndDate
Check thisFolder is present on A:\PG\CW
For each file in thisFolder.Files
CopyFile file to A:\PG\CW & thisFolder
Next
End If
End If
Next
Set up routines in VB to:
- enter and validate a date from the user.
- check a folder exists
- Create fodlers as required (see previous post)
- check a date is before or after another date
Thanks a lot..
As a new programmer, I still have doubts for your instructions...
What is FSO and what does it do?
As for your previous code..(the earlier one), it doesn't output the way it should. perhaps you can give me any extra advice...thanks
FSO = File Scripting Object. Allows you to do things with files, like stepping through every file in a folder, or every sub-folder in a folder. Its not strictly needed, but using it will be easier for you than trying to do recursion with DIR() functions.
As for your previous code..(the earlier one), it doesn't output the way it should.
Yes it does. But it might not output the way you want it to! :-)
Tell us which code, and what you need to be different, AND what you have tried so far so we don't duplicate your work.
Hello here is the attachment of my program, i have highlighted my questions with remarks....the bottom part. The top portion generally works well...
the bottom part, .... I can't seem to get the date right yet. please advise....thanks in advance