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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Benny-D
Posts: 302
Joined: 12 Mar 2014, 10:09

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

12 Aug 2019, 20:16

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)
Last edited by Benny-D on 14 Aug 2019, 00:35, edited 5 times in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

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

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
User avatar
Benny-D
Posts: 302
Joined: 12 Mar 2014, 10:09

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

12 Aug 2019, 22:46

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)
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

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

13 Aug 2019, 21:41

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.
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Marium0505, Nerafius and 189 guests