Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475

    String.SplitPath

    If i split the path for a single file in order to get file name and file extension i use this code;
    --------------------------------------------------------------
    resFind = File.Find("data", "1.txt", false, false, nil);

    resSplitPath = String.SplitPath(resFind[1]);

    result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, "");
    --------------------------------------------------------------
    But how must be this code adapted when the search returns a table of data?
    --------------------------------------------------------------
    resFind = File.Find("data", "*.txt", false, false, nil);

    resSplitPath = String.SplitPath(resFind[1]);

    result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, "");
    --------------------------------------------------------------


    Thank you

    Sside

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Sside

    Since the File.Find returns a table you can use a for loop to enumerate the table and add each item one at a time. Here is an example for the code.
    Code:
    resFind = File.Find("data", "*.txt", false, false, nil);
    
    for index, value in resFind do
    resSplitPath = String.SplitPath(resFind[index]);
    
    result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[index]);
    end

    I usually will add the full path for the file into the Data section of the listbox as you can see above, that way if I want to open the file I can use that to open it without having to search for the full path again.

    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

  3. #3
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    Thank you TJ_Tigger

    It works, perfect.
    The idea of the path in the data section is also very useful. Thanks for the idea.

    I try to loop it (for i, v.../ for n=1...) but no luck.

    Anyway now it works fine.

    Once again thank you for your time

    Sside

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by sside
    Thank you TJ_Tigger

    It works, perfect.
    The idea of the path in the data section is also very useful. Thanks for the idea.

    I try to loop it (for i, v.../ for n=1...) but no luck.

    Anyway now it works fine.

    Once again thank you for your time

    Sside
    Either of those should work. I find that the for i,v in table do works very well but for n = 1,TableCount(table) do should work as well
    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

  5. #5
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    Hello TJ_Tigger,

    Yes they work fine as well,
    --------------------------------------------------------------
    resFind = File.Find("data", "*.txt", false, false, nil);

    for i, v in resFind do
    resSplitPath = String.SplitPath(resFind[i]);
    result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[i]);
    end
    --------------------------------------------------------------
    resFind = File.Find("data", "*.txt", false, false, nil);

    for n=1, Table.Count(resFind) do
    resSplitPath = String.SplitPath(resFind[n]);

    result = ListBox.AddItem("ListBox3", resSplitPath.Filename..resSplitPath.Extension, resFind[n]);
    end
    ---------------------------------------------------------------

    Thanks a lot for the help

    Sside

  6. #6
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    TJ_Tigger

    One more question,

    I have a ini file with paths to be searched for, it could be 3, 4, 5 ... paths
    1-I search for the value names (INIFile.GetValueNames) in order to get their values.
    2-I search for values (INIFile.GetValue) in order to get the paths to search for.
    3-I want to search these paths for files.
    -----------------------------------------------------------------------
    resValues = INIFile.GetValueNames("data\\1.ini", "paths");

    for i, v in resValues do
    resPaths = INIFile.GetValue("data\\1.ini", "paths", resValues[i]);
    resSearch = File.Find(resPaths, "*", false, false, nil);
    end

    for i, v in resSearch do
    result = ListBox.AddItem("ListBox3", v, "");
    end
    ------------------------------------------------------------------------
    Only the last value will be stored in resPaths
    So the question is how can i search these paths ?

    Thanks a lot

    Sside

  7. #7
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Probably not the best thing to do but this is what I would probably do.
    Code:
    resValues = INIFile.GetValueNames("data\\1.ini", "paths");
    
    resSearch = {};
    for i, v in resValues do
    resPaths = INIFile.GetValue("data\\1.ini", "paths", resValues[i]);
    tempresSearch = File.Find(resPaths, "*", false, false, nil);
    if tempresSearch then
    for ti, tv in tempresSearch do
    --This insert command will take all the items found if any and place them 
    -- in the first place position pushing everything else down in the table.
    Table.Insert(resSearch, 1, tv)
    end
    end
    
    for i, v in resSearch do
    result = ListBox.AddItem("ListBox3", v, "");
    end
    That is the best I can come up with right now. I might find something better tommorrow.

    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

  8. #8
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    Hello Tigg

    It works fine. Thanks a lot for your help. I'm new to this table thing so.. that's why so many questions.

    Once again thank you.

    Sside

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts