P
PcolaITGuy
I have a macro that is used to copy a source file (dim srcfile as string) out
to a path (dim destpath as string).
user inputs the full source file path into a text box.
(srcfile=txt_source.text)
user input the destination path into a second text box.
(destpath=txt_destpath.text)
there is a command button (cmd_execute_copy) with associated code that
constructs a command line string using copy command with the user inputs
("cmd.exe /c copy " + srcfile + " " +destpath).
This all works just great. However, I would like to be able to construct an
IF statement that first checks to see if the same file name already exists in
the destination path. If it does, then I would like to be able to add ".bak"
to the end of the SRCFILE value and then continue the copy operation. I
guess the trick would be to first parse the SRCFILE string from the end
backwards to the first "\" that it runs into which should then indicate the
filename?
Here is my code so far:
Private Sub cmd_execute_copy_Click()
Dim srcfile As String
Dim destpath As String
Dim copystring As String
srcfile = txt_source.Text
destpath = txt_destpath.Text
copystring = "cmd.exe /c copy " + srcfile + " " + destpath
Shell (copystring), 1
end sub
Thanks in advance,
Pcola
to a path (dim destpath as string).
user inputs the full source file path into a text box.
(srcfile=txt_source.text)
user input the destination path into a second text box.
(destpath=txt_destpath.text)
there is a command button (cmd_execute_copy) with associated code that
constructs a command line string using copy command with the user inputs
("cmd.exe /c copy " + srcfile + " " +destpath).
This all works just great. However, I would like to be able to construct an
IF statement that first checks to see if the same file name already exists in
the destination path. If it does, then I would like to be able to add ".bak"
to the end of the SRCFILE value and then continue the copy operation. I
guess the trick would be to first parse the SRCFILE string from the end
backwards to the first "\" that it runs into which should then indicate the
filename?
Here is my code so far:
Private Sub cmd_execute_copy_Click()
Dim srcfile As String
Dim destpath As String
Dim copystring As String
srcfile = txt_source.Text
destpath = txt_destpath.Text
copystring = "cmd.exe /c copy " + srcfile + " " + destpath
Shell (copystring), 1
end sub
Thanks in advance,
Pcola