View Single Post
Old Jul 21st, 2006, 11:54 AM   #1
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Creation date comparison for subdirectories

I need to move files from one drive to another. I have an application that will run on a given frequency to do this. Also, i do not want to move files that were moved the last time this application ran. Being that I am fairly new to programming, i figured i would think out loud and hopefully, if I a missing anything (other the grammer) that someone could point it out. Here are the steps I want to accomplish.

1. Check for drives that are mapped
2. Check last run date
3. Run, do a date compairson for each file in each directory on a given directory. If the file is newer, copy, if not, skip.
4. Renew last run date
5. Close

I am making this a *.exe file so no one can mess w/ the code. People around here have tendency to think they are fixing things, when they are not. So, all the following is going to be put in a load event.

So, for part 3 this is the code I am going to use.

        Dim path As String = "y:\filehere.txt" 'File for checking mapped drive
        Dim file(), dir() As Object 'Array variables
        Dim dirName, fileName, totFileLoc, endDir As String 'Used in For Each
        Dim lastDate, currDate As DateTime 'Last run and Creation DateTime
        
        dir = System.IO.Directory.GetDirectories("C:\application\reports")

        For Each dirName In dir
            file = System.IO.Directory.GetFiles(dirName)
            For Each fileName In file
                totFileLoc = dirName & fileName
                currDate = System.IO.File.GetCreationTime(fileName)
                If currDate > lastDate Then
                    endDir = "Y:\" & dirName & fileName
                    System.IO.File.Copy(totFileLoc, endDir)
                End If
            Next
        Next

I used the full Class.Object.Method names for learning purposes. In the future will be assigning the Call.Object to variables. Do you think this code will succesffuly get the directories and files and do the comparison? Bassically for each directory it will get a list of files and compare the dates. Once I get the function working, i'll build a "Working Bar" for the user interaction.
__________________
_Marshall_

"America has bred a society that is innocent and incapable of accepting responsibility, but yet, is able to place blame on others without guilt."
randum77 is offline   Reply With Quote