Results 1 to 6 of 6

Thread: [RESOLVED] FSO loosing / in path when Inserting in DB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    85

    Resolved [RESOLVED] FSO loosing / in path when Inserting in DB

    I am trying to write a chunk of code to recursivly read a directory from a given location and add it to a DB. I have most of it working. I do however have 2 problems.
    1. for some reason it is dropping all the / from the path. d:/pics/fun becomes dicsfun
    2. part way down the list it has both the path and filename in the db.

    ie. d:/pics/fun/001.bmp goes in as:
    filename currentpath
    001.bmp dicsfun001.bmp

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: FSO loosing / in path when Inserting in DB

    could you post your code...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    85

    forgot current code.

    being overly tired i forgot to post the code. here it is.
    VB Code:
    1. Option Explicit
    2. Dim fso As New FileSystemObject 'The file system object
    3. Dim ParFolder As Folder 'parent folder variable
    4. Dim n As Long 'for counting
    5.  
    6. Public filelist() As String 'array To hold the list of files With path
    7. Public Function FindFile(Optional ByVal sFol As String, Optional ByVal NumberFiles As Long)
    8.     Dim CurFile As File
    9.     Dim CurFolder As Folder
    10.     Dim NFiles As Long
    11.     Set ParFolder = fso.GetFolder(sFol)
    12.    
    13.     NFiles = ParFolder.Files.Count
    14.     If NFiles > 0 Then ' checks if dir has any files
    15.     For Each CurFile In ParFolder.Files
    16. ' fix bad file/folder names
    17. filename = Replace(CurFile.Name, "'", "''")
    18. foldername = Replace(CurFile.Path, "'", "''")
    19. 'add to db
    20. sqlstr = "insert into smfiles(filename, path, filesize)values('" & filename & "', '" & foldername & "', '" & CurFile.Size & "')"
    21. conn.Execute (sqlstr)
    22.  
    23.      filecount = filecount + 1
    24.         Next
    25.      mainfrm.filecounttxt.Text = filecount
    26.      mainfrm.Refresh
    27.    
    28.     End If
    29.  
    30.     For Each CurFolder In ParFolder.SubFolders 'IF SUBFOLDERS OF CURRENT FOLDER ARE THERE
    31.         FindFile CurFolder 'call itself To Get the files of subfolders
    32.     Next
    33. End Function
    tanks for any help.

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: FSO loosing / in path when Inserting in DB

    it worked fine for me...i tried with msgbox like this
    VB Code:
    1. Public Function FindFile(Optional ByVal sFol As String, Optional ByVal NumberFiles As Long)
    2.     Dim CurFile As File
    3.     Dim CurFolder As Folder
    4.     Dim NFiles As Long
    5.     Set ParFolder = fso.GetFolder(sFol)
    6.     Dim FileName As String
    7.     Dim FolderName As String
    8.     Dim SqlStr As String
    9.    
    10.     NFiles = ParFolder.Files.Count
    11.     If NFiles > 0 Then ' checks if dir has any files
    12.         For Each CurFile In ParFolder.Files
    13.             ' fix bad file/folder names
    14.             FileName = Replace(CurFile.Name, "'", "''")
    15.             FolderName = Replace(CurFile.Path, "'", "''")
    16.             'display it
    17.             MsgBox FileName & ", " & FolderName & ", " & CurFile.Size
    18.  
    19.             filecount = filecount + 1
    20.         Next
    21.     End If
    22.  
    23.     For Each CurFolder In ParFolder.SubFolders 'IF SUBFOLDERS OF CURRENT FOLDER ARE THERE
    24.         FindFile CurFolder 'call itself To Get the files of subfolders
    25.     Next
    26. End Function
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    85

    Smile Re: FSO loosing / in path when Inserting in DB

    thank you for the replies. yes the msg box worked for me as well. I should have mentioned earlyer that the DB was MySQL. Im not sure right now if that would have made a difference. I did figure out how to make it work for the DB. I just needed another replace.
    VB Code:
    1. foldername = Replace(foldername, "\", "\\")
    if any one knows of other possible chars that may be a problem please let me know.
    again thank you.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    85

    Re: FSO loosing / in path when Inserting in DB

    I also found the other problem.
    VB Code:
    1. FolderName = Replace(CurFile.Path, "'", "''")
    should have been
    VB Code:
    1. FolderName = Replace(CurFile.ParentFolder, "'", "''")

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