hie guys
i want to create a project which would cut and paste txt files one at a time from a directory to another at an interval of about a second apart. can anybody explain how i can do this.
Printable View
hie guys
i want to create a project which would cut and paste txt files one at a time from a directory to another at an interval of about a second apart. can anybody explain how i can do this.
Just add a timer to the form, set the Interval property to 1000 and enable it when you want the process to start.
In the Timer Tick routine just add this:
Although, what if the previous file hasn't completed being transferred and you try to start another transfer? Would this cause an error? I don't know if the way you want to do this is exactly correct.Code:My.Computer.FileSystem.MoveFile("\SourceFile.txt", "\NewDestinationFile.txt", True)
i did clealy show were i needed help but thanks for that either. i would like to know how i would write the code to select only text files from the folder regardless of the text file name, cut it then paste to the destination folder.
You would use the Directory.GetFiles method. The documentation will show you how to filter the results.
i have tryied this (below) and im an having a problem in passing the value of "filename1" to the movefile source and destination the reason being filename1 can not be converted to string. can somebody explain to me how i can pass the values such that i will have a unique value for each loop not specifying the name as on the example.
Code:'Dim MyString As String
Dim di As New IO.DirectoryInfo("c:\GARA")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim filename1 As IO.FileInfo
For Each filename1 In diar1
My.Computer.FileSystem.MoveFile("c:\GARA\test.txt", "C:\GARA1\test.txt", True)
'MyString = MyString & CStr(filename1)
'MsgBox "& filename1& "<br />""
If Then
Exit For
End If
Next
Code:Dim di As New IO.DirectoryInfo("c:\GARA\")
Dim diar1 As IO.FileInfo() = di.GetFiles("*.txt") 'add filter
For Each filename1 As IO.FileInfo In diar1
My.Computer.FileSystem.MoveFile(filename1.FullName, "C:\GARA1\" & filename1.Name, True)
Next
Thanks So Much Stimbo.
That Means If I Want To Set My Timer To Say 3 Seconds I Will Just Write The Code Under Timer1 And Set The Interval To 3000 Is It? Such That The Loop Will Run After 3 Seconds
anyone help please
Help with what?
as i had explained ealier, i want my tool to move one text file at a time with an interval of 3 seconds. i made my declarations pablic and under timer i specified the move command and set my inteval but im having an error of which this is were i need help, "variable used before it is assigned a value" and if i put my index it also gives me the same err can not be indexed because of the above err'sand the code and declarations are as followsfor the declaractions and for timerCode:Dim di As New IO.DirectoryInfo(txtsource.Text)
Dim diar1 As IO.FileInfo() = di.GetFiles("*.txt") 'add filter
Dim mycounter As Integer = 0
Dim files As IO.FileInfo
Code:My.Computer.FileSystem.MoveFile(files(mycounter).FullName, txtdestination.Text & files.Name, True)
txtnowexporting.Text = files.FullName
mycounter = mycounter = 1
Yes you explained it earlier, the code has pretty much been written for you, but you didn't mention what the current problem is and I'm not a mind reader so didn't know what errors you were getting as you didn't explain or show the new code that was causing the problems.
What is this supposed to do??
mycounter = mycounter = 1
Do you mean: myCounter = myCounter + 1
I think the main problem is that you have declared the variable myCounter in one sub routine and are try to use it in another which you can't do. You have to declare the variable at the form level (usually under the Public Class Form1 line of code if you haven't renamed your form).
as on my above post i have declared mycounter on the public declarations and my concern is on the errors on how i can assign a value to filesQuote:
Originally Posted by GARAKWAZVO
Stimbo asked a question:Stimbo also said:Quote:
Originally Posted by stimbo
You've now said this:Quote:
Originally Posted by stimbo
You haven't answered stimbo's question and you are still yet to tell us what errors you're talking about. Stimbo is not the only one here who isn't a mind-reader. If you really do want us to provide a solution then you will provide us with the information we need. How can we solve the problem if we don't know what the problem is?Quote:
Originally Posted by GARAKWAZVO
the higlighted areas are giving "cannot be indexed because it has no default property". how can i get rid of that error.Quote:
Originally Posted by GARAKWAZVO
i have also corrected the line to what it should have looked like at the first place.
Hi,
you define
then you used in 2 waysCode:Dim files As IO.FileInfo
So, "files" is an instance or a 1D array?Code:My.Computer.FileSystem.MoveFile(files(mycounter).FullName, txtdestination.Text & files.Name, True)
txtnowexporting.Text = files.FullName
That's where the problem is. You are trying to use a FileInfo object as an array which you can't. Here is what you probably want to do:
vb Code:
'FORM level variables Dim myCounter As Integer = 0 Dim myFiles() As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Try myFiles = IO.Directory.GetFiles("C:\GARA\", "*.txt") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Try If myCounter <= myFiles.Length - 1 Then My.Computer.FileSystem.MoveFile(myFiles(myCounter), "C:\GARA1\" & IO.Path.GetFileName(myFiles(myCounter))) myCounter += 1 End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
thats exactly what i was looking for thanks so much