topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 8, 2024, 5:42 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AHK Script to create and delete a file until it is closed  (Read 6978 times)

Zero3K

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 300
    • View Profile
    • Donate to Member
AHK Script to create and delete a file until it is closed
« on: August 07, 2019, 06:45 PM »
It would be nice if someone could make one that fills a file (in the root directory) with the word Dummy and deletes it then repeats the process until it is closed.

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: AHK Script to create and delete a file until it is closed
« Reply #1 on: August 08, 2019, 02:31 AM »
#NoEnv
#SingleInstance force
SetWorkingDir %A_ScriptDir%
FileEncoding UTF-8
SetBatchLines, -1

drive := "C:\"
file  := "Dummy.txt"
path  := drive . file
text  := "Dummy"


if FileExist(drive) {
    Loop {
        if FileExist(path)
            FileDelete, % path
        FileAppend, % text, % path
    }
}

Zero3K

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 300
    • View Profile
    • Donate to Member
Re: AHK Script to create and delete a file until it is closed
« Reply #2 on: August 08, 2019, 02:39 PM »
Thanks. And would removing the delete line from it make it overwrite the file after it is made or already exists?

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: AHK Script to create and delete a file until it is closed
« Reply #3 on: August 08, 2019, 03:36 PM »
Nope

Zero3K

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 300
    • View Profile
    • Donate to Member
Re: AHK Script to create and delete a file until it is closed
« Reply #4 on: August 10, 2019, 10:32 AM »
Can you please make one that overwrites the file that is made?

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: AHK Script to create and delete a file until it is closed
« Reply #5 on: August 11, 2019, 09:42 AM »
#NoEnv
#SingleInstance force
SetWorkingDir %A_ScriptDir%
FileEncoding UTF-8
SetBatchLines, -1

drive := "C:\"
file  := "Dummy.txt"
path  := drive . file
text  := "Dummy"


if FileExist(drive) {
    Loop {
        EmptyFile(path)
        FileAppend, % text, % path
    }
}

EmptyFile(file) {
    hFile := DllCall("CreateFile", Str, file, UInt, 0x40000000, UInt, 3, UInt, 0, UInt, 5, UInt, 0, UInt, 0)
    DllCall("CloseHandle", UInt, hFile)
    return hFile > 0 ? 1 : hFile
}

But ofc this empties the file before it gets overwritten...

OpenFile() would impose too many problems (no unicode, no > 128 file path length...)