cannot delete file

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

cannot delete file

Post by smhodge » Mon May 28, 2007 7:30 pm

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon May 28, 2007 8:19 pm

I just tested that script and it works fine for me so I would suspect some file access issue. What OS?

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Mon May 28, 2007 8:32 pm

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?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Mon May 28, 2007 9:41 pm

Hmmm, I just did the same test. From an XP user account I could delete (with macroscheduler) a file created by that account with notepad, but could not delete a file created by admin. Did something else write to the file after it was created?

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Tue May 29, 2007 3:28 pm

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 29, 2007 4:14 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 29, 2007 4:18 pm

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?

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Tue May 29, 2007 4:30 pm

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

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Tue May 29, 2007 4:37 pm

The second suggested script, namely:

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
works fine also.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 29, 2007 4:43 pm

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:

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
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Tue May 29, 2007 5:27 pm

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?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 29, 2007 5:57 pm

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?

smhodge
Newbie
Posts: 12
Joined: Mon May 28, 2007 6:46 pm

Post by smhodge » Thu May 31, 2007 7:01 pm

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.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu May 31, 2007 7:39 pm

Hi smhodge,
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?
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?
Help File wrote:Example

RenameFile>c:\temp\myfile.txt,c:\temp\myfile.bak
Does your code then work as expected?
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 - :-)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts