gurkensaas
gurkensaas

Reputation: 903

Detecting file size in applescript

So I'm trying to alert myself if a certain file ever gets to big, but I didn't really find anything related to filesize on the internet. I know you could theoretically use a shell find command or something similar, but I don't really like using shell in combination with applescript.

set theSize to the size of "/Directory/to/my/File"
if theSize > 100000 then
    display notification "This file is really big, you should delete it."
end if

Upvotes: 0

Views: 926

Answers (1)

Robert Kniazidis
Robert Kniazidis

Reputation: 1878

You can ask the Finder, info for command (deprecated), AsObjC's FileManager for the size of some file:

tell application "Finder" to set theSize to size of ("/Directory/to/my/File" as POSIX file as alias)
-- set theSize to size of (info for "/Directory/to/my/File")

if theSize > 100000 then
    display notification "This file is really big, you should delete it."
end if

Upvotes: 1

Related Questions