Results 1 to 7 of 7

Thread: Copy selected file (CommonDialog) to another folder?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Copy selected file (CommonDialog) to another folder?

    Hi guys is it possible that when a user selects a file from commondialog1 (Open) and press the command button it will copy the file and paste a copy of it into the folder C:\New

    ?
    thanks
    Jamie

  2. #2
    Lively Member
    Join Date
    Aug 2009
    Posts
    98

    Re: Copy selected file (CommonDialog) to another folder?

    Yes it is possible. After selecting a file from Open Commondialog1, save its name with full path to a text box. Now in command button use CopyFile method to copy file to a new folder C:\New. May use FileScriptObject for this.

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Copy selected file (CommonDialog) to another folder?

    You could do this:

    vb Code:
    1. Dim original As String, dest As String
    2. Private Sub Command1_Click()
    3. CommonDialog1.ShowOpen
    4. original = CommonDialog1.FileName
    5. End Sub
    6.  
    7. Private Sub Command2_Click()
    8. CommonDialog1.ShowSave
    9. dest = CommonDialog1.FileName
    10. FileCopy original, dest
    11. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Copy selected file (CommonDialog) to another folder?

    Yes if you want to copy the file use the FileCopy method shown in post #3, do not use the FSO

    If you want to move a file then you would use the Name method
    Code:
    Name OldFilename As NewFileName

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Copy selected file (CommonDialog) to another folder?

    Or he could use the SHFileoperations-API or the CopyFileEx-API if he wants to show the Copy-Progress (usually only with big files)
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Copy selected file (CommonDialog) to another folder?

    Hi guys, I'm getting a run time error '52' bad file name which then highlights -


    dest = "\\server\Attachments\"
    FileCopy Text1.Text, dest



    any ideas?

    thanks

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Copy selected file (CommonDialog) to another folder?

    You have to use an explicit filename including path for destination or in your variable

    Code:
    txtSource.Text="C:\MySourceFolder\MyFile.txt"
    txtDest.Text="\\Server\Attachments\MyDestFile.txt"
    
    FileCopy txtSource.Text, txtDest.Text
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width