Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 21st, 2006, 12:54 PM   #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
Old Jul 21st, 2006, 4:21 PM   #2
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Ok, I got it so that the array's worked and did a file list to a text box for the files in a dir and so on. Here's the code if your interested. I put it in the click event of the uiGoButton.

 Dim path As String
        Dim dir, file As Object
        Dim dirName, fileName As String


        Me.uiOutputTextBox.Text = ""

        'Gets the directory to search and assigns to variable
        path = Me.uiLocationTextBox.Text



        file = System.IO.Directory.GetFiles(path)
        For Each fileName In file
            Me.uiOutputTextBox.Text = (Me.uiOutputTextBox.Text & fileName & ControlChars.NewLine)
        Next

        dir = System.IO.Directory.GetDirectories(path)
        For Each dirName In dir
            Me.uiOutputTextBox.Text = (Me.uiOutputTextBox.Text & dirName & ControlChars.NewLine)
            file = System.IO.Directory.GetFiles(dirName)
            For Each fileName In file
                Me.uiOutputTextBox.Text = (Me.uiOutputTextBox.Text & "     " & fileName & ControlChars.NewLine)
            Next
        Next
    End Sub

Let me know what you think.
__________________
_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
Old Jul 21st, 2006, 4:26 PM   #3
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
Here's a screenshot.
__________________
_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
Old Jul 21st, 2006, 5:37 PM   #4
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 319
Rep Power: 4 andro is on a distinguished road
Send a message via AIM to andro
What's with the forward slashes? I was under the impression that Windows uses backslashes.
andro is offline   Reply With Quote
Old Jul 22nd, 2006, 12:09 AM   #5
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
For some odd reason, it didn't care. I couldn't tell you. I know w/ most things it is the "\" .
__________________
_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
Old Jul 22nd, 2006, 9:15 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
If you're going to use forward-slashes, you don't need to double them up. That only works because Windows treats C:\\WINDOWS as C:\WINDOWS (after the text has been parsed), and I believe all forward-slashes are converted to backslashes when using them in Windows paths.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 22nd, 2006, 9:40 AM   #7
randum77
Programmer
 
randum77's Avatar
 
Join Date: Jun 2006
Location: Fayettehell, NC
Posts: 56
Rep Power: 3 randum77 is on a distinguished road
I beleive your right. It just ended up like that when i was having problems with something else. Forgot to change it back since it did't pose any problems. I'm just etstatic that the thing works.
__________________
_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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete File Before a Certain date bobrivers Bash / Shell Scripting 4 Nov 10th, 2005 5:43 AM
date question rjbrynteson ASP 3 Oct 19th, 2005 4:24 PM
Php Postgresql Class Pizentios Show Off Your Open Source Projects 15 Jun 28th, 2005 10:55 AM
Date Method Abyss Java 2 Apr 10th, 2005 9:47 AM
Enquiry About Visual Basic Project kbkhoo5053 Visual Basic 13 Feb 15th, 2005 3:20 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC