|
-
Oct 18th, 2007, 02:51 AM
#1
Thread Starter
Member
[RESOLVED] [2005] cut and paste
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.
-
Oct 18th, 2007, 03:04 AM
#2
Re: [2005] cut and paste
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:
Code:
My.Computer.FileSystem.MoveFile("\SourceFile.txt", "\NewDestinationFile.txt", True)
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.
-
Oct 18th, 2007, 05:41 AM
#3
Thread Starter
Member
Re: [2005] cut and paste
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.
-
Oct 18th, 2007, 05:46 AM
#4
Re: [2005] cut and paste
You would use the Directory.GetFiles method. The documentation will show you how to filter the results.
-
Oct 19th, 2007, 04:08 AM
#5
Thread Starter
Member
Re: [2005] cut and paste
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
-
Oct 19th, 2007, 04:19 AM
#6
Re: [2005] cut and paste
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
-
Oct 19th, 2007, 04:33 AM
#7
Thread Starter
Member
Re: [2005] cut and paste
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
-
Oct 22nd, 2007, 03:20 AM
#8
Thread Starter
Member
-
Oct 22nd, 2007, 03:33 AM
#9
-
Oct 22nd, 2007, 03:48 AM
#10
Thread Starter
Member
Re: [2005] cut and paste
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 follows
Code:
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
for the declaractions and for timer
Code:
My.Computer.FileSystem.MoveFile(files(mycounter).FullName, txtdestination.Text & files.Name, True)
txtnowexporting.Text = files.FullName
mycounter = mycounter = 1
-
Oct 22nd, 2007, 03:53 AM
#11
Re: [2005] cut and paste
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).
-
Oct 22nd, 2007, 04:48 AM
#12
Thread Starter
Member
Re: [2005] cut and paste
 Originally Posted by GARAKWAZVO
Code:
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
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 files
-
Oct 22nd, 2007, 04:58 AM
#13
Re: [2005] cut and paste
Stimbo asked a question:
 Originally Posted by stimbo
What is this supposed to do??
mycounter = mycounter = 1
Do you mean: myCounter = myCounter + 1
Stimbo also said:
 Originally Posted by stimbo
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.
You've now said this:
 Originally Posted by GARAKWAZVO
my concern is on the errors
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?
-
Oct 22nd, 2007, 05:16 AM
#14
Thread Starter
Member
Re: [2005] cut and paste
 Originally Posted by GARAKWAZVO
Code:
My.Computer.FileSystem.MoveFile(files(mycounter).FullName, txtdestination.Text & files.Name, True)
txtnowexporting.Text = files.FullName
mycounter = mycounter + 1
the higlighted areas are giving "cannot be indexed because it has no default property". how can i get rid of that error.
i have also corrected the line to what it should have looked like at the first place.
-
Oct 22nd, 2007, 06:15 AM
#15
Lively Member
Re: [2005] cut and paste
Hi,
you define
Code:
Dim files As IO.FileInfo
then you used in 2 ways
Code:
My.Computer.FileSystem.MoveFile(files(mycounter).FullName, txtdestination.Text & files.Name, True)
txtnowexporting.Text = files.FullName
So, "files" is an instance or a 1D array?
-
Oct 22nd, 2007, 07:30 AM
#16
Re: [2005] cut and paste
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
-
Oct 22nd, 2007, 09:01 AM
#17
Thread Starter
Member
Re: [2005] cut and paste
thats exactly what i was looking for thanks so much
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
|