Jump to content

FileDelete()


Recommended Posts

I am creating a file using the code FileOpen($Test,10) where 10 is writemode errase previous contents and create the directory struture if it does not exist adding a number of lines using Filewritetoline and then closing it using FileClose when check the properites of the file'Windows Vista' the only attribute set in 'Details' is 'A' otherwise it would appear that I have full control of the file. I am not setting any of the files read write system attributes using the applicable Autoit command however when trying to delete the file using FileDelete the file remains untouched in tact but can be deleted manually.

The only other code associated with the file after it has been created is ShellExecute($test, "", @ScriptDir, "Edit") and to ensure that the Notepad text editor used to display and or print the file is closed the following code If ProcessExists($NotePadExe) Then ProcessClose($NotePadExe).

My question is does the FileOpen($Test,10) set file or folder attributes which have to be changed in order to gain control of the file and be able to delete it using the FileDelete command.

Help is always appreciated Ant.. :unsure:

Link to comment
Share on other sites

My question is does the FileOpen($Test,10) set file or folder attributes which have to be changed in order to gain control of the file and be able to delete it using the FileDelete command.

Help is always appreciated Ant.. :unsure:

Someone correct me if I'm wrong but if you using FileOpen to open the file, and then are trying to delete it...yeh that's not going to work. You have an open file handle with that file. You need to FileClose() before trying to delete it I believe.

Link to comment
Share on other sites

Hello Ant,

In order to delete a file, that file has to not be used by any application.

As dufran3 said - make sure you have closed the file first and the file is not opened in Notepad or any other application.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Someone correct me if I'm wrong but if you using FileOpen to open the file, and then are trying to delete it...yeh that's not going to work. You have an open file handle with that file. You need to FileClose() before trying to delete it I believe.

You are correct the file must be closed before processing the FileDelete and in such circumstances the issue persists. This is a totally new aboration which seems to have appeared and may be related to updates published by Microsoft althought I cannot say with any certainty that it is related. Perhaps if some also running a Windows Vista desktop which is uptodate with every update patch published by Microsoft could perform a simple test to see if it is a system specific issue. Ant :unsure:

Link to comment
Share on other sites

  • Moderators

anixon,

This works fine for me (Vista x32 SP2 fully updated - AutoIt v3.3.6.1): :unsure:

$sName = "Fred.txt"

$hFile = FileOpen($sName, 10)

FileWrite($hFile, "Fred")

FileClose($hFile)

ShellExecute($sName, "", @ScriptDir, "Edit")

Sleep(10000)

If ProcessExists("NotePad.exe") Then ProcessClose("NotePad.exe")

FileDelete($sName)

Watching in the file manager shows the file being created, edited and destroyed without problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

anixon,

This works fine for me (Vista x32 SP2 fully updated - AutoIt v3.3.6.1): :unsure:

$sName = "Fred.txt"

$hFile = FileOpen($sName, 10)

FileWrite($hFile, "Fred")

FileClose($hFile)

ShellExecute($sName, "", @ScriptDir, "Edit")

Sleep(10000)

If ProcessExists("NotePad.exe") Then ProcessClose("NotePad.exe")

FileDelete($sName)

Watching in the file manager shows the file being created, edited and destroyed without problem.

M23

Thanks for that that code works without any issue although I did notice that the file opened before it appeared in the file manager.

Is it likely that you could corrupt the script directory or the 'Fred' file if you incorporated a FileSetAttrib($Fred, "-RS") where the file was not set as +RS :>

Edit: Or perhaps the mistake I made was changing the attributes after the file was open.. 2nd Edit that did not make a difference at all so my issue at the time was not created by the FileSetAttrib code.. humm .. ;)

Edited by anixon
Link to comment
Share on other sites

  • Moderators

anixon,

I did notice that the file opened before it appeared in the file manager

As you are creating the file using FileOpen, how could it appear before it was opened? :unsure:

Is it likely that you could corrupt the script directory or the 'Fred' file if you incorporated a FileSetAttrib

I very much doubt it.

Perhaps if you posted some code which reproduces the problem for you. :>

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

anixon,

As you are creating the file using FileOpen, how could it appear before it was opened? :unsure:

I very much doubt it.

Perhaps if you posted some code which reproduces the problem for you. :>

M23

Perhaps I did not explain the FileOpen as well as I could. Put simply the Notebook had the file open displaying its contents before that file open by the previous FileOpen process actually appeared in the file manager window. I guess I was expecting that the file would be created appear in the file manager before it was available to be opened by the text editor. Whether that indicates a timing issue that requires some sort of wait statement I will leave to others to comment.

I have noted on past occasions that a cold boot of the system sometimes remedies unexplained issues. Having rebooted my always on system and can confirm that the code as I have written which pretty much mirrors your example works without issue. I therefore have no definitive answer as to what was, might have been, or was the issue that cause the symptom .

I have noticed however that in recent times the File Manager has on occasions become particularly slow which given that my operating system runs on a SDD may indicate an issue unrelated to AutoIT. In the same environment Photoshop CS5 a heavyweight application shows no degradation in launching or processing performance. All of which I have for the time being put down to just another one of life's mysteries Ant ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...