Unreliable File Deletion

R.H. roland.huettmann at gmail.com
Sun Mar 28 13:11:15 EDT 2021


@ Peter Reid

Your message found my attention.
Also I am working on Windows 10 and have the same problem using LC 9.6.1
Indy version.

The problem with copying text to the clipboard and then pasting it into
other applications results in inserting double lines. I think there was a
discussion about the clipboard on the forum or here recently. Instead of
directly copying the text, I create a temp file temp.txt, insert the text
to be copied, then read the file and then I can paste the text reliably.
The file is then deleted.

The similar or same problem as you have: I want to delete the text file.
The command I issue is "detele file <pathname>". The error it returns:
"Can't delete file".

So, I tried using a forced Shell command which did not work (probably it
needs Admin rights). But the standard Shell command deletes the file.

Here is the script snippet:

// The original purpose of using this script as part of a larger script is
to copy column names of a database table to the clipboard and insert them
anywhere.

## Script snippet calling Shell (Windows 10/64)
// Save data to external file to get rid of wrong carriage returns in
Windows
// Copy data as text to the clipboard
// Space are replaced by "." for this message list
// A temporary text file is created and shall be deleted after usage
// tOut contains the resulting data from before...
//  myMsg is a separate custom message handler that directs messages either
to the message box, writes to a log file or places the message into a
field, or all together...)

... local tOut
... local tFilePath
... local tResult
... local tCmd

... put specialfolderpath("resources") &"/temp.txt" into tFilePath
... put tOut into URL("binfile:"&tFilePath)
... put URL("binfile:"&tFilePath) into tOut
... set the clipboarddata["text"] to tOut

... // Delete temp file
... delete file ("binfile:"&tFilePath)
... put the result into tResult
... if "can't delete that file" is in tResult then

...... myMSG tHInfo & "File could not be deleted." &CR& tFilePath --> My
message handler
...... if the platform is "win32" then
......... set the hideConsoleWindows to true
......... replace "/" with "\" in tFilePath
......... put quote & tFilePath & quote into tFilePath
......... put "del "&tFilePath into tCmd -- this shell command works for me
......... put shell(tCmd) into tResult
......... put CR& the result after tResult
......... /* Comment: Error messages appear when using "rmdir /s /q"
......... to force delete the file
......... Error message: Invalid switch - "Users".  */
......... myMSG tHInfo & tResult --> My message handler
...... end if
... end if
##/ End script snipped

So, if other users have the problem that a file cannot be deleted with the
"delete file" command (even though it he file tit is not flagged as part of
another process or flagged as "cant delete") then this seems to be a bug.

I would report it if I am not the only one seeing the problem.

Roland



More information about the use-livecode mailing list