Getting user input for file/ directory copy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anupkkumar
    New Member
    • Dec 2007
    • 4

    Getting user input for file/ directory copy

    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.Fil eSystem.CopyDir ectory("C:\abc\ <file/dir>", "D:\cde\<Fi le/dir>")

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

    Thanks,
    Anup.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Please find a related discussion here.

    Comment

    • VijaySofist
      New Member
      • Jun 2007
      • 107

      #3
      Hi Anup!

      Use FileSystemObjec t 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.

      Code:
      Dim fso as FileSystemObject
      fso.CopyFile "SourcePath",Destination Path"
      fso.CopyFolder "Source Folder Name", Destination Folder Name"

      All The Best

      With Regards
      Vijay. R

      Comment

      • anupkkumar
        New Member
        • Dec 2007
        • 4

        #4
        Hi Vijay,

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

        Thanks,
        Anup.

        Comment

        • anupkkumar
          New Member
          • Dec 2007
          • 4

          #5
          Hi Vijay,

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

          Thanks,
          Anup.

          Comment

          • anupkkumar
            New Member
            • Dec 2007
            • 4

            #6
            Hi All,

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

            Could any one help?

            Thanks,
            Anup.

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

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

              Goolge and check..

              Regards
              Veena

              Comment

              • VijaySofist
                New Member
                • Jun 2007
                • 107

                #8
                Originally posted by anupkkumar
                Hi All,

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

                Could any one help?

                Thanks,
                Anup.
                Hi Anup!

                To DownLoad Files from the site use the following coding.
                Code:
                Public Declare Function URLDownloadToFile Lib "urlmon" Alias _
                    "URLDownloadToFileA" (ByVal pCaller As Long, _
                    ByVal szURL As String, _
                    ByVal szFileName As String, _
                    ByVal dwReserved As Long, _
                    ByVal lpfnCB As Long) As Long
                
                Public Function DownloadFile(URL As String, _
                    LocalFilename As String) As Boolean
                    Dim lngRetVal As Long
                    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
                    If lngRetVal = 0 Then DownloadFile = True
                End Function

                All the Best.

                With Regards
                Vijay. R

                Comment

                Working...