Announcement

Collapse
No announcement yet.

search folder on all the drives

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • kevin8
    replied
    Originally posted by colc View Post
    Updated
    [ATTACH]n305768[/ATTACH]
    perfect

    Leave a comment:


  • colc
    replied
    Updated
    Folder search in drives2.apz

    Leave a comment:


  • kevin8
    replied
    Originally posted by colc View Post
    OK try this litte apz
    [ATTACH]n305763[/ATTACH]
    We use Drive.Enumerate to get a Table of ALL drives
    We then create another table of Fixed Drives with a table count
    Loop through to search for folder
    If not found on last count Drive then create the folder

    Please try and study the code, Cheers
    If do not enter a folder name and click the Cancel button, a cancel folder will be created, Maybe add an IF statement. I try it. Thank you again

    Leave a comment:


  • colc
    replied
    OK try this litte apz
    Folder Search_Drives.apz
    We use Drive.Enumerate to get a Table of ALL drives
    We then create another table of Fixed Drives with a table count
    Loop through to search for folder
    If not found on last count Drive then create the folder

    Please try and study the code, Cheers

    Leave a comment:


  • kevin8
    replied
    Originally posted by colc View Post
    Please man do some research on the given code and if you cannot understand basic code then what's the point - YOU want someone to write everything for you.

    From your original "found code" the line
    Code:
    search_results = Folder.Find(DriveLetter, folder, [COLOR=#3498db]true[/COLOR], FindCallBack);
    The TRUE recurses the search for all folders - searches within folders AS you want your folder to search in root directory of drive then that should be FALSE

    As to your practical example just add code to
    Code:
    -- If no directories were found, inform the user
    if (search_results == nil) then
    Check folder.create [hint: DriveLetter.."\\ABC"]

    Cheers
    I haven't done it yet, I need to create the ABC folder on the last local drive, In the example above, it's disk E:, not created under each drive

    Leave a comment:


  • colc
    replied
    Please man do some research on the given code and if you cannot understand basic code then what's the point - YOU want someone to write everything for you.

    From your original "found code" the line
    Code:
    search_results = Folder.Find(DriveLetter, folder, [COLOR=#3498db]true[/COLOR], FindCallBack);
    The TRUE recurses the search for all folders - searches within folders AS you want your folder to search in root directory of drive then that should be FALSE

    As to your practical example just add code to
    Code:
    -- If no directories were found, inform the user
    if (search_results == nil) then
    Check folder.create [hint: DriveLetter.."\\ABC"]

    Cheers

    Leave a comment:


  • kevin8
    replied
    Originally posted by colc View Post
    My dear friend in your title you said "All Drives" , in the exampleyou see how the drive types were listed with drive letters.
    Now we know fixed drive type is 3 so we place a if statment to only search for fixed drives

    Code:
    -- Set the folder to search for
    folder = Dialog.Input("Folder Search", "Please Enter Folder Name:", "", MB_ICONQUESTION);
    
    
    -- Get a list of the available drives and loop through returned table looking for folder.
    tbDrives = Drive.Enumerate();
    
    
    for i,DriveLetter in pairs(tbDrives) do
    [COLOR=#c0392b]---Get the drive type
    nType = Drive.GetType(DriveLetter)--we get the drive type and if fixed = 3 then search
    if nType == 3 then[/COLOR]
    if not cancel then --check if user cancelled search, check globals
    StatusDlg.Show(0, false);
    search_results = Folder.Find(DriveLetter, folder, true, FindCallBack);
    --Check to see if an error occurred during the search. If it did, display the error message.
    error = Application.GetLastError();
    StatusDlg.Hide();
    if error ~= 0 then
    Dialog.Message("Error",_tblErrorMessages[error]);
    else
    -- If no directories were found, inform the user
    if (search_results == nil) then
    message = "No folder named " .. folder .. " on Drive " .. DriveLetter .. " found."
    Dialog.Message("Notice",message );
    
    -- If folders were found, display a dialog containing a list of their locations.
    else
    message = "A folder named '" .. folder .. "' was found at the following location(s):\r\n\r\n";
    for index, path in pairs(search_results) do
    message = String.Concat(message, path.."\r\n");
    end
    Dialog.Message("File Search Results", message, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    end
    
    
    else
    
    break;--exits loop
    
    end
    [COLOR=#c0392b]end[/COLOR]
    end
    Add the code in red to your findfolder button
    Cheers
    Thank you for your help.
    I found that the search speed is very slow. Maybe my description is wrong. My English is not very good

    Here's a practical example,

    I currently have three local drives on my computer, which are C: D: E: and three mobile drives: F: G: H:
    Check whether the ABC folder under the local drive exists. If it exists, the folder path will be displayed 【for example, D: \ABC】. If not, create a folder in the last local drive 【for example, create an ABC folder under disk E:】
    C:\ABC
    D:\ABC
    E:\ABC

    The search speed will be very fast,In this case, is there simpler code? Thank you in advance

    Leave a comment:


  • colc
    replied
    My dear friend in your title you said "All Drives" , in the exampleyou see how the drive types were listed with drive letters.
    Now we know fixed drive type is 3 so we place a if statment to only search for fixed drives

    Code:
    -- Set the folder to search for
    folder = Dialog.Input("Folder Search", "Please Enter Folder Name:", "", MB_ICONQUESTION);
    
    
    -- Get a list of the available drives and loop through returned table looking for folder.
    tbDrives = Drive.Enumerate();
    
    
    for i,DriveLetter in pairs(tbDrives) do
    [COLOR=#c0392b]---Get the drive type
    nType = Drive.GetType(DriveLetter)--we get the drive type and if fixed = 3 then search
    if nType == 3 then[/COLOR]
    if not cancel then --check if user cancelled search, check globals
    StatusDlg.Show(0, false);
    search_results = Folder.Find(DriveLetter, folder, true, FindCallBack);
    --Check to see if an error occurred during the search. If it did, display the error message.
    error = Application.GetLastError();
    StatusDlg.Hide();
    if error ~= 0 then
    Dialog.Message("Error",_tblErrorMessages[error]);
    else
    -- If no directories were found, inform the user
    if (search_results == nil) then
    message = "No folder named " .. folder .. " on Drive " .. DriveLetter .. " found."
    Dialog.Message("Notice",message );
    
    -- If folders were found, display a dialog containing a list of their locations.
    else
    message = "A folder named '" .. folder .. "' was found at the following location(s):\r\n\r\n";
    for index, path in pairs(search_results) do
    message = String.Concat(message, path.."\r\n");
    end
    Dialog.Message("File Search Results", message, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    end
    
    
    else
    
    break;--exits loop
    
    end
    [COLOR=#c0392b]end[/COLOR]
    end
    Add the code in red to your findfolder button
    Cheers

    Leave a comment:


  • kevin8
    replied
    Originally posted by colc View Post
    try this - check documented code in project
    [ATTACH]n305738[/ATTACH]
    Cheers
    Thank you for your help,

    Now there is a problem. If I have a removable hard disk or USB drive on my computer, the drive letter will also be displayed

    I just want to search the drive of local hard disk. How to achieve this?

    My programming level is too low, which may be very simple for the master

    Leave a comment:


  • colc
    replied
    try this - check documented code in project
    Folder_Search.apz
    Cheers

    Leave a comment:


  • kevin8
    started a topic search folder on all the drives

    search folder on all the drives

    Hello, everyone. I have just learned how to use autoplay media studio. I have encountered some problems. I hope someone can give some guidance. Any suggestions are welcome. Thank you in advance

    I wanted to search folder ABC on all the drives on my computer. I found the following two pieces of code, but I didn't know how to merge them to achieve my goal,




    Find the ABC folder under drive C:\

    Code:
    -- Set the callback function (used by action Folder.Find)
    function FindCallBack(CurrentFolder)
    -- Show the cancel button
    StatusDlg.ShowCancelButton(true, "Cancel");
    -- Set the status dialog title, message, and status text
    StatusDlg.SetTitle("Searching . . . ");
    StatusDlg.SetMessage("Please wait. Search is in progress.");
    StatusDlg.SetStatusText("Current Folder: " .. CurrentFolder);
    -- Check if the user pressed cancel
    cancel = StatusDlg.IsCancelled();
    if cancel then
    -- Cancel was pressed, stop the current operation
    return false;
    else
    -- Cancel was not pressed, continue
    return true;
    end
    end
    
    -- Set the drive to search
    drive = "C:\\";
    -- Set the folder to search for
    folder = "abc";
    -- Search the specified drive for folders named "windows"
    -- Display the status dialog
    StatusDlg.Show(0, false);
    search_results = Folder.Find(drive, folder, true, FindCallBack);
    --Check to see if an error occurred during the search. If it did, display the error message.
    error = Application.GetLastError();
    StatusDlg.Hide();
    if error ~= 0 then
    Dialog.Message("Error",_tblErrorMessages[error]);
    else
    -- If no directories were found, inform the user
    if (search_results == nil) then
    Dialog.Message("Notice", "There are no folders named '" .. folder .. "' on drive '" .. drive .. "'.");
    -- If folders were found, display a dialog containing a list of their locations.
    else
    message = "A folder named '" .. folder .. "' was found at the following location(s):\r\n\r\n";
    for index, path in pairs(search_results) do
    message = String.Concat(message, path.."\r\n");
    end
    Dialog.Message("File Search Results", message, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    end

    Gets all of the drive letters on the user's system and stores them in a numerically indexed table of drive letters called "drives".

    Code:
    -- Get a list of the available drives.
    drives = Drive.Enumerate();
    
    -- Determine if an error occurred.
    error = Application.GetLastError();
    
    -- If an error occurred, display the error message.
    -- If no error occurred, display the available drives in a dialog.
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    else
    
        -- Create a string consisting of all of the drive letters and display them.
        all_drives = Table.Concat(drives, "\r\n");
        Dialog.Message("Notice", "Below is a list of all of your current drives:\r\n"..all_drives);
    end
Working...
X