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:
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
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.