Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default VB copy files from one folder to other

Hi all, I am using Visual Basic 2008. I am working on code with which
I can copy specified extention files from one folder to other. I need
two codes, one which can copy files of specified extention only from
top main folder and two which can copy files of specified extention
from top main folder as well as from all the subfolder which exist in
that top main folder. In these both codes I also need to have
progress bar code to show user the progress. I am struggling on this
and so far i came up with code (see below) which only copies files
from top main folder and i am getting error on line
"ProgressBar1.Value = (n / Fldrfl.Count) * 100". I'll be very
greatful if any friend can help me on this.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim FldrNm As String
Dim Fso As Object
Dim Fldr As Object
Dim Fldrfl As Object
Dim n As Long

FldrNm = TextBox1.Text
Fso = CreateObject("Scripting.FileSystemObject")
Fldr = Fso.GetFolder(FldrNm)
For Each Fldrfl In Fldr.Files
If Microsoft.VisualBasic.Right(Fldrfl.Name,
Microsoft.VisualBasic.Len(Fldrfl.Name) -
Microsoft.VisualBasic.InStrRev(Fldrfl.Name, ".")) = TextBox2.Text Then
Fldrfl.Copy(TextBox3.Text & "\" & Fldrfl.Name)
n = n + 1
ProgressBar1.Value = (n / Fldrfl.Count) * 100
Application.DoEvents()
End If
Next

Fldrfl = Nothing
Fldr = Nothing
Fso = Nothing

MsgBox("Files have been copied successful!", MsgBoxStyle.Information,
"Done!")
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VB copy files from one folder to other

Hi K,

At a guess I'd suggest that you need:

ProgressBar1.Value = ( n / Fldr.Files.Count ) * 100 ' Untested

I doubt the Fldrfl supports the .Count property - by definition there can be
only 1.

Is there any reason you are declaring your variables as Object rather than
as specified types? If you did this intellisense would probably help you
out.

Regards,

Peter Beach

"K" wrote in message
...
Hi all, I am using Visual Basic 2008. I am working on code with which
I can copy specified extention files from one folder to other. I need
two codes, one which can copy files of specified extention only from
top main folder and two which can copy files of specified extention
from top main folder as well as from all the subfolder which exist in
that top main folder. In these both codes I also need to have
progress bar code to show user the progress. I am struggling on this
and so far i came up with code (see below) which only copies files
from top main folder and i am getting error on line
"ProgressBar1.Value = (n / Fldrfl.Count) * 100". I'll be very
greatful if any friend can help me on this.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim FldrNm As String
Dim Fso As Object
Dim Fldr As Object
Dim Fldrfl As Object
Dim n As Long

FldrNm = TextBox1.Text
Fso = CreateObject("Scripting.FileSystemObject")
Fldr = Fso.GetFolder(FldrNm)
For Each Fldrfl In Fldr.Files
If Microsoft.VisualBasic.Right(Fldrfl.Name,
Microsoft.VisualBasic.Len(Fldrfl.Name) -
Microsoft.VisualBasic.InStrRev(Fldrfl.Name, ".")) = TextBox2.Text Then
Fldrfl.Copy(TextBox3.Text & "\" & Fldrfl.Name)
n = n + 1
ProgressBar1.Value = (n / Fldrfl.Count) * 100
Application.DoEvents()
End If
Next

Fldrfl = Nothing
Fldr = Nothing
Fso = Nothing

MsgBox("Files have been copied successful!", MsgBoxStyle.Information,
"Done!")
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default VB copy files from one folder to other

No, take a look at http://tinyurl.com/yz5lkh5

--

HTH

Bob

"K" wrote in message
...
Hi all, I am using Visual Basic 2008. I am working on code with which
I can copy specified extention files from one folder to other. I need
two codes, one which can copy files of specified extention only from
top main folder and two which can copy files of specified extention
from top main folder as well as from all the subfolder which exist in
that top main folder. In these both codes I also need to have
progress bar code to show user the progress. I am struggling on this
and so far i came up with code (see below) which only copies files
from top main folder and i am getting error on line
"ProgressBar1.Value = (n / Fldrfl.Count) * 100". I'll be very
greatful if any friend can help me on this.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim FldrNm As String
Dim Fso As Object
Dim Fldr As Object
Dim Fldrfl As Object
Dim n As Long

FldrNm = TextBox1.Text
Fso = CreateObject("Scripting.FileSystemObject")
Fldr = Fso.GetFolder(FldrNm)
For Each Fldrfl In Fldr.Files
If Microsoft.VisualBasic.Right(Fldrfl.Name,
Microsoft.VisualBasic.Len(Fldrfl.Name) -
Microsoft.VisualBasic.InStrRev(Fldrfl.Name, ".")) = TextBox2.Text Then
Fldrfl.Copy(TextBox3.Text & "\" & Fldrfl.Name)
n = n + 1
ProgressBar1.Value = (n / Fldrfl.Count) * 100
Application.DoEvents()
End If
Next

Fldrfl = Nothing
Fldr = Nothing
Fso = Nothing

MsgBox("Files have been copied successful!", MsgBoxStyle.Information,
"Done!")
End If
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Files to other folder TISR Excel Programming 4 April 1st 06 08:43 AM
How to copy 30 csv files from a folder to another folder ddiicc Excel Programming 1 July 17th 05 09:42 AM
Copy files from spreadsheet into folder Intotao Excel Discussion (Misc queries) 3 January 27th 05 11:38 PM
Copy same data from all files in folder BENNY Excel Programming 1 June 18th 04 10:52 PM
Copy Files from a folder to new location saybut[_3_] Excel Programming 0 February 10th 04 03:26 PM


All times are GMT +1. The time now is 07:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"