I'm probably going about this the hard way, I was inputing a file and then writing it to a new dir, is their a simpler command something like
copy "c:\file1" to "c:\temp\file2"
that would work?
Printable View
I'm probably going about this the hard way, I was inputing a file and then writing it to a new dir, is their a simpler command something like
copy "c:\file1" to "c:\temp\file2"
that would work?
filecopy "c:\file1", "c:\temp\file2"
Or, if you do not want a copy in both places, use Name to rename the file.
Name "c:\file1" As "c:\temp\file2"
Or, if you are copying to a location where the file aready exists, (using name here will raise an error), you can use:
VB Code:
'========================================== 'for the value, bFailIfExists. If you set this value to true, then 'the file won't be copied is the file already exists. If this value 'is false, then the file will overwrite any existing copies of the 'file '=========================================== Private Declare Function CopyFile Lib "kernel32" Alias _ "CopyFileA" (ByVal lpExistingFileName As String, _ ByVal lpNewFileName As String, _ ByVal bFailIfExists As Long) As Long Private Command1_Click() Dim lret as long '=========================================== 'This will create a duplicate file, without deleting the original 'file. And will overwrite the destination file, if it already exits. '=========================================== lret=CopyFile("c:\windows\desktop\test.txt", "c:\windows\desktop\test1.txt", True) End sub
Hope this helps.
ok this is what I'm trying and I'm getting an error
'Path not found'
VB Code:
FileCopy App.Path & "\" & File1.Filename, App.Path & "\backup\" & TempFilename
File1.Filename is from a filelistbox, and is the file name we are copying.
Tempfilename is the newname of the file.
I am going to guess that the directory that you want to copy to, doesn't exist. In all the commands that have been posted, the directory structure must be present for the copy commands to work. If you need to check to see if a nested directory exists (and create it if it doesn't) then look at this tip from vbworld:
http://www.vbworld.com/files/tip528.html
Hope this helps.
Right. If backup directory does not exist, you will get Path Not Found. So, either create it outside of the VB app, or use MkDir in VB to make sure it exists.
humm, that's not the problem I was thinking that I possibly could of writen the code improperly,
lets just say that the main directory is c:\
the backupdir would then be c:\backup.
which is how I have it set up, so I was thinking that the way I was linking all the commands
App.Path & "\backup\" & TempFilename
the & commands weren't working correctly, I'll take a look at that tip though.
ok narrowed it down to this part of the code.
TempFilename
this is what is causing the error,
I added a msgbox to display the last section of where it's being copied to and it's not showing the file name, just the dir.
Temppath = App.Path & "\backup\" & TempFilename
MsgBox Temppath
= c:\backup\
no file name??
Ok, I found my problem, I didn't declare Tempfilename in the option explicit area, but under a differend command_click()
opps. :D
My bad. Thanks all.