cancel
Showing results for 
Search instead for 
Did you mean: 

Delete File methods not working

SOLVED
Highlighted
Occasional Contributor

Delete File methods not working

Hi, 

 

I've been attempting to pass in a string to either the aqFileSystem.DeleteFile and/or aqFile.Delete methods in order to delete a single file based on the string, passed in. I am having an issue where the test runs and successfully finishes, however the file is not deleted.

 

If I manually take the string passed in and hard code the value for deletion, the file is deleted, I cannot see why this works with the hard coded string, but not the passed in value, see below example.

 

// At this point a file has been identified for deletion and we are simply creating the expected string value to pass in using the file path.
function OldLogsDelete(aFile){
  var DateTime = aqDateTime.Now();
  var DateTimeMinusXDays = aqDateTime.AddDays(DateTime, -14);
  if (aFile.DateCreated < DateTimeMinusXDays)
    {
      FilePathString = aqConvert.VarToStr(aFile.Path)
      var FilePathString = aqString.Replace(FilePathString, "\\", "\\\\");
      aFile = '"' + FilePathString + '"'
      aqFile.Delete("aFile");
      Log.Message(aFile + "deleted" );
    }

When executed, we get the below output - note this matched the expected value as per example in https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/delete.html:

TCFileDeletion1.Png

Really struggling to see what is wrong here as if I just copy the string and paste it in the method instead of the aFile value, then it works fine.

 

Thanks in advance for any help/suggestion,

Tris

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Delete File methods not working

In the example you provided, the path to the file you want to delete is badly created dynamically.

 

See my attached file.

 

So if you specify the path manually it works properly and if you specify it by the .Path method it doesn't work because you're formatting it badly.

 

 

View solution in original post

4 REPLIES 4
Highlighted
Contributor

Re: Delete File methods not working

1. Is that folder or file accessible 

2. Do you have admin permission while executing script

3. what if Log.Message(.....) not there inside function ? is it still throws error ?

4. Why dont you just return a bool at end of function and see the file status.

Occasional Contributor

Re: Delete File methods not working

Hi Santi,

 

  1. The file/folder is accessable
  2. I am running TestComplete as admin (and have full admin rights on the PC it is running on)
  3. I attempted to run with or without the message, not no error is thrown, I took the screenshot during execution to show string passed in
  4. I don't think the affects the method's function

Thanks,

Tris

Highlighted
Community Leader

Re: Delete File methods not working

In the example you provided, the path to the file you want to delete is badly created dynamically.

 

See my attached file.

 

So if you specify the path manually it works properly and if you specify it by the .Path method it doesn't work because you're formatting it badly.

 

 

View solution in original post

Highlighted
Occasional Contributor

Re: Delete File methods not working

Thanks Wamboo, it was indeed the case that I was adding in formatting unnecessarily - for some reason I thought I needed to add it to the string based on the example I saw, however when declaring the variable the formatting is actually removed from the string once defined.

 

A dumb mistake that took me too long to get! 

 

To anyone interested, I had to amend to the below:

 

// At this point a file has been identified for deletion and we are simply creating the expected string value to pass in using the file path.
function OldLogsDelete(aFile){
  var DateTime = aqDateTime.Now();
  var DateTimeMinusXDays = aqDateTime.AddDays(DateTime, -14);
  if (aFile.DateCreated < DateTimeMinusXDays)
    {
      FilePathString = aqConvert.VarToStr(aFile.Path)
      aqFile.Delete("FilePathString ");
      Log.Message(FilePathString + " deleted" );
    }

 

Thanks again!

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!
Top Kudoed Authors