Indigo Rose Software
  #1  
Old 09-26-2003
Desmond's Avatar
Desmond Desmond is offline
Indigo Rose Staff Member
 
Join Date: Jul 2003
Posts: 628
Grin KB: Making a Document Browser

AutoPlay Media Studio 5.0 Knowledge Base

Making a Document Browser

Document ID: IR10050
The information in this article applies to:
  • AutoPlay Media Studio 5.0 Professional Edition

SUMMARY

This article describes how to make a document browser

DISCUSSION

As an example, we will create an application that has the user select a folder on his drive, and then populates a listbox object with all of the *.doc files within that directory. The user clicks on a file in the listbox object, and clicks the "Open" button to open the document.

  1. Create a project with one listbox object, and two button objects.

  2. Label Button1 "Load" and Button2 "Open".

  3. Insert the following code into the On Click event for Button1:
    --Disable listbox Updating  ListBox.SetUpdate("ListBox1", false);



    --Get the desired folder to browse

    folder = Dialog.FolderBrowse("Open Folder", "C:\\");



    --populate a table with all the .doc files

    file = File.Find(folder, "*.doc", false, false, nil);



    --do the following for each file:

    for j,file_path in file do

    --add the item to the listbox, with the name visible and path as data

    ListBox.AddItem("ListBox1", String.SplitPath(file_path).Filename, file_path);

    end



    --Allow the listbox to display the updated content ListBox.SetUpdate("ListBox1", true);
  4. Insert the following code into the On Click event for Button2:
    selected = ListBox.GetSelected("ListBox1");

    for j,k in selected do

    File.Open(ListBox.GetItemData("ListBox1", k),"", SW_SHOWNORMAL);

    end

MORE INFORMATION

KEYWORDS: AutoPlay Media Studio 5.0, Document, Browser


Last reviewed: September 26, 2003
Copyright © 2003 Indigo Rose Corporation. All rights reserved.
__________________
Setup Factory 8.0 comes with over 250 actions so you can create smaller, faster and more intelligent software installers than ever before.

WebHelp Guides: AMS | MSIFACT | SUF | TU | VP
  #2  
Old 10-26-2004
azmanar's Avatar
azmanar azmanar is offline
Indigo Rose Customer
 
Join Date: Oct 2004
Location: East, South & West Asia
Posts: 948
Error Message Pops Up If No File Exist

Hi,

I tested this example.

The FILE BROWSER OPENS. Good.

However, when I attempted to LOAD a FOLDER that contains NONE of the .doc files, this error message appears: ON CLICK, Line 11: attempt to call nil value.

How do I get rid of this error message? Better still, a message will appear saying that no such files, and tell us to try another folder.

Thanks

Azman
  #3  
Old 10-26-2004
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
In the section where you enumerate the files.
Code:
for j,file_path in file do
      --add the item to the listbox, with the name visible and path as data
      ListBox.AddItem("ListBox1", String.SplitPath(file_path).Filename, file_path);
end
encapsulate that bit of code in an if statement that checks to make sure the table file contains data.

Code:
if file then
      for j,file_path in file do
            --add the item to the listbox, with the name visible and path as data
            ListBox.AddItem("ListBox1", String.SplitPath(file_path).Filename, file_path);
      end
end
That way you wont run the code unless you actually find files.

Tigg
__________________
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  #4  
Old 10-27-2004
azmanar's Avatar
azmanar azmanar is offline
Indigo Rose Customer
 
Join Date: Oct 2004
Location: East, South & West Asia
Posts: 948
Another way

Hi Tigg,

And this is what Adam suggested and works as well.

Code:
if file ~= nil then

--do the following for each file:
for j,file_path in file do
--add the item to the listbox, with the name visible and path as data
ListBox.AddItem("ListBox1", String.SplitPath(file_path).Filename, file_path);
end

--Allow the listbox to display the updated content
ListBox.SetUpdate("ListBox1", true); 

else
Dialog.Message("Notice","No Documents were found in that directory");
end
Thanks Tigg.

Azman
  #5  
Old 10-27-2004
azmanar's Avatar
azmanar azmanar is offline
Indigo Rose Customer
 
Join Date: Oct 2004
Location: East, South & West Asia
Posts: 948
More File Types

Hi,

How would look for more than 1 file type. Say, I would like to search for .doc and .ppt at the same time from the same folder?

So, if this is the case, how could I actually display even the file extensions to differentiate between the 2 types.

Any ideas?

I'm not a programmer , so I need some practical ideas as a kick-start.

Thanks

Azman
  #6  
Old 10-28-2004
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Here is an example of what I have done in the past

Code:
--Get the desired folder to browse
folder = Dialog.FolderBrowse("Open Folder", "C:\\");
tbSearchFiles = {"*.doc", "*.ppt"};

for index,type in tbSearchFiles do
       file = File.Find(folder, type, false, false, nil);
       
       if file ~= nil then

              --do the following for each file:
              for j,file_path in file do
                     --add the item to the listbox, with the name visible and path as data
                     ListBox.AddItem("ListBox1", String.SplitPath(file_path).Filename, file_path);
              end

       else
              Dialog.Message("Notice","No Documents were found in that directory");
       end
end

--Allow the listbox to display the updated content
ListBox.SetUpdate("ListBox1", true);
Just add the file for which you want to search to the tbSearchFiles table and let 'er rip, so to speak.

Hope this helps.

If I can find it again, this is also on the forums somewhere out there.

Tigg
__________________
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  #7  
Old 10-28-2004
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Here is another version of the above code that I posted on the forums before

http://www.indigorose.com/forums/showthread.php?t=6864
__________________
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  #8  
Old 10-29-2004
azmanar's Avatar
azmanar azmanar is offline
Indigo Rose Customer
 
Join Date: Oct 2004
Location: East, South & West Asia
Posts: 948
Both Worked Well

Hi Tigg,

Both scripts worked very well.

One item is missing, i.e. The File Extension.

When we list in the ListBox only the filenames can be seen. What do we need to do to show the File Extensions?

Thanks

Azman
  #9  
Old 10-29-2004
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
The splitpath command was used when added to a listbox and it did not include the extension. Try this.

Code:
--Get the desired folder to browse
folder = Dialog.FolderBrowse("Open Folder", "C:\\");
tbSearchFiles = {"*.doc", "*.ppt"};

for index,type in tbSearchFiles do
       file = File.Find(folder, type, false, false, nil);
       
       if file ~= nil then

              --do the following for each file:
              for j,file_path in file do
                     --add the item to the listbox, with the name visible and path as data
                     tbFilePath = String.SplitPath(file_path);
                     ListBox.AddItem("ListBox1", tbFilePath.Filename..tbFilePath.Extension, file_path);
              end

       else
              Dialog.Message("Notice","No Documents were found in that directory");
       end
end

--Allow the listbox to display the updated content
ListBox.SetUpdate("ListBox1", true);
__________________
TJ-Tigger
"A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
"Draco dormiens nunquam titillandus."
Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  #10  
Old 01-14-2005
upena upena is offline
Forum Member
 
Join Date: Jan 2005
Posts: 11
Aloha

Working with listbox in a DEMO (before I shell out my money). I understand the script - but - how do I make it look at multiple drives for a specific folder. Not knowing which drive the CD will be in on different machines - but knowing the folder name, how do I do this?

I tried
result = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\MyFolderName");
and modified this line to look for .ZIP files instead of .doc files
file = File.Find(folder, "*.zip", false, false, nil);

When I click "Load" - it opens a pop-up that lists my "C:/My Documents" instead of going to the Folder that I specified. Any ideas? Or is this just because it is in Preview mode and only looking at what I created and saved on my "C" drive.

Also, is it possible to open a .zip and then open a .pdf or .doc or .whatever after - all in one smooth move?

Please bear with me - I am still learning.

Thanks in advance

Lar
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On



All times are GMT -6. The time now is 06:37 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software