|
-
Dec 16th, 2005, 06:25 PM
#1
Thread Starter
Fanatic Member
Path/File Access Error
Hi all,
I am trying to move files from one folder to another with my program. How I am doing it is the user clicks the file in the file list box and then clicks Copy, then clicks a folder name in a listbox. But it gives me the error "Path/File Access Error"
Here is my code
VB Code:
Private Sub cmdCopyTo_Click()
If File1.ListIndex < 0 Then
MsgBox "No Selected Songs.", vbCritical
Exit Sub
End If
sFileName = File1.Path
If Right$(sFileName, 1) <> "\" Then
sFileName = sFileName & "\"
End If
sFileName = sFileName & File1.Filename
MsgBox "Select Folder to send files to.", vbInformation
blnCopy = True
End Sub
Private Sub lstSetupAr_Click()
Dim dir As String
If blnCopy Then
lstSetupDire.ListIndex = lstSetupAr.ListIndex
[COLOR=Red]FileCopy sFileName, lstSetupDire.Text[/COLOR] 'Error Line
blnCopy = False
Exit Sub
End If
End Sub
-
Dec 16th, 2005, 06:47 PM
#2
Re: Path/File Access Error
Have you defined sFileName someplace?
-
Dec 16th, 2005, 06:51 PM
#3
Thread Starter
Fanatic Member
Re: Path/File Access Error
Yes as a string in general declarations
-
Dec 16th, 2005, 06:52 PM
#4
Re: Path/File Access Error
Thats probably because a FileListBox only shows FileNames, you need to use a DirListBox as well to find its path.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Dec 16th, 2005, 06:53 PM
#5
Thread Starter
Fanatic Member
Re: Path/File Access Error
File1.Path will give you the path that the file list box is showing
-
Dec 16th, 2005, 06:54 PM
#6
Re: Path/File Access Error
 Originally Posted by paralinx
Yes as a string in general declarations
Ok, that's good but you might want to start the names of form-level variables with "m" the name might better be msFileName.
-
Dec 16th, 2005, 06:56 PM
#7
Thread Starter
Fanatic Member
Re: Path/File Access Error
 Originally Posted by MartinLiss
Ok, that's good but you might want to start the names of form-level variables with "m" the name might better be msFileName.
Oh ok sorry, what does the M stand for though?
-
Dec 16th, 2005, 06:58 PM
#8
Re: Path/File Access Error
 Originally Posted by paralinx
File1.Path will give you the path that the file list box is showing
Yes File1.Path will show the App.Path but if you want to copy these files to another location how are you finding this new path?
FileCopy sFileName, lstSetupDire.Text 'Error Line
What is in lstSetupDire? The filename and path?
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Dec 16th, 2005, 07:04 PM
#9
Thread Starter
Fanatic Member
Re: Path/File Access Error
 Originally Posted by Keithuk
Yes File1.Path will show the App.Path but if you want to copy these files to another location how are you finding this new path?
FileCopy sFileName, lstSetupDire.Text 'Error Line
What is in lstSetupDire? The filename and path?
that's the listbox that shows the directory of the file I want to copy it to.
-
Dec 16th, 2005, 07:04 PM
#10
Re: Path/File Access Error
You must also include the filename in the destination location. It's not like DOS, which uses the original name in a copy statement. Don't forget the "\"
-
Dec 16th, 2005, 07:09 PM
#11
Thread Starter
Fanatic Member
Re: Path/File Access Error
I stepped through my program and looked at the variables and they equal the correct directory and file names
-
Dec 16th, 2005, 07:12 PM
#12
Re: Path/File Access Error
Use a debug.print statement for each file, you can't really see the full path in the tool tip. It may be missing the "\" or have an extra one on the end.
-
Dec 16th, 2005, 07:18 PM
#13
Thread Starter
Fanatic Member
Re: Path/File Access Error
No, they are perfectly fine here's what comes up in the debug window
Code:
C:\Documents and Settings\Owner\Desktop\My Stuff\Music\Led Zeppelin\Achilles last stand.mp4
C:\Documents and Settings\Owner\Desktop\My Stuff\Music\Led Zeppelin
-
Dec 16th, 2005, 07:28 PM
#14
Re: Path/File Access Error
You are not specifying the destination filename
Try this:
VB Code:
FileCopy sFileName, lstSetupDire.Text & sFileName
-
Dec 16th, 2005, 07:37 PM
#15
Thread Starter
Fanatic Member
Re: Path/File Access Error
Oh yeah! I've gotta include what the new copied file name will be.
Thanks a lot jcis
-
Dec 16th, 2005, 07:40 PM
#16
Re: Path/File Access Error
 Originally Posted by dglienna
You must also include the filename in the destination location. It's not like DOS, which uses the original name in a copy statement. Don't forget the "\"
Did you miss that?
-
Dec 16th, 2005, 07:49 PM
#17
Thread Starter
Fanatic Member
Re: Path/File Access Error
Oh sorry, I didn't even see that post
-
Dec 16th, 2005, 07:57 PM
#18
Re: Path/File Access Error
 Originally Posted by paralinx
Oh ok sorry, what does the M stand for though?
Nothing to be sorry about, but part of the normal convention for naming files includes m or m_ for module-level (meaning form-module-level) variables and g or g_ for global (meaning those defined at the top of code modules). That way you 6 months from now or someone maintaing your program will know the scope of the variable by just looking at the name.
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
|