Jump to content

Help with File "Close/Open/Delete"


Recommended Posts

I have a script where I am adding several files into one file, and then deleting each of the multiple files and the final file once its contents have been read to the clipboard and pasted elsewhere.

Problem is that it's not deleting the files until the app is closed.  I"ve read the help file several times, and I've made changes but the files are still "locked"

Any help would be appreciated.

 

Sample code below.

Local $HardwareAdd
            Local $HardwareAdd2
            Local $HardwareAdd3
            Local $HardwareAdd4
            Local $HardwareAdd5
            Local $HardwareAdd6
            Local $HardwareAdd7
            Local $FinalHardwareAddConfig
            GUISetState(@SW_DISABLE)
            $FinalHardwareAddConfig = FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)

            ClipPut($HardwareAdd = FileOpen(@TempDir & "\Multiple Hardware Add.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)

            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd2 = FileOpen(@TempDir & "\Multiple Hardware Add2.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add2.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd3 = FileOpen(@TempDir & "\Multiple Hardware Add3.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add3.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd4 = FileOpen(@TempDir & "\Multiple Hardware Add4.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add4.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd5 = FileOpen(@TempDir & "\Multiple Hardware Add5.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add5.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd6 = FileOpen(@TempDir & "\Multiple Hardware Add6.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add6.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")
            ;FileClose($FinalHardwareAddConfig)

            ClipPut($HardwareAdd7 = FileOpen(@TempDir & "\Multiple Hardware Add7.txt", 1))
            FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
            Local $test = FileRead(@TempDir & "\Multiple Hardware Add7.txt")
            FileWrite($FinalHardwareAddConfig, $test & @CRLF)
            ;FileClose(@TempDir & "\Final Hardware Add Config.txt")



            FileClose($HardwareAdd)
            FileClose($HardwareAdd2)
            FileClose($HardwareAdd3)
            FileClose($HardwareAdd4)
            FileClose($HardwareAdd5)
            FileClose($HardwareAdd6)
            FileClose($HardwareAdd7)
            FileClose($FinalHardwareAddConfig)
            Filedelete(@TempDir & "\Multiple Hardware Add.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add2.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add3.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add4.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add5.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add6.txt")
            Filedelete(@TempDir & "\Multiple Hardware Add7.txt")

All of my data that I want is successfully written to the new file so that good, I just can't figure out why the files won't get deleted.

Edited by atnextc
Link to comment
Share on other sites

DOS internal copy command can concatenate files in a single command line.

anyway, i must confess i'm having trouble following the logic of the script, you declare func _CombinedFiles()

but you don't call it anywhere? and you use the clipboard for what, you have ClipPut but never ClipGet? and you declare $FinalHardwareAddConfig inside the func, but use it outside?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

@orbs see updated post.

essentially i'm writing a router config, and the way i have to do it is write each part to a seperate file, and then coming them into one complete file, which is copied to the clipboard and pasted into an editbox during another part of the script. I'm just trying to figure out why the files aren't being deleted.

Link to comment
Share on other sites

; create the files text1.txt, text2.txt, ... , text6.txt in the same folder as this script, then run the script
For $i=1 To 6
    FileWriteLine('fulltext.txt',FileRead('text'&$i&'.txt')&@CRLF)
    FileDelete('text'&$i&'.txt')
Next
ClipPut(FileRead('fulltext.txt'))
MsgBox(0,'Clipboard contents:',ClipGet())

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • Developers

you got it ? :)

Could you get yourself some chill-pills and take them at regular intervals?

Seriously: You are becoming pretty annoying around here with:

  • Your multiple subsequent replies in threads
  • Your so called opinion which often doesn't contribute to the topic.

 

So, please slow down, relax and stick to a single reply at the time. Use the Edit button when you forgot to mention something.

Jos 

Edited by Jos

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

  • Developers

ok i'll stop my activities.

Not sure if you really mean what you said but that is entirely your choice and not what I requested.

Jos

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

Unfortunately the suggested option of creating the file in the same directory as the script isn't possible neither is the method of looping the file names as is this was just a small posting of the rest of the code which is over 5000 lines and the file names are hard coded for other purposes. But thank you for the reply :)

Link to comment
Share on other sites

Try this, as it's a lot better than what you were doing, there's no need to use the clipboard for any part of this script, and as your files are named the same except for the final digit it's easy to create a loop to add them all to the main file and delete them as soon as you're done with them.

Local $HardwareAdd, $TempFileName, $FinalHardwareAddConfig
Local $FileName = @TempDir & "\Multiple Hardware Add"
GUISetState(@SW_DISABLE)
$FinalHardwareAddConfig = FileOpen(@TempDir & "\Final Hardware Add Config.txt", 1)
For $I = 1 To 7
    $TempFileName = $FileName
    If $I = 1 Then
        $HardwareAdd = FileOpen($TempFileName & ".txt")
    Else
        $TempFileName &= $I 
        $HardwareAdd = FileOpen($TempFileName & ".txt")
    EndIf
    Local $test = FileRead($HardwareAdd)
    FileWrite($FinalHardwareAddConfig, $test & @CRLF)
    FileClose($HardwareAdd)
    FileDelete($TempFileName & ".txt")
Next

FileClose $FinalHardwareAddConfig

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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