cannot delete file
Moderators: JRL, Dorian (MJT support)
cannot delete file
I cannot get the command DeleteFile to work. I've tried it with a simple 2-line test script, one to Change Directory and one to delete the file. I've checked permissions and they are ok. I can delete the file just fine from a file manager.
The test script is:
Change Directory>D:\Steve\Logs
DeleteFile>test.log
This is part of a more complex script that strips lines from a file, writing to a new file in the process, sending emails, and what not, and all that works fine. I just can't get this supposedly very simple step to work! Why not?
Thanks, Steve
The test script is:
Change Directory>D:\Steve\Logs
DeleteFile>test.log
This is part of a more complex script that strips lines from a file, writing to a new file in the process, sending emails, and what not, and all that works fine. I just can't get this supposedly very simple step to work! Why not?
Thanks, Steve
Windows XP Pro SP2 & all latest updates
I created test.log with Notepad and the script with Macro Scheduler all from the same account without logging out at any time. Why would there be any access rights problems...
...unless (I hate to think) Macro Scheduler must have administrator rights to delete a file. Is that the case?
I created test.log with Notepad and the script with Macro Scheduler all from the same account without logging out at any time. Why would there be any access rights problems...
...unless (I hate to think) Macro Scheduler must have administrator rights to delete a file. Is that the case?
I've done some more tests and the DeleteFile simply will not work. I've created test files and the script, both with limited user rights (my regular situation) and with administrator rights, and in no situation does it work.
CopyFile works fine, but, as might be expected, RenameFile does not work either.
I have even tried this script:
Change Directory>D:\Steve\Logs
CopyFile>test.log,testcopy.log
Wait>10
DeleteFile>testcopy.log
Even though "testcopy.log" was created by the script, DeleteFile will not delete it.
Any help would be much appreciated. I just purchased Macro Scheduler to do many tasks, and this is the first one I have attempted, and it does not work. It doesn't leave one with a very good impression.
Steve
CopyFile works fine, but, as might be expected, RenameFile does not work either.
I have even tried this script:
Change Directory>D:\Steve\Logs
CopyFile>test.log,testcopy.log
Wait>10
DeleteFile>testcopy.log
Even though "testcopy.log" was created by the script, DeleteFile will not delete it.
Any help would be much appreciated. I just purchased Macro Scheduler to do many tasks, and this is the first one I have attempted, and it does not work. It doesn't leave one with a very good impression.
Steve
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I'm unable to replicate. Made an exact (save for the paths) copy of your script. Have used DeleteFile in thousands of other scripts over the years and seen it in use in customer scripts and have never encountered an issue. So I think this is specific to your scenario. Maybe something else has the file locked.
What happens with this script:
Change Directory>D:\Steve\Logs
CopyFile>test.log,testcopy.log
Let>RP_WAIT=1
Run>cmd.exe /c del d:\steve\logs\testcopy.log
What created test.log in the first place? Is it owned by the same user you are running under? Is the application that created it still running? What are the attributes?
If you need some help please drop our tech support a line and we can hook up to your desktop and see if we can see what is going on.
What happens with this script:
Change Directory>D:\Steve\Logs
CopyFile>test.log,testcopy.log
Let>RP_WAIT=1
Run>cmd.exe /c del d:\steve\logs\testcopy.log
What created test.log in the first place? Is it owned by the same user you are running under? Is the application that created it still running? What are the attributes?
If you need some help please drop our tech support a line and we can hook up to your desktop and see if we can see what is going on.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
What happens with this:
Code: Select all
//create a file
WriteLn>d:\steve\test.txt,result,This is a test file
Wait>5
//delete the file
DeleteFile>d:\steve\test.txt
IfFileExists>d:\steve\test.txt
MessageModal>file still exists
Else
MessageModal>file deleted
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
That script works. In fact, I accidentally discovered that the "RP_WAIT=1" is not necessary.
Test.log was created by notepad in the same login session that the script tests were made, and notepad was closed after creating the file and before running the script. In fact, for other reasons, I have also rebooted the computer and logged back in and, using the same file unaltered, still got the same (negative) results.
The file attributes are perfectly "normal", ie, not read-only and not hidden. Under "Security" it is owned by the correct user (ie, me) with "full control". There is absolutely nothing strange about any of these settings; they are the same as countless other files I have created.
Steve
Test.log was created by notepad in the same login session that the script tests were made, and notepad was closed after creating the file and before running the script. In fact, for other reasons, I have also rebooted the computer and logged back in and, using the same file unaltered, still got the same (negative) results.
The file attributes are perfectly "normal", ie, not read-only and not hidden. Under "Security" it is owned by the correct user (ie, me) with "full control". There is absolutely nothing strange about any of these settings; they are the same as countless other files I have created.
Steve
The second suggested script, namely:
works fine also.
Code: Select all
//create a file
WriteLn>d:\steve\test.txt,result,This is a test file
Wait>5
//delete the file
DeleteFile>d:\steve\test.txt
IfFileExists>d:\steve\test.txt
MessageModal>file still exists
Else
MessageModal>file deleted
Endif
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
RP_WAIT=1 is necessary if the script has additional steps - otherwise the script will not wait for the Run>cmd... line to complete before continuing.
I've just created a file in notepad. Then saved it and closed notepad. Then deleted it with a one line DeleteFile script. Works fine.
Try this:
That works for me. It carries out the exact steps you have done - creates a new file in notepad, saves it, closes notepad and then deletes it.
I've just created a file in notepad. Then saved it and closed notepad. Then deleted it with a one line DeleteFile script. Works fine.
Try this:
Code: Select all
//Create a new file in Notepad ... mimics what you did manually
Run>notepad.exe d:\steve\newtestfile.txt
WaitWindowOpen>notepad*
SetFocus>notepad*
Wait>1
//Confirm we want to create a new file
Press Enter
Wait>1
//Send some text into notepad
Send>Hello World
Wait>1
//Save the file
Press CTRL
Send>s
Release CTRL
Wait>1
//Close Notepad
Press ALT
Press F4
Release ALT
//Delete the file just created
DeleteFile>d:\steve\newtestfile.txt
//Has it gone?
IfFileExists>d:\steve\newtestfile.txt
MessageModal>file still exists
Else
MessageModal>file deleted
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
The last script you sent me also works. In fact, I broke it into two separate scripts, one to create the file and one to delete it, and they work just fine also.
I then had a hunch that it was not the DeleteFile function but rather the Change Directory one, and indeed that is the case. If I simply put the full path into my very first original script, it works just fine. In other words,
DeleteFile>d:\steve\test.log
works, but
Change Directory>d:\steve
DeleteFile>test.log
does not work.
Can you reproduce this?
I then had a hunch that it was not the DeleteFile function but rather the Change Directory one, and indeed that is the case. If I simply put the full path into my very first original script, it works just fine. In other words,
DeleteFile>d:\steve\test.log
works, but
Change Directory>d:\steve
DeleteFile>test.log
does not work.
Can you reproduce this?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
That works for me.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Problem solved, sort of.
On a hunch I did a complete uninstall (using Total Uninstall) and then a complete fresh install of Macro Scheduler. That fixed the problem with Change Directory. My original installation was the trial version overwritten with the licensed downloaded version. The new fresh install was done from the CD that I received in the mail. (Thanks for the CD; it saved the day.)
However, there is still a glitch. I have two files, the second a temporary file created from the first (with the preceding part of the script). At successful completion I simply wish to replace the original file with the new one using the same original file name. My initial script was simply:
...
...create nod32.tmp from nod32.log
...
DeleteFile>nod32.log
RenameFile>nod32.tmp,nod32.log
The original nod32.log is successfully deleted, and a copy of the temporary file (nod32.tmp) is created with the desired original name, nod32.log. However, the temporary file does not get deleted. This is not what I would expect a "rename" would do. Why not?
The script
DeleteFile>nod32.log
CopyFile>nod32.tmp,nod32.log
DeleteFile>nod32.tmp
works fine.
On a hunch I did a complete uninstall (using Total Uninstall) and then a complete fresh install of Macro Scheduler. That fixed the problem with Change Directory. My original installation was the trial version overwritten with the licensed downloaded version. The new fresh install was done from the CD that I received in the mail. (Thanks for the CD; it saved the day.)
However, there is still a glitch. I have two files, the second a temporary file created from the first (with the preceding part of the script). At successful completion I simply wish to replace the original file with the new one using the same original file name. My initial script was simply:
...
...create nod32.tmp from nod32.log
...
DeleteFile>nod32.log
RenameFile>nod32.tmp,nod32.log
The original nod32.log is successfully deleted, and a copy of the temporary file (nod32.tmp) is created with the desired original name, nod32.log. However, the temporary file does not get deleted. This is not what I would expect a "rename" would do. Why not?
The script
DeleteFile>nod32.log
CopyFile>nod32.tmp,nod32.log
DeleteFile>nod32.tmp
works fine.
Hi smhodge,
What happens if you instead use the full path name in your "RenameFile>" line like in the example code in the "RenameFile" topic in the Help file?smhodge wrote:...
...create nod32.tmp from nod32.log
...
DeleteFile>nod32.log
RenameFile>nod32.tmp,nod32.log
The original nod32.log is successfully deleted, and a copy of the temporary file (nod32.tmp) is created with the desired original name, nod32.log. However, the temporary file does not get deleted. This is not what I would expect a "rename" would do. Why not?
Does your code then work as expected?Help File wrote:Example
RenameFile>c:\temp\myfile.txt,c:\temp\myfile.bak
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
