Jump to content

About file ...


Recommended Posts

Hi all, i have doubts about some file matter needing your help.

Normally, when a file is opened and using by a window or a program, it will be locked and associated with that program, with window restricting, so u can not delete, rename or save editting this file. I wonder that can we unlock or close a file which is using or opening by a program for deleting, renaming ... the file? Thanks.

Link to comment
Share on other sites

Why do you want to delete/rename a file that another program has open? I'm sure that's going to cause some issues with that program when it tries to read/write to the file that's not there anymore.

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

Some program will automatic create a new file if the file is deleted or missing, or for example i need adjust some configuration conditions without exit the program, of course, i know when or how edit the file to not effect the program running. I just wonder if we can do it?

Edited by hiepkhachsg
Link to comment
Share on other sites

When it's your own program its possible if you don't lock the file, small example:

#cs -----------------------------------------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:                        AutoBert:    http://autoit.de/index.php?page=Thread&postID=164341#post164341

    Skriptbeispiel für den Umgang mit INI-Files und ComboBox
#ce -----------------------------------------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <StaticConstants.au3>

Const $sElect = "bitte eine URL auswählen"
Const $sAppIni=@AppDataDir&"\URLs.INI"
Global $URL

If Not FileExists($sAppIni) Then
    $sData = "AutoIt=http://autoit.de" & @LF
    $sData &= "Buch=http://autoit.de/index.php?page=Thread&postID=92818#post92818" & @LF
    $sData &= "richtig Posten=http://autoit.de/index.php?page=Thread&threadID=4424" & @LF
    $sData &= "Tutorial=http://wiki.autoit.de/wiki/index.php/Tutorial" & @LF
    $sData &= "Skriptfehler finden=http://autoit.de/index.php?page=Thread&threadID=13785" & @LF
    $sData &= "Hilfe=http://translation.autoit.de/autoitinfo/hilfedateien/AutoIt-Hilfe-Deutsch-3.3.6.1-Stand-09_05_10.zip" & @LF
    $sData &= "MiniUrl-Manger=http://autoit.de/index.php?page=Thread&postID=164341#post164341" & @LF
    IniWriteSection($sAppIni, "URLs", $sData)
EndIf

$hGui = GUICreate("MiniUrl-Manager", 300, 90, 302, 218)
$hcboProg = GUICtrlCreateCombo("", 8, 8, 200, 25)
$hbtnAdd = GUICtrlCreateButton("&Hinzufügen", 213, 8,80)
$hbtnDel = GUICtrlCreateButton("&Löschen", 213, 35,80)
$hlblURL = GUICtrlCreateLabel("", 8, 70, 290,25)
$hbtnOpen = GUICtrlCreateButton("&Öffnen", 8, 35,200)
GUICtrlSetState($hbtnOpen, $GUI_DISABLE)
GUICtrlCreateGraphic(0,65,300,2,$SS_ETCHEDHORZ )
read_INI()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hbtnAdd
            $write1 = InputBox("URL", "Bitte eine gültige URL eingeben")
            If $write1 <> "" Then
                $write2 = InputBox("URL verwalten  unter", "Bitte Kurzbegriff eingeben")
                If $write2 <> "" Then IniWrite($sAppIni, "URLs", $write2, $write1)
                GUICtrlSetData($hcboProg, $write2, $write2)
            EndIf
            show_Selection()
        Case $hbtnDel
            $sDel = GUICtrlRead($hcboProg)
            IniDelete($sAppIni, "URLs", $sDel)
            GUICtrlSetData($hcboProg,"")
            read_INI()
        Case $hcboProg
            show_Selection()
        Case $hbtnOpen
            ShellExecute($URL)
            ;ConsoleWrite($URL & @CRLF)
    EndSwitch
WEnd

Func read_INI()
    $list1 = IniReadSection($sAppIni, "URLs")
    ConsoleWrite($list1 & @CRLF)
    if IsArray($list1) Then
        For $i = 1 To $list1[0][0]
            GUICtrlSetData($hcboProg, $list1[$i][0])
        Next
    EndIf
    _GUICtrlComboBox_InsertString ($hcboProg,$sElect,0)
    _GUICtrlComboBox_SetCurSel($hcboProg,0)
EndFunc   ;==>read_INI

Func show_Selection()
    If GUICtrlRead($hcboProg) = $sElect Then
        GUICtrlSetState($hbtnOpen, $GUI_DISABLE)
        GUICtrlSetData($hlblURL, "")
    Else
        GUICtrlSetState($hbtnOpen, $GUI_ENABLE)
        $Prog = GUICtrlRead($hcboProg)
        ConsoleWrite("ausgewählt: " & $Prog & @CRLF)
        $URL = IniRead($sAppIni, "URLs", $Prog, "")
        GUICtrlSetData($hlblURL, $URL)
    EndIf
EndFunc   ;==>show_Selection

in this example you can also change url's with editor while running and it takes effect. For programs which lock you can unlock with winapi-funcs, there are several example script in forum like:

 just search and test if they are runable with actual stable.

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