Something is lying...
Keep in mind that this works as expected when I run the script manually, but not when it is run via task scheduler.
I have a TCL script that is supposed to check to see if a file exists on a network drive and delete it if it does. I do this by:
if {[file exists X:/path/to/file.txt]} {
log_output "Deleting file X:/path/to/file.txt"
file delete -force X:/path/to/file.txt
}
and i noticed that the file was never being deleted when run via Task Scheduler. So I preformed another check to try to get more information.
if {[file exists X:/path/to/file.txt]} {
log_output "File X:/path/to/file.txt NOT DELETED!"
} else {
log_output "File X:/path/to/file.txt DELETED!"
}
My output is:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
The second line confirms that the file was actually reported as deleted as the exists check failed. Finally, I then run a command that generates a new file.
exec myProgram --outFile X:/path/to/file.txt
Again, the weird thing is when I run this script manually, it works just fine. However, When I have it set to run via task scheduler (using Win7), the old file is not deleted even though the output log shows it was:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
When I check the date and time stamp of the file it is always from the last time I preformed a manual run. I thought it was more of a permissions error, but this doesnt make sense. Why would it report as deleted and still be there unchanged?
To be thorough, I tried some other workarounds. Instead of writing a file to the network drive via the command, I tried writing it locally:
if {[file exists C:/path/to/file.txt]} {
log_output "Deleting file C:/path/to/file.txt"
file delete -force C:/path/to/file.txt
}
if {[file exists C:/path/to/file.txt]} {
log_output "File C:/path/to/file.txt NOT DELETED!"
} else {
log_output "File C:/path/to/file.txt DELETED!"
}
exec myProgram --outFile C:/path/to/file.txt
Then copying it to the network drive:
file copy -force C:/path/to/file.txt X:/path/to/file.txt
file copy -force C:/path/to/file.txt X:/path/to/file1.txt
I get:
Deleting file X:/path/to/file.txt
File X:/path/to/file.txt DELETED!
Deleting file C:/path/to/file.txt
File C:/path/to/file.txt DELETED!
But sure enough, the old file remains and the new file 'file1.txt' does not exist...
Again, manual runs always result in success.
Try this
1.Set the file location or path in a variable as
set way "/XX/XXX".
2.Apply this
if {[file exists $way/file.txt]} {
exec rm -f $way/file.txt
}
I hope this will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With