#188511 - 2008-07-02 04:31 PM
detect empty text files
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
Hi everyone. Does anyone know of a UDF that will detect all empty text files in a given directory? By empty I mean absolutely no text inside the file.
Thanks.
|
|
Top
|
|
|
|
#188515 - 2008-07-02 04:46 PM
Re: detect empty text files
[Re: Gargoyle]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here is an example:
BREAK ON
$sDir="D:\TEMP"
$sFile=DIR($sDir) While $sFile If Not (16 & GetFileAttr($sDIR+"\"+$sFile)) If Not GetFileSize($sDir+"\"+$sFile) "File "+$sDir+"\"+$sFile+" is empty"+@CRLF EndIf EndIf $sFile=DIR() Loop
|
|
|
Top
|
|
|
|
#188516 - 2008-07-02 04:59 PM
Re: detect empty text files
[Re: Gargoyle]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
Gargoyle, the "empty" files were showing up as 1KB even though there appeared to be nothing in them. However, upon further review, there is one blank line in the file that's causing it to be greater than 0 bytes. If I delete that line, then it goes to 0 bytes.
The files are created using redirectoutput. I'll have to look into why it's putting a blank line in there. I think I have an idea.
Thanks for the response.
|
|
Top
|
|
|
|
#188519 - 2008-07-02 05:31 PM
Re: detect empty text files
[Re: booey]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you cannot get rid off the blank line from RedirectOutput() then you have a couple of choices
- Read each file and check if there are only blank lines
- Determine if there is a cutoff size below which you can assume that a file is empty. For example, if a file with data is never smaller than 20 bytes then you can assume that a file with less than 20 bytes is empty.
|
|
Top
|
|
|
|
#188520 - 2008-07-02 05:37 PM
Re: detect empty text files
[Re: Richard H.]
|
booey
Getting the hang of it
Registered: 2005-07-25
Posts: 76
Loc: USA
|
Thanks to all who responded.
I just used DirPlus and the file.size FSO to determine that a 3 byte file is empty with only a blank line.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1636 anonymous users online.
|
|
|