-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile.ahk
50 lines (47 loc) · 1.45 KB
/
File.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Extended library for File
(c) 2022-2024 Ken Verdadero
2022-06-10
*/
/**
* Similar to FileAppend but handles deletion of the existing file.
*
* @param content the content to be written to the file
* @param filename the file to be written to
* @param {Integer} append True if the content should be appended to the file, False if the file should be overwritten
* @param {String} options
* @param {Integer} ignoreErrors True if the function should ignore errors, False if the function should throw an error
* @param {String} encoding The encoding to be used when writing to the file
*/
FileWrite(content, filename, append := false, options := '', ignoreErrors := false, encoding := "") {
if FileExist(filename) && !append {
try {
file := FileOpen(filename, "w", encoding)
file.write("")
file.close()
} catch Error {
if !ignoreErrors {
throw Error("File access is denied.")
}
}
}
try FileAppend(content, filename, options)
catch Error {
if !ignoreErrors {
throw Error("Cannot save the file")
}
}
return filename
}
/**
* Transfer the contents of a file without deleting the file.
* @param source the source file
* @param dest the destination file
*/
FileTransfer(source, dest) {
src := FileOpen(source, "r")
dst := FileOpen(dest, "w")
dst.Write(src.Read())
src.Close()
dst.Close()
}