Page 1 of 1

[solved] How to find out if file is empty without opening it?

Posted: 12 Aug 2019, 20:16
by Benny-D
Is there any way in AHK to establish if the file is empty without reading or even opening it?


EDIT:
By "empty" I mean "containing no text".
By "text" I mean "any combination of non-white-space and white-space characters that is easily seen by a user with his own eyes (for example, by looking at the flashing cursor) when he opens the file by clicking its icon".
By "file" I mean only a .txt file.
By "reading a file" and "opening a file" I mean using AHK commands FileRead or FileOpen.
(just added these edits to my original post)

Re: How to find out if file is empty without opening it?

Posted: 12 Aug 2019, 21:11
by Xtra
0 byte size

Re: How to find out if file is empty without opening it?

Posted: 12 Aug 2019, 22:12
by swagfag
i think u would have to be a bit more precise with ur definitions of "empty", "reading" and "opening it"
an "empty" file saved as UTF8 with BOM still contains the 3 byte BOM, for instance
FileGetSize "opens" the file. as does, ultimately, any function, needing to perform operations on a file

Re: How to find out if file is empty without opening it?

Posted: 12 Aug 2019, 22:46
by Benny-D
swagfag wrote:
12 Aug 2019, 22:12
i think u would have to be a bit more precise with ur definitions of "empty", "reading" and "opening it"
an "empty" file saved as UTF8 with BOM still contains the 3 byte BOM, for instance
FileGetSize "opens" the file. as does, ultimately, any function, needing to perform operations on a file
- I see.

By "empty" I mean "containing no text".
By "text" I mean "any combination of non-white-space and white-space characters that is easily seen by a user with his own eyes (for example, by looking at the flashing cursor) when he opens the file by clicking its icon".
By "file" I mean only a .txt file.
By "reading a file" and "opening a file" I mean using AHK commands FileRead or FileOpen.

(just added these edits to my original post)

Re: How to find out if file is empty without opening it?  Topic is solved

Posted: 13 Aug 2019, 21:41
by flyingDman
I use the following to delete 0 byte sized files:

Code: Select all

loop, %path%\*.*
	if A_LoopFileSize = 0
		{
		filedelete %A_LoopFileFullPath% 
		list .= A_LoopFileFullPath "`n"
		count++
		}
if !count
	count = no
msgbox %count% deleted file(s)`n%list%		
Comes in handy once in a while.