File.GetCreationTime and For Each... Question

Gearhead7

Member
Joined
Jul 17, 2006
Messages
10
Programming Experience
Beginner
*Code inside* File.GetCreationTime and For Each... Question

Well, it stands obvious i am building a app to do some simple stuff. Bassically I'm trying to make it pull a date from a text file. Then compare that date to the creation date of files in a directory with multipe sub directories.So, question is.

1. To compare mulitple dates within mulitple directories in a loop, can i build an 1-d array for subdirectory names and one for files names, then use those as the (dir(y)) and (file(x)) in a File.GetCreationdate(dir(y)+(file(x)) where the " x " is incremented by one at the end of each part of the file loop. When it reaches the end of the file array, it steps up one in the (dir(y)) array, zeros' out the "X" for the file array, and does goes back to the (file(x)) array again? If so, what object / method would you suggest to build the arrays?

2. Can you nest "For Each / Next" statements. We never got to that chapter in text books and I'm reading it right now. :)

Thank you in advance. I'll post a code sample when I put it together. The timing is based on free time... works has been a pain in rear lately.
 
Last edited:
Ok, i just found the "System.IO.Directory.GetFiles(ByValString, ByValString)String()" after digging a bit and I beleive it will place the name of files into an array for me. This would be great. If i can build that array, I can then build a "For Each" to compare the dates for each var in the array. Does that sound like it will work?
 
Here is the code i've come up with. I am sure it's got problems, but it's definately a start. :) Please offer some suggestions.

VB.NET:
[SIZE=2][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] dirName [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] dir
file = System.IO.Directory.GetFiles(dirName)
[/SIZE][SIZE=2][COLOR=#0000ff]   For[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] fileName [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] file
      totFileLoc = dirName & fileName
      currDate = System.IO.File.GetCreationTime(fileName)
[/SIZE][SIZE=2][COLOR=#0000ff]         If[/COLOR][/SIZE][SIZE=2] currDate > lastDate [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]            endDir = "Y:\" & dirName & fileName
            System.IO.File.Copy(totFileLoc, endDir)
[/SIZE][SIZE=2][COLOR=#0000ff]         End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]      Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]
 
Last edited:
Paszt, that helps out a bit. The only problem is that I need to do a date comparison for each file. I need to go in and compare the date of the file to the last run date of the application, and copy it if it the files date is newer then the last run. I would also like to build a lable control that would show which file is being copied.
 
When I previoiusly ran though the code (very quickly, was in the middle of job duties) it didn't seem to have that ability. I will spend some time on the suggested code to better understand and see if it will cover what I am looking for.
 
Back
Top