|
-
Jan 23rd, 2008, 09:23 AM
#1
Thread Starter
Member
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
-
Jan 23rd, 2008, 09:25 AM
#2
Re: copying files
what does the dos xcopy command do?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 09:26 AM
#3
Thread Starter
Member
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.
-
Jan 23rd, 2008, 09:52 AM
#4
-
Jan 23rd, 2008, 11:00 AM
#5
Thread Starter
Member
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
-
Jan 23rd, 2008, 11:07 AM
#6
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.
-
Jan 23rd, 2008, 11:31 AM
#7
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.
-
Jan 23rd, 2008, 12:00 PM
#8
Thread Starter
Member
Re: copying files
that is a much better way thanks! only one problem though
FileInfo() is not declared
sorry for the hassle
masterhoulahan
-
Jan 23rd, 2008, 12:01 PM
#9
Re: copying files
 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.
-
Jan 23rd, 2008, 12:10 PM
#10
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|