|
-
Jun 27th, 2001, 10:36 AM
#1
Thread Starter
Lively Member
Copying files in Vb
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?
Vini, Vidi, Vici!
-----------------
say this 5 times fast
"I am not a pheasant plucker, I'm a pheasant plucker's son. I'm only plucking pheasants, till the pheasant plucker comes."
-
Jun 27th, 2001, 10:38 AM
#2
Fanatic Member
filecopy "c:\file1", "c:\temp\file2"
-
Jun 27th, 2001, 10:42 AM
#3
Fanatic Member
Or, if you do not want a copy in both places, use Name to rename the file.
Name "c:\file1" As "c:\temp\file2"
-
Jun 27th, 2001, 10:58 AM
#4
Hyperactive Member
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.
-
Jun 27th, 2001, 11:00 AM
#5
Thread Starter
Lively Member
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.
Vini, Vidi, Vici!
-----------------
say this 5 times fast
"I am not a pheasant plucker, I'm a pheasant plucker's son. I'm only plucking pheasants, till the pheasant plucker comes."
-
Jun 27th, 2001, 11:17 AM
#6
Hyperactive Member
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.
-
Jun 27th, 2001, 11:22 AM
#7
Fanatic Member
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.
-
Jun 27th, 2001, 11:51 AM
#8
Thread Starter
Lively Member
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.
Vini, Vidi, Vici!
-----------------
say this 5 times fast
"I am not a pheasant plucker, I'm a pheasant plucker's son. I'm only plucking pheasants, till the pheasant plucker comes."
-
Jun 27th, 2001, 12:01 PM
#9
Thread Starter
Lively Member
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.
My bad. Thanks all.
Vini, Vidi, Vici!
-----------------
say this 5 times fast
"I am not a pheasant plucker, I'm a pheasant plucker's son. I'm only plucking pheasants, till the pheasant plucker comes."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|