ListBox to Field in a database - Forum

Forum Navigation
You need to log in to create posts and topics.

ListBox to Field in a database

First, I would like to thank @mishem for the answer to List all .mp3 files question. As this left me with more questions.

What I would like to do, is create the ability to import each file name into a table within a database, so saving them being entered by hand. This would be for when the user first runs the program, and then after this, would have the ability to add when the person find more.

@mishem answer showed me a search and show method, but left me missing something

Loop "1" "[zmFindFilesCount]" "[Count2]"
If "[Count2]" "<>" ""
dbpVarToRecord "IndexDoc" "MainData" "[ListBox1]" "Delimiter=,;IncludeHidden=No"


EndLoop

The Loop works and so does the dbpVarToRecord, but the table still stands at 0 records.

I'm missing something, can anyone point me to what I'm missing, please

 

Try it this way

Loop "1" "[zmFindFilesCount]" "[Count2]"
If "[Count2]" "<>" ""
dbpVarToRecord "IndexDoc" "MainData" "[ListBox1]" "Delimiter=[#13];IncludeHidden=No"
EndLoop

or like this

Loop "1" "[zmFindFilesCount]" "[Count2]"
If "[Count2]" "<>" ""
dbpVarToRecord "IndexDoc" "MainData" "[ListBox1]" "Delimiter=[#13][#10];IncludeHidden=No"
EndLoop

@mishem thank you the help, but it did not work as expected.

If I change the [ListBox1] with [Results] it records one record,but still runs the Loop, and put all the file names into the first record, on a new line for each file name and not making a new record for each file.

FileExists "[PubDir]IndexDoc.mdb" "[Result]"
If "[Result]" "=" "True"
    FileErase "[PubDir]IndexDoc.mdb"
EndIf
dbpCreateAccessDatabase "[PubDir]IndexDoc.mdb" "Password=;Encrypted=No"
dbpOpenDatabase "IndexDoc" "[PubDir]IndexDoc.mdb"
dbpCreateTable "IndexDoc" "MainData" "File Memo"
dbpOpenTable "IndexDoc" "MainData" ""
.Specify your rectangle
dbpShowGrid "IndexDoc" "MainData" "Rectangle1"
.Specify your folder path and mask
zmFindFiles "*.*" "[PubDir]" "" "" "[ListBox1]"

If "[zmFindFilesCount]" "<>" "0"
    StrReplace "[ListBox1]" "[#13][#10]" "|" "[ListBox1]" ""
    FileWrite "[PubDir]1.csv" "All" "[ListBox1]"
    dbpImportFromCSV "IndexDoc" "MainData" "[PubDir]1.csv" "Delimiter=,;ContainsFieldNames=No;MatchFieldNames=No"
EndLoop

Create a folder. Create a new project. Drop a rectangle onto the form. In `zmFindFiles`, specify the path to the folder containing your files.

Is this what you need?

If so, consult the documentation to understand how the export and import processes work. Take a look at how fields and rows are delimited.

@mishem thank you for the help.

I did find the need to create a file but used a txt file, and that’s where I left it yesterday.

I have reduce the code to

.Button to run Convert
FolderBox "Select Folders" "[Result]"
 zmFindFiles "*.*" "[Result]" "SubFolders" "" "[Result]" "Find"
   
If "[zmFindFilesCount]" "<>" "0"
    StrRegexReplace "(?m-s)^.+\\" "[Result]" "" "" "[ListBox1]"
    FileWrite "[PubDir]1.csv" "All" "[ListBox1]"
    dbpImportFromCSV "IndexDoc" "MainData" "[PubDir]1.csv" "Delimiter=,;ContainsFieldNames=No;MatchFieldNames=No"
    AlertBox "Find" "Files found : [zmFindFilesCount]"
    .FileErase "[PubDir]1.csv"
EndLoop

This code does add the search to the database, but left me with the question, can I add the file location to the database?

You say to consult the Documentation, and I have been looking into Regular expression strings, and Delimited.

Again Thank you for the help

 

" can I add the file location to the database?"

I’m not sure I understand your question.
Does "location" mean the file path? If so, yes, that’s possible.
Does "location" mean the file itself? That’s also possible.

I refer you to the documentation because everything is explained more clearly there than I could ever manage via a translator. In essence, I would just be paraphrasing the documentation for you—likely while leaving out some important details.
Think about it: first, I translate the documentation from English into Russian; then, my words are translated from Russian back into English; and if English isn’t your native language, you might even end up translating it yet again into your own language.

Sorry for the miss understanding, Location is the place on the disk i.e. D:\DATA\Census. The question was after I run the code and found that the fold (D:\Data\) held 1,529 Files, 41 Folders. and this will only get larger with time.

Quote from m.burdess on November 19, 2026, 10:59 am

Sorry for the miss understanding, Location is the place on the disk i.e. D:\DATA\Census. The question was after I run the code and found that the fold (D:\Data\) held 1,529 Files, 41 Folders. and this will only get larger with time.

So, what is it that you want? To store the entire folder of files in the database, or just the path to the folder?

Or are you looking to extract the folder path from a file path? What exactly are you trying to do? Your question lacks a specific task. Programming does not allow for such vague definitions; you need to state the task precisely.