By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

Getting user input for file/ directory copy

P: 4
Hi All,

Is there any way to copy a file/ directory from one location to the other? The file or the directory name should be given by the user. This is the criteria.

For example:
My.Computer.FileSystem.CopyDirectory("C:\abc\<file/dir>", "D:\cde\<File/dir>")

Here the file/dir should be obtained from the user during runtime. Please let me know the code or the logic.

Thanks,
Anup.
Dec 27 '07 #1
Share this Question
Share on Google+
7 Replies


debasisdas
Expert 5K+
P: 8,127
Please find a related discussion here.
Dec 27 '07 #2

VijaySofist
100+
P: 107
Hi Anup!

Use FileSystemObject for this purpose. By using this you can do CopyFile, CopyFolder etc. For this you have to include Microsoft Scripting Runtime Reference in your Project.

Expand|Select|Wrap|Line Numbers
  1. Dim fso as FileSystemObject
  2. fso.CopyFile "SourcePath",Destination Path"
  3. fso.CopyFolder "Source Folder Name", Destination Folder Name"
  4.  

All The Best

With Regards
Vijay. R
Dec 27 '07 #3

P: 4
Hi Vijay,

After including Microsoft Scripting Runtime reference to the project, I get an error that "FileSystemObject" type is undefined. Should some other reference be included? Please clarify.

Thanks,
Anup.
Dec 28 '07 #4

P: 4
Hi Vijay,

Thanks a lot for your input. I got the solution. We need to declare the variable as Scripting.FileSystemObject.

Thanks,
Anup.
Dec 28 '07 #5

P: 4
Hi All,

In continuation to my previous query... Would it be possible to copy a file from the net say "www.abc.com/file" to the destination folder on my system say "C:\Anup". I get exception errors when giving the source file as "www.abc.com" when using FSO.

Could any one help?

Thanks,
Anup.
Dec 28 '07 #6

QVeen72
Expert 100+
P: 1,445
Hi,

To Download Files from Web, you need to use "WinSock" or "Inet" or "DownLoad.Ctl"

Goolge and check..

Regards
Veena
Dec 28 '07 #7

VijaySofist
100+
P: 107
Hi All,

In continuation to my previous query... Would it be possible to copy a file from the net say "www.abc.com/file" to the destination folder on my system say "C:\Anup". I get exception errors when giving the source file as "www.abc.com" when using FSO.

Could any one help?

Thanks,
Anup.
Hi Anup!

To DownLoad Files from the site use the following coding.
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function URLDownloadToFile Lib "urlmon" Alias _
  2.     "URLDownloadToFileA" (ByVal pCaller As Long, _
  3.     ByVal szURL As String, _
  4.     ByVal szFileName As String, _
  5.     ByVal dwReserved As Long, _
  6.     ByVal lpfnCB As Long) As Long
  7.  
  8. Public Function DownloadFile(URL As String, _
  9.     LocalFilename As String) As Boolean
  10.     Dim lngRetVal As Long
  11.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
  12.     If lngRetVal = 0 Then DownloadFile = True
  13. End Function
  14.  

All the Best.

With Regards
Vijay. R
Dec 28 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.