Results 1 to 18 of 18

Thread: Path/File Access Error

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    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:
    1. Private Sub cmdCopyTo_Click()
    2.     If File1.ListIndex < 0 Then
    3.         MsgBox "No Selected Songs.", vbCritical
    4.         Exit Sub
    5.     End If
    6.     sFileName = File1.Path
    7.     If Right$(sFileName, 1) <> "\" Then
    8.         sFileName = sFileName & "\"
    9.     End If
    10.     sFileName = sFileName & File1.Filename
    11.     MsgBox "Select Folder to send files to.", vbInformation
    12.     blnCopy = True
    13. End Sub
    14.  
    15. Private Sub lstSetupAr_Click()
    16.     Dim dir As String
    17.     If blnCopy Then
    18.         lstSetupDire.ListIndex = lstSetupAr.ListIndex
    19.         [COLOR=Red]FileCopy sFileName, lstSetupDire.Text[/COLOR] 'Error Line
    20.         blnCopy = False
    21.         Exit Sub
    22.     End If
    23. End Sub

  2. #2

  3. #3

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    Yes as a string in general declarations

  4. #4
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    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.

  5. #5

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    File1.Path will give you the path that the file list box is showing

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Path/File Access Error

    Quote 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.

  7. #7

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    Quote 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?

  8. #8
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Path/File Access Error

    Quote 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.

  9. #9

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    Quote 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.

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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 "\"

  11. #11

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    I stepped through my program and looked at the variables and they equal the correct directory and file names
    Attached Images Attached Images   

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  13. #13

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    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

  14. #14
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Path/File Access Error

    You are not specifying the destination filename
    Try this:
    VB Code:
    1. FileCopy sFileName, lstSetupDire.Text & sFileName

  15. #15

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    Oh yeah! I've gotta include what the new copied file name will be.

    Thanks a lot jcis

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Path/File Access Error

    Quote 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?

  17. #17

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Path/File Access Error

    Oh sorry, I didn't even see that post

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Path/File Access Error

    Quote 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
  •  



Click Here to Expand Forum to Full Width