Advertisement
tjone270

script for checking about high amount of local files

Feb 8th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set thePaths to {"path/to/scan/for/files1", "path/to/scan/for/files2/etc"}
  2. set theProgramName to "File Counter"
  3. set theProgramWarningMessageUponFindingFilesThatExceedUpperLimit to "Hey there, fellow student, I see there you have some dandy files knocking around your Desktop and stuff. I'm pretty sure I told you about that thing we have, ownCloud? Yeah, use that man!"
  4. set theMaxAmountOfFilesAndFolders to 1
  5.  
  6.  
  7. ----------------------------------------------------------------------------------
  8. ------------ DON'T EDIT THIS BELOW UNLESS YOU KNOW WHAT YOU'RE DOING -------------    -- Thomas Jones (08/02/16)
  9. ----------------------------------------------------------------------------------
  10.  
  11. set counter to 0
  12. set warn to false
  13. repeat (count thePaths) times
  14.     set counter to (counter + 1)
  15.     set thePath to item counter of thePaths as string
  16.     set theCount to (do shell script "ls -l \"" & thePath & "\" | wc -l | awk '{ print $1 }'") as integer
  17.     set theCount to (theCount - 1) # we do this to remove possible hidden files like Desktop_DF etc
  18.     if theCount is greater than theMaxAmountOfFilesAndFolders then
  19.         set warn to true
  20.     end if
  21. end repeat
  22.  
  23. if warn is true then
  24.     display alert theProgramName message theProgramWarningMessageUponFindingFilesThatExceedUpperLimit as warning
  25.     do shell script "date >> ~/.userWasWarnedAboutHighAmountOfLocalFiles"
  26. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement