Hi There,
I'm working on a project for work and I'm having some issue trying to distribute to program the smoothes as possible, on idea I had was using VB, I’m kind of new at this so ill explain to you what I’m hoping to do. Basically to have commandbuttons when you click on them it would get a file from lets say G:\path\path1\path2\file.hta to C:\path\path1\folder So it would take the file and copy past it in another folder from a different directory. I look everywhere for a code that could help me. If a popup message could popup saying completed as well that would be great.
Copy/move file to different directory
Page 1 of 17 Replies - 29445 Views - Last Post: 18 November 2010 - 05:59 AM
Replies To: Copy/move file to different directory
#2
Re: Copy/move file to different directory
Posted 09 November 2010 - 10:17 PM
Look into FileCopy
That will copy a file from a location to a location
Then look into Kill
That will delete the source file
Then look into msgbox
This will give a popup message box when it's done to let you know...
One question, is the destination location already specified or do you want the user to select it before the program runs? If you want the user to select it, then you'll have to create a string(strFileLoc) and use FileDialog 'or' CommonDialog to let the user select the new location.
Hope this helps! Come back with some code/errors and we'll go from there
That will copy a file from a location to a location
Then look into Kill
That will delete the source file
Then look into msgbox
This will give a popup message box when it's done to let you know...
One question, is the destination location already specified or do you want the user to select it before the program runs? If you want the user to select it, then you'll have to create a string(strFileLoc) and use FileDialog 'or' CommonDialog to let the user select the new location.
Hope this helps! Come back with some code/errors and we'll go from there

#3
Re: Copy/move file to different directory
Posted 10 November 2010 - 05:56 AM
guyfromri has given you some great pointers there. You could also look into the filesystem object, which has lots of file and folder manipulation functions.
#4
Re: Copy/move file to different directory
Posted 10 November 2010 - 08:46 PM
thanks for the heads up, like i said I dont usely use VB6 so i have no idea how to start, if you guys could show my a code i could start from there, thanks
#5
Re: Copy/move file to different directory
Posted 10 November 2010 - 11:13 PM
We're not really in the habbit of creating code for people here but since this is relatively easy, try this out.
Sub test() Dim strSelFile As String Dim strNewLoc As String MsgBox ("Select file to copy") With Application.FileDialog(msoFileDialogFilePicker) If .Show = False Then End strSelFile = .SelectedItems(1) .AllowMultiSelect = False .Title = "Location to output new file to" End With MsgBox ("Select location to output file to") With Application.FileDialog(msoFileDialogFolderPicker) If .Show = False Then End strNewLoc = .SelectedItems(1) .AllowMultiSelect = False .Title = "Location to output new file to" End With FileCopy strSelFile, strNewLoc If MsgBox("Do you want to delete the source file?", vbYesNo) = vbNo Then Kill (strSelFile) MsgBox ("Done!") End Sub
#6
Re: Copy/move file to different directory
Posted 17 November 2010 - 09:02 PM
guyfromri, on 10 November 2010 - 10:13 PM, said:
We're not really in the habbit of creating code for people here but since this is relatively easy, try this out.
Sub test() Dim strSelFile As String Dim strNewLoc As String MsgBox ("Select file to copy") With Application.FileDialog(msoFileDialogFilePicker) If .Show = False Then End strSelFile = .SelectedItems(1) .AllowMultiSelect = False .Title = "Location to output new file to" End With MsgBox ("Select location to output file to") With Application.FileDialog(msoFileDialogFolderPicker) If .Show = False Then End strNewLoc = .SelectedItems(1) .AllowMultiSelect = False .Title = "Location to output new file to" End With FileCopy strSelFile, strNewLoc If MsgBox("Do you want to delete the source file?", vbYesNo) = vbNo Then Kill (strSelFile) MsgBox ("Done!") End Sub
hey thanks for the code,
so i tried using it, looks like its asking the user to choose the file to copy and its location, do you think you might be able to show me how to get a specific file and move it to a specific folder in a different directory, for G:/ to C:/ and no option to delete. it would be very helpful thanks.
#7
Re: Copy/move file to different directory
Posted 18 November 2010 - 05:51 AM
Just try coding your from and to paths in the two variables strSelFile and strNewLoc, then call the FileCopy function.
guyfromri has given you everything you need to do what you asked, he even wrote the code for you, which isn't the norm here.
Have a go at making the changes yourself and if you have problems post back your code and the issues you have.
guyfromri has given you everything you need to do what you asked, he even wrote the code for you, which isn't the norm here.
Have a go at making the changes yourself and if you have problems post back your code and the issues you have.
This post has been edited by maj3091: 18 November 2010 - 05:52 AM
#8
Re: Copy/move file to different directory
Posted 18 November 2010 - 05:59 AM
you can also check our tutorial section for some more information
Page 1 of 1