anixon Posted May 8, 2011 Share Posted May 8, 2011 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.. Link to comment Share on other sites More sharing options...
dufran3 Posted May 8, 2011 Share Posted May 8, 2011 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.. 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 More sharing options...
enaiman Posted May 8, 2011 Share Posted May 8, 2011 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 More sharing options...
anixon Posted May 8, 2011 Author Share Posted May 8, 2011 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 9, 2011 Moderators Share Posted May 9, 2011 anixon, This works fine for me (Vista x32 SP2 fully updated - AutoIt v3.3.6.1): $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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
anixon Posted May 9, 2011 Author Share Posted May 9, 2011 (edited) anixon, This works fine for me (Vista x32 SP2 fully updated - AutoIt v3.3.6.1): $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 May 9, 2011 by anixon Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 10, 2011 Moderators Share Posted May 10, 2011 anixon,I did notice that the file opened before it appeared in the file managerAs you are creating the file using FileOpen, how could it appear before it was opened? Is it likely that you could corrupt the script directory or the 'Fred' file if you incorporated a FileSetAttribI very much doubt it.Perhaps if you posted some code which reproduces the problem for you. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
anixon Posted May 11, 2011 Author Share Posted May 11, 2011 anixon,As you are creating the file using FileOpen, how could it appear before it was opened? I very much doubt it.Perhaps if you posted some code which reproduces the problem for you. M23Perhaps 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now