Results 1 to 10 of 10

Thread: copying files

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    copying files

    Hi i was wondering if it would be possible to make a code which was similar to the dos xcopy command like the /D:m-d-y function which the date and location could be inputted by a text boxes ive looked on the forum but could only see copying functions.
    thanks in advance
    masterhoulahan

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: copying files

    what does the dos xcopy command do?

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Re: copying files

    Xcopy is a powerful version of the copy command with additional features; has the capability of moving files, directories, and even whole drives from one location to another.

    /D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: copying files

    I found this

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Re: copying files

    i saw that but i get a error when i try it

    InvalidOperationException was unhandled
    Process must exit before requested information can be determined.

    thanks
    masterhoulahan

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: copying files

    Thats because the code is actually waiting 15 seconds for the process to exit, then it tries to get the ExitCode of the process. However if the process hasnt exited after the 15 second wait, that exception will occur.
    A way better thing to do is to add a handle for the process' Exited event, and perform all code that needs to be done after the process has exited in that event handler instead.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: copying files

    You don't need to go through all the hassles of trying to run the cmd process from .NET. All the functionality of XCOPY can be reproduced using .NET objects

    Code:
    Private _fileDate As DateTime
    
        Private Sub btnCopyFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopyFiles.Click
            
            Dim sOriginDir as String = txtOriginDir.Text
            Dim sDestDir as String = txtDestDir.Text
    
            Dim fileCol As FileInfo() = My.Computer.FileSystem.GetDirectoryInfo(sOriginDir).GetFiles()
    
            _fileDate = txtFileDate.Text
    
            Dim filesToCopy As FileInfo() = Array.FindAll(fileCol, AddressOf FindFile)
    
            For Each fi As FileInfo In filesToCopy
                fi.CopyTo(sDestDir + "\" + fi.Name, True)
            Next
    
        End Sub
    
        Private Function FindFile(ByVal pFile As FileInfo) As Boolean
    
            If pFile.LastWriteTime > _fileDate Then
                Return True
            Else
                Return False
            End If
    
        End Function
    That will grab any files in a given directory that have been modified after a given date and copy them to another directory. You can also customize it as you see fit, rather than trying to pass a bunch of stuff intoa command line program.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Re: copying files

    that is a much better way thanks! only one problem though

    FileInfo() is not declared

    sorry for the hassle
    masterhoulahan

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: copying files

    Quote Originally Posted by masterhoulahan
    that is a much better way thanks! only one problem though

    FileInfo() is not declared

    sorry for the hassle
    masterhoulahan
    Either use the full path: System.IO.FileInfo, or Import the System.IO namespace.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2006
    Posts
    62

    Re: copying files

    thanks alot! big help all works as i wanted thanks again.
    masterhoulahan.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width