MSI Factory 2.3

File.Delete

File.Delete

This is the first topic This is the last topic  

File.Delete

This is the first topic This is the last topic  

OverviewExamples

File.Delete (

string   Source,

boolean Recurse = false,

boolean AbortOnFail = false,

boolean IncludeHiddenFiles = true,

function CallbackFunction = nil )

Example 1

File.Delete(_TempFolder.."\\TempSetup\\*.txt");

Deletes all of the text files in the "TempSetup" folder located in the user's Temporary folder, and does not go into any subfolders inside "TempSetup" as it searches for files ending in .txt.

Note: _TempFolder is a built-in variable that contains the path to the user's Temporary directory.

Example 2

File.Delete(_TempFolder .. "\\install.log", false, false, true, CB_Delete);

Deletes a file named "install.log" from the user's temp folder. The action is told not to recurse into subfolders, not to abort on failure, and to delete the file even if its "hidden" or "system" attributes are set. A function named CB_Delete will be called whenever progress is made in the delete operation (i.e. every time x number of bytes are deleted).

Example 3

-- Gets the path to the user's My Documents folder.

my_docs_path = Shell.GetFolder(SHF_MYDOCUMENTS);

 

-- Check to see if the My Documents folder detection was successful.

if (Application.GetLastError() == 0)then

 

   -- Search the user's My Documents folder for the file "Data.ini".

   search_results = File.Find(my_docs_path, "Data.ini", true, false, nil);

 

   --Check to see if an error occurred during the search. If it did, display the error message.

   error = Application.GetLastError();

   if error ~= 0 then

       Dialog.Message("Error",_tblErrorMessages[error]);

   else

 

       -- If no files were found, notify the user.

       if (search_results == nil) then

           Dialog.Message("Notice", "Data.ini was not found in your My Documents folder.");

 

       -- If files were found, display a dialog containing a list of their locations.

       -- Also ask for deletion confirmation.

       else

           message = "Data.ini was found in the following location(s). Click OK to delete the file(s):\r\n\r\n";

           for index, path in search_results do

               message = String.Concat(message, path.."\r\n");

           end

           proceed = Dialog.Message("File Search Results", message, MB_OKCANCEL, MB_ICONQUESTION, MB_DEFBUTTON1);

 

           -- If the user clicked OK, delete all of the files found.

           if proceed == IDOK then

 

               -- Delete each file found in the search.

               for index, path in search_results do

                   File.Delete(path, false, false, false, nil);

 

                   -- Check to see if any errors occurred during the deletion.

                   if (Application.GetLastError() ~= 0) then

                       Dialog.Message("Error", "The file located at: "..path.." could not be deleted.");

                   end

               end

           end

       end

   end

end

This example uses the File.Find action to search for all copies of a particular INI file in the user's My Documents folder. If the file is found in more than one location, the user is presented with the list and asked if they wish to delete them. If they agree, each copy is deleted using the File.Delete action.

See also: Related Actions


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us