|
-
Apr 21st, 2006, 11:46 PM
#1
Thread Starter
Lively Member
-
Apr 21st, 2006, 11:48 PM
#2
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.
-
Apr 21st, 2006, 11:51 PM
#3
Thread Starter
Lively Member
forgot current code.
being overly tired i forgot to post the code. here it is.
VB Code:
Option Explicit
Dim fso As New FileSystemObject 'The file system object
Dim ParFolder As Folder 'parent folder variable
Dim n As Long 'for counting
Public filelist() As String 'array To hold the list of files With path
Public Function FindFile(Optional ByVal sFol As String, Optional ByVal NumberFiles As Long)
Dim CurFile As File
Dim CurFolder As Folder
Dim NFiles As Long
Set ParFolder = fso.GetFolder(sFol)
NFiles = ParFolder.Files.Count
If NFiles > 0 Then ' checks if dir has any files
For Each CurFile In ParFolder.Files
' fix bad file/folder names
filename = Replace(CurFile.Name, "'", "''")
foldername = Replace(CurFile.Path, "'", "''")
'add to db
sqlstr = "insert into smfiles(filename, path, filesize)values('" & filename & "', '" & foldername & "', '" & CurFile.Size & "')"
conn.Execute (sqlstr)
filecount = filecount + 1
Next
mainfrm.filecounttxt.Text = filecount
mainfrm.Refresh
End If
For Each CurFolder In ParFolder.SubFolders 'IF SUBFOLDERS OF CURRENT FOLDER ARE THERE
FindFile CurFolder 'call itself To Get the files of subfolders
Next
End Function
tanks for any help.
-
Apr 22nd, 2006, 12:12 AM
#4
Re: FSO loosing / in path when Inserting in DB
it worked fine for me...i tried with msgbox like this
VB Code:
Public Function FindFile(Optional ByVal sFol As String, Optional ByVal NumberFiles As Long)
Dim CurFile As File
Dim CurFolder As Folder
Dim NFiles As Long
Set ParFolder = fso.GetFolder(sFol)
Dim FileName As String
Dim FolderName As String
Dim SqlStr As String
NFiles = ParFolder.Files.Count
If NFiles > 0 Then ' checks if dir has any files
For Each CurFile In ParFolder.Files
' fix bad file/folder names
FileName = Replace(CurFile.Name, "'", "''")
FolderName = Replace(CurFile.Path, "'", "''")
'display it
MsgBox FileName & ", " & FolderName & ", " & CurFile.Size
filecount = filecount + 1
Next
End If
For Each CurFolder In ParFolder.SubFolders 'IF SUBFOLDERS OF CURRENT FOLDER ARE THERE
FindFile CurFolder 'call itself To Get the files of subfolders
Next
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.
-
Apr 22nd, 2006, 02:22 AM
#5
Thread Starter
Lively Member
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:
foldername = Replace(foldername, "\", "\\")
if any one knows of other possible chars that may be a problem please let me know.
again thank you.
-
Apr 22nd, 2006, 02:27 AM
#6
Thread Starter
Lively Member
Re: FSO loosing / in path when Inserting in DB
I also found the other problem.
VB Code:
FolderName = Replace(CurFile.Path, "'", "''")
should have been
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|