Announcement

Collapse
No announcement yet.

insert variables table into a file.find

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

  • insert variables table into a file.find

    Hi:

    I was searching some solution in this forum by using the search feature first place before posting here and from several attempts to achieve the result to file find certains listing of files stored in a table with no success, I ask: How do you assign the variable string from a usermade table's item to insert into file.find function instead by using "*.*" standard parameter for file find from help file?

    I do try a table like this:

    Code:
    path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
    
    tFileContents = {}
    tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
    tFileContents[2]= "MYCESUR.png"
    tFileContents[3]= "office2007.psd"
    tFileContents[4]= "Reglamentación.pdf"
    tFileContents[5]= "reserva materiales.xlsx"
    
    
    	local nFound = File.Find(path, "*.*", true, true, nil, nil);	
    	count = Table.Count(nFound);
    
    	if nFind ~= -1 then
    		if count ~= 0 then
    		Dialog.TimedMessage("Please Wait...", "files :"..count, 2000, MB_ICONINFORMATION);
    		end
    	end
    If you change the v variable to "*.*" dialog shows that folder with 5 files, untill here is it correct but if you do this;

    Code:
    path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
    
    tFileContents = {}
    tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
    tFileContents[2]= "MYCESUR.png"
    tFileContents[3]= "office2007.psd"
    tFileContents[4]= "Reglamentación.pdf"
    tFileContents[5]= "reserva materiales.xlsx"
    
    for i,v in pairs (tFileContents) do
    	local nFound = File.Find(path, v, true, true, nil, nil);	
    	count = Table.Count(nFound);
    end
    
    	if nFound ~= -1 then
    		if count ~= 0 then
    		Dialog.TimedMessage("Please Wait...", "files :"..count, 2000, MB_ICONINFORMATION);
    		end
    	end
    I know that folder does it have 5 files, instead showing dialog that folder have 5 files it does shows as 1 file not 5. Where I am doing wrong? I am missing something?

  • #2
    When you use your for loop:

    It takes the first item in the table, looks for the file, finds it, counts how many files found (1) and then saves the result to your variable "count".

    It then takes the second item in the table looks for the file, finds it, counts how many files found (1) and then saves the result to your variable "count".

    Etc....

    So count only ever contains the number 1.

    What exactly is it that you are trying to achieve?

    Comment


    • #3
      hi:
      mmm, I though that this function was for look for directly all files besides filetypes does it carries or not ....Im triyng to achieve to count how many files does it have in a folder, if there is 5 in total or so, not "myfile.txt" was found x times in that folder.

      Comment


      • #4
        To count how many files in a folder:

        Code:
        path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
        
        TableOfFiles = File.Find(path, "*.*", true, true, nil, nil);
        
        NumberOfFiles = Table.Count(TableOfFiles);
        
        Dialog.Message("Number of Files", path .. ": " .. tostring(NumberOfFiles));

        To check how many of the files contained within a custom made table are in a folder:

        Code:
        tFilesFound = {}
        
        tFileContents = {}
        tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
        tFileContents[2]= "MYCESUR.png"
        tFileContents[3]= "office2007.psd"
        tFileContents[4]= "Reglamentación.pdf"
        tFileContents[5]= "reserva materiales.xlsx"
        
        path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
        
        for i,v in pairs(tFileContents) do
            TableOfFiles = File.Find(path, v, true, true, nil, nil);
             
             if TableOfFiles ~= -1 then
                   Table.Insert(tFilesFound, Table.Count(tFilesFound)+1, v);
             end
        end
        
        Dialog.Message("Files Found", "Number of Files: " .. NumberOfFiles);
        
        if TableOfFiles ~= nil then
             for i,v in pairs(tFilesFound) do
                   Dialog.Message("Files Found", v);
             end
        end
        Hope this helps

        Comment


        • #5
          For the second script, is it curious that it was needed to do 2 loops separately, first for search with no specific filters it does creates directly a table from this function and then would have to store in the another table I created before at beginning script.

          Thanks for the idea about the table.insert function I thought at first moment this was'nt needed I see is it

          Comment


          • #6
            Well I got your code and tested it I got a variable error, this is I did;
            Code:
            tFilesFound = {}
            
            tFileContents = {}
            tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
            tFileContents[2]= "MYCESUR.png"
            tFileContents[3]= "office2007.psd"
            tFileContents[4]= "Reglamentación.pdf"
            tFileContents[5]= "reserva materiales.xlsx"
            
            path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
            
            for i,v in pairs(tFileContents) do
                TableOfFiles = File.Find(path, v, true, true, nil, nil);
            
                 if TableOfFiles ~= nil then
                    Table.Insert(tFilesFound, Table.Count(tFilesFound)+1, v);
                 	final = Table.Concat(tFilesFound, "\r\n", 1, TABLE_ALL);
            	   	list= Table.Count(tFilesFound);
                 	
                 else
                 Dialog.Message("Error!", "There is not all needed files!");
            	 Application.ExitScript();
                 end
            
            end
               Dialog.Message("Files Found", "Found: "..list.." Files: \r\n"..final);

            Comment


            • #7
              What about using File.DoesExist() for that which is the proper way to accomplish this task

              Code:
              tFileContents = {}
              tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
              tFileContents[2]= "MYCESUR.png"
              tFileContents[3]= "office2007.psd"
              tFileContents[4]= "Reglamentación.pdf"
              tFileContents[5]= "reserva materiales.xlsx"
              
              local path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
              
              if(path ~= "CANCEL") then
              	
              	local strMissingFiles = "";
              	local bError = false;
              	
              	for i,v in pairs(tFileContents) do
              		if(File.DoesExist(path.."\\"..v) == false) then	
              			strMissingFiles = strMissingFiles .. v .."\r\n";
              			bError = true;
              		end
              	end
              	
              	if(bError) then
              		Dialog.Message("Error!", "Following files could not be found in specified folder\r\n\r\n"..strMissingFiles);
              	else
              		--success all files there
              	end
              	
              end
              amsplugins.com Is Closed.

              Facebook Page

              Comment


              • #8
                Hi Reteset;

                Its a good trick the use of boolean variables combined with file.doesxist function I didn't not think about that lol, many thanks for your help. The bError variable did the trick lol. I fullfilled the code for the user forums, I created another virtual table to fill those are missing when searching the files listed in first table declared in first place:

                Code:
                [COLOR="orange"][B]tFileContents = {}
                tFileContents[1]= "GESTION EXISTENCIAS ALMACEN 30.09.13 modificado.xls"
                tFileContents[2]= "MYCESUR.png"
                tFileContents[3]= "office2007.psd"
                tFileContents[4]= "Reglamentación.pdf"
                tFileContents[5]= "reserva materiales.xlsx"[/B][/COLOR]
                
                local path = Dialog.FolderBrowse("Please select a folder:", "AutoPlay\\Docs");
                [B][COLOR="#4169e1"]nMissingFiles = {}[/COLOR][/B]
                if(path ~= "CANCEL") then
                	
                	local strMissingFiles = "";
                	local bError = false;
                	
                	for i,v in pairs(tFileContents) do
                		if(File.DoesExist(path.."\\"..v) == false) then	
                			Table.Insert(nMissingFiles, Table.Count(nMissingFiles)+1, v);
                			nCountMissing = Table.Count(nMissingFiles);
                			strMissingFiles = strMissingFiles .. v .."\r\n";
                			bError = true;
                		else
                		total = Table.Count(tFileContents);
                		end
                	end
                	
                	if(bError) then
                		Dialog.Message("Error!", "Total missing files: "..nCountMissing.." Following files could not be found in specified folder "..path.."\r\n\r\n"..strMissingFiles);
                	else
                		Dialog.Message("Success!", "Found all files: "..total);
                	end
                	
                end
                Thanks again mate!

                Comment

                Working...
                X