Generate listbox from file folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • sheena
    Indigo Rose Customer
    • Jul 2005
    • 6

    Generate listbox from file folder

    Help!!! Is there a way to generate a listbox from a folder of pdfs that will generate the list and make them clickable to lauch each individual pdf from clicking the name of the file?
  • Desrat
    Forum Member
    • Nov 2006
    • 240

    #2
    Code:
    --code to find pdf files and populate listbox
    --place in a button or onshow of page
    
    --Purge listbox of all previous data
    ListBox.DeleteItem("Name Of Listbox", LB_ALLITEMS);
    
    --find all pdf files in the folder
    tblPDF = File.Find("C:\\Path To Folder", "*.pdf", false, false, nil, nil);
    
    --ensure there was a result and continue
    if (tblPDF) then 
    
    	--loop to step through table adding items to listbox
    	for i, v in tblPDF do
    	
    	--split file path so we can get the file name
    	tblSplit = String.SplitPath(tblPDF[i]);
    	
    	--add filename as text and filepath as data
    	ListBox.AddItem("Name Of Listbox", tblSplit.Filename, tblPDF[i]);
    	end
    	
    	
    --no pdf files found
    else Dialog.Message("Notice", "No PDF files found", MB_OK);
    
    end
    Code:
    --code for on click event of listbox
    --get selected item
    tblSelected = ListBox.GetSelected("Name Of Listbox");
    
    --ensure there is a valid selection
    if (tblSelected) then 
    
    --get data for selected item i.e the file path
    strFilePath = ListBox.GetItemData("Name Of Listbox", tblSelected[1]);
    
    	--ensure no errors
    	if strFilePath == "" then
    	Dialog.Message("Notice", "No filepath found", MB_OK);
    	
    	--no error so open file
    	else File.Open(strFilePath, "", SW_SHOWNORMAL);
    	
    	end
    	
    --no listbox item selected
    else Dialog.Message("Notice", "No Item selected", MB_OK);
    
    end

    Comment

    • sebalius
      No longer a forum member
      • Jan 2008
      • 47

      #3
      Is this any good

      Will this work for you ?
      Regards
      sebalius

      Comment

      • DaSoulRed
        Forum Member
        • Aug 2007
        • 407

        #4
        Why i cant populate a hard drive folder...

        I use this code and the Apz runs just fine... but i need to use this path "c:\\somedir\\otherdir" and when i use my hard drive i cant populate the files to the list box why is that any one can helpme a Byte.

        myCategory = "PDFfiles"; --set the name to your own folder

        bFound = Folder.DoesExist("AutoPlay\\Docs\\"..myCategory);

        if bFound == true then

        tFiles = File.Find("AutoPlay\\Docs\\"..myCategory, "*", false, false, nil, nil);

        if tFiles then

        ListBox.DeleteItem("ListBox1", -1); -- clears the previous choice

        for i,sFilePath in pairs(tFiles) do
        tFileParts = String.SplitPath(sFilePath); -- this breaks everypart of the filepath
        sFileName = tFileParts.Filename; -- this one is the Filename only
        sFileExtension = tFileParts.Extension; -- this one is File Extension only
        sFullFileName = sFileName..sFileExtension; -- concatenate
        ListBox.AddItem("ListBox1", sFileName, sFilePath); -- add to the ListBox
        end

        end

        end

        Comment

        • DaSoulRed
          Forum Member
          • Aug 2007
          • 407

          #5
          Greets Forum People... here is a Problemo any one can help...

          I Just Bumb it...

          About populate a listbox from hard drive using C:\\pathhere\\somefolder

          Comment

          • Cybergraph
            Indigo Rose Customer
            • Feb 2007
            • 1633

            #6
            Why you use a sub-path of the application ("AutoPlay\\Docs\\"..) if you instead need the path "c:\\somedir\\otherdir" ?

            The code you posted works fine, but you are making confusion with file paths.
            We are slowly invading your planet to teach lazy humans to read the user manual.
            But don't be scared: we are here to help.

            Comment

            • DaSoulRed
              Forum Member
              • Aug 2007
              • 407

              #7
              I want to populate from "c:\\somedir\\otherdir but does not work... any example will help...


              THANKS AND ENJOY LIFE... ANY HOW...

              Comment

              • mikeln
                Forum Member
                • Aug 2006
                • 27

                #8
                my_docs_path = _DesktopFolder.."\\screens\\";
                --or in your example my_docs_path = "c:\\somedir\\otherdir\\"
                -- Search the user's My Documents folder for the text files.
                search_resultsb = File.Find(my_docs_path, "*.txt", true, false, nil, nil);
                for index, pathb in search_resultsb do
                ListBox.AddItem("ListBox1", pathb, "")
                end
                else

                end

                Comment

                Working...
                X