Jump to content

FileDelete WONT filedelete


Recommended Posts

have searched the forums and found nothing to help me.

here is a snippet of my code, all i want it to do is delete the inientry and associate .txt file.

Case $iMsgBoxAnswer = 6;Yes
                        $ar = IniReadSection($IniFile, "names")
                        IniDelete($IniFile, "names")
                        $rr = GUICtrlRead($char_combo)
                        For $y = 1 To $ar[0][0]
                            If $ar[$y][1] <> $rr Then IniWrite($IniFile, "names", $ar[$y][0], $ar[$y][1])
                            
                        Next
                        _GUICtrlComboDeleteString($char_combo, _GUICtrlComboGetCurSel($char_combo))

                        FileDelete(@MyDocumentsDir & "\" & $rr & ".txt")
Link to comment
Share on other sites

Hi,

I realy can not see the problem, it sims that you have a correct code there...

I can't say more, because...

1) i don't know if the file @MyDocumentsDir & "\" & $rr & ".txt" is realy the file that exists and need to be deleted.

2) i don't know what in the combobox (what value).

3) you have all rights to delete files on your system?

maby also the file is buesy with other process... check the returned value of FileDelete, it should be 1 on secess, or 0 on failure.

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

i think the problem is when i create the file.

inifile looks like;-

[names]

0=test

1=test2

Dim $IniFile = @MyDocumentsDir & "\config.ini"
$op = FileOpen($IniFile, 0)
If $op = -1 Then
    IniWrite($IniFile, "names", "0", "0")
Else
    $var_open = IniReadSection($IniFile, "names")
    
    If @error = 0 Then
        For $xi = 1 To $var_open[0][0]

            FileOpen(@MyDocumentsDir & "\" & $var_open[$xi][1] & ".txt", 0)
            GUICtrlSetData($char_combo, $var_open[$xi][1])
            
        Next
    Else
    ;GUICtrlSetData($log,"No data")
    EndIf
EndIf

fileopen doesnt have a handle.

but i dont know how to create one in this example, would it be something like;-

$op[$xi]=FileOpen(@MyDocumentsDir & "\" & $var_open[$xi][1] & ".txt", 0)

any ideas

Link to comment
Share on other sites

Hi,

you needn't to FileOpen the file before writing to it with iniFuncs.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

my prog crates 2 file,

1, an inifile for config.

NEVER use FileOpen on an INI file. It will make INI functions fail.

2, a text file for data.

do i not need to open the textfile.?

NO. Unless you need to use binary, raw or any of the other FileRead or FileWrite options. If you also read or write very often to a file, then using FileOpen can save unneeded opening and closing of file handles between each operation. FileOpen can be used also to check if a file is accessible to use.

:rolleyes:

Link to comment
Share on other sites

Hi,

depends whether you arite to the txt file with iniFuncs then no, Filewrite then yes.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 3 weeks later...

Aceguy, did you ever get your FileDelete operation working? I've got a script that's also not deleting files. My files are:

$FTPS_Script = @ScriptDir & "\ftps_script.txt"
$Custom_Backup = @ScriptDir & "\custom_backup.txt"
$Restore_Files = @ScriptDir & "\restore_files.txt"
When I'm done with them, I'm doing my FileDeletes as:
FileDelete($FTPS_Script)
FileDelete($Custom_Backup)
FileDelete($Restore_Files)
The files are created by my script and I'm an local admin on the machine, so file rights don't seem to be the issue. I can even delete those same files from a different script. But I don't want to be calling other scripts just to delete my temp files.

Link to comment
Share on other sites

Are these files closed before trying to delete them ?

Yes, I'm doing a FileOpen, reading the contents of the file, then FileClose, FileDelete.

Hatcheda, some of the files are being created/used multiple times in the script, so I need to be able to delete them each time I finish with them. Particularly because a couple of them are being read into an array. I've tried just overwriting the files, but then I get an array with empty strings later in the script. I could check for that, but I'd rather have the files deleted.

Link to comment
Share on other sites

  • Developers

Yes, I'm doing a FileOpen, reading the contents of the file, then FileClose, FileDelete.

Can you show these portions of the code to see if any mistakes are made or that replicates the problem you have?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Sure...

$Omit_List = _ArrayCreate("Administrator", "TeamAdmin", "Default User", "MachineKeys", "cookies", "Downloader", "\Temp\", "Temporary Internet Files", "\Local Settings\History", "user.dmp", "usrclass.dat", "usrclass.dat.log", "ntuser.dat", "ntuser.dat.log", ".ost", "Cache", "Microsoft Help", "\Recent\")
        
        FileOpen($FTPS_Script, 2)
        FileWriteLine($FTPS_Script, $username & @CRLF & $password & @CRLF & _
                'get /custom_exclude.txt "' & $Custom_Exclude & '"' & @CRLF & _
                'quit')
        FileClose($FTPS_Script)
        If _FTPS() = 0 Then Exit
        FileDelete($FTPS_Script)
        
        If FileExists($Custom_Exclude) Then
            $Custom_Omit_List = ""
            If _FileReadToArray($Custom_Exclude, $Custom_Omit_List)=1 Then
                For $i=1 to UBound($Custom_Omit_List)-1
                    _ArrayAdd($Omit_List, $Custom_Omit_List[$i])
                Next
            EndIf
        EndIf
        
        FileDelete($Custom_Exclude)
            
        $find = ''
        For $i = 1 To Ubound($Omit_List) - 1
            $find = $find & '| find /i /v "' & $Omit_List[$i] & '" '
        Next
        RunWait(@ComSpec & ' /c dir /b /s /a-d /o:e "' & $vPath & '" ' & $find & '> "' & @TempDir & '\tmpOUTPUT.txt"', @WorkingDir, @SW_HIDE)
        _FileReadToArray(@TempDir & "\tmpOUTPUT.txt", $File_List)
        FileDelete(@TempDir & "\tmpOUTPUT.txt")

Only FileDelete(@TempDir & "\tmpOUTPUT.txt") is working in this script.

Link to comment
Share on other sites

Hi 2tim3_16,

You are open file, but write to it using the file name itself (you must use the file handle that return FileOpen()), and closing the file name :)

Try this:

$FileOpenHandle = FileOpen($FTPS_Script, 2)
        FileWriteLine($FileOpenHandle, $username & @CRLF & $password & @CRLF & _
                'get /custom_exclude.txt "' & $Custom_Exclude & '"' & @CRLF & _
                'quit')
        FileClose($FileOpenHandle)

Now the file will be closen, and now you can delete the file :P

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • Developers

Sure...

FileOpen($FTPS_Script, 2)

FileWriteLine($FTPS_Script, $username & @CRLF & $password & @CRLF & _

'get /custom_exclude.txt "' & $Custom_Exclude & '"' & @CRLF & _

'quit')

FileClose($FTPS_Script)

This is a common made mistake... You need to work with filehandles. like MsCreatoR explained...

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hey guys, thanks for the help. I've changed it to

$FileOpenHandle = FileOpen($FTPS_Script, 2)
FileWriteLine($FileOpenHandle, $username & @CRLF & $password & @CRLF & _
    'get /custom_exclude.txt "' & $Custom_Exclude & '"' & @CRLF & _
    'quit')
FileClose($FileOpenHandle)
If _FTPS() = 0 Then Exit
FileDelete($FTPS_Script)
but it's still not deleting the file.

BTW, here's the _FTPS() function referred to:

Func _FTPS()
    RunWait('"C:\Program Files\MOVEit Freely\ftps.exe" -e:on -a -z ' & $FTPS_server & ' -s:"' & $FTPS_Script & '"', '', @SW_HIDE)
        If @error = 1 Then 
            Return 0
        Else
            Return 1
        EndIf
EndFunc  ;==>_FTPS
Edited by 2tim3_16
Link to comment
Share on other sites

  • Developers

Hey guys, thanks for the help. I've changed it to

$FileOpenHandle = FileOpen($FTPS_Script, 2)
FileWriteLine($FileOpenHandle, $username & @CRLF & $password & @CRLF & _
    'get /custom_exclude.txt "' & $Custom_Exclude & '"' & @CRLF & _
    'quit')
FileClose($FileOpenHandle)
If _FTPS() = 0 Then Exit
FileDelete($FTPS_Script)
but it's still not deleting the file.
what about when you remove this line? : If _FTPS() = 0 Then Exit

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

what about when you remove this line? : If _FTPS() = 0 Then Exit

That's deleting it. So maybe MOVEIt Freely (ftps.exe) isn't releasing the file? I thought that using RunWait would mean that ftps.exe has completely exited before the script goes on.

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...