R. E. Cook
Home 
Contact Us 

Dr. Cook
Resume 

RunningShoes Library for WinRunner 
RunningShoes 

Custom WinRunner Functions 
and Utilities,
to Your Specs
Custom 

A Random Collection of WinRunner Solutions
Solutions 

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

R. E. Cook Consulting

 


Delete a folder and all files in the folder

Functions: FolderListFiles(), FolderDelete(), FileDelete(), FileSetAttributes()


Deleting a folder full of files is simple with RunningShoes. Delete all files in the folder, then delete the folder itself. The easy way is to capture an array with all of the filenames, then loop through the array, deleting each file after turning off any attributes that might prevent the deletion. When the folder is empty, delete it too. 


Code sample

## Define the path to the folder.
folder = "c:\\FilesToBeDeleted\\";

## Capture an array of files in the folder.
rc = FolderListFiles(folder, file_arr);

## Display an error message if the function fails.
if(rc != E_OK)
{
    message = "Error capturing filenames: " & RSReturnCodes(rc, RETURN_MESSAGE_BRIEF);
    pause(message);
}

## Delete all files in the array.
for(subscript in file_arr)
{
    ## Append the filename to the path.
    current_file = folder & file_arr[subscript];

    ## Turn off all attributes so the file can be deleted.
    rc = FileSetAttributes(current_file, FILE_ATTRIBUTE_NORMAL);

    ## Delete the file.
    rc = FileDelete(current_file);
}

## Delete the folder.
rc = FolderDelete(folder);


Updated 17 January 2005



Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.