/FunctionsFile.ahk

http://pokershortcuts.googlecode.com/ · AutoHotKey · 98 lines · 58 code · 20 blank · 20 comment · 7 complexity · eca0971bddbfdfd43e556d02df852fe1 MD5 · raw file

  1. ;Tail function by Laszlo of the AutoHotkey forums
  2. FileTail(k,file) ; Return the last k lines of file
  3. {
  4. Loop Read, %file%
  5. {
  6. i := Mod(A_Index,k)
  7. L%i% = %A_LoopReadLine%
  8. }
  9. L := L%i%
  10. Loop % k-1
  11. {
  12. IfLess i,1, SetEnv i,%k%
  13. i-- ; Mod does not work here
  14. L := L%i% "`n" L
  15. }
  16. Return L
  17. }
  18. ; return the full path of a file matching: filename in directory with this suffix
  19. ; if suffix isn't given, then use * for suffix
  20. ; id directory is not given, then use a_workingDir
  21. ; from Roland functions
  22. FileSearch(filename, directory="", suffix="*")
  23. {
  24. directory := directory!="" ? directory : a_workingDir
  25. Loop %directory%\*.%suffix%
  26. { if InStr(a_loopFileName, filename)
  27. return directory "\" a_loopFileName
  28. }
  29. }
  30. ; search for files in directory containing Criteria1 but not Exclusion
  31. ; ALSO find the matching file with the LATEST timemmodified date
  32. FileSearchOneCriteriaLatestDate(Criteria1, Exclusion, directory="", suffix="*")
  33. {
  34. ;outputdebug, filesearch2criteria Criteria1:%Criteria1% Criteria2:%Criteria2% Exclusion:%Exclusion% directory:%directory% suffix:%suffix%
  35. directory := directory!="" ? directory : a_workingDir
  36. filetime := 0
  37. filename := ""
  38. ; loop thru all the files in this directory with this suffix
  39. Loop %directory%\*.%suffix%
  40. {
  41. ; check if our two criteria are in the file name
  42. if InStr(a_loopFileName, Criteria1)
  43. {
  44. ; if the exclusion is included, then make sure that it is not there
  45. if (Exclusion and instr(a_loopFileName, Exclusion))
  46. continue
  47. ; see if this filename is LATER than the previous one that we found
  48. if (A_LoopFileTimeModified > filetime)
  49. {
  50. filename := a_loopFileName
  51. filetime := A_LoopFileTimeModified
  52. }
  53. }
  54. }
  55. if filename
  56. return directory "\" filename
  57. }
  58. ; return the full path of a file matching: filename in directory with this suffix
  59. ; if suffix isn't given, then use * for suffix
  60. ; id directory is not given, then use a_workingDir
  61. ; from Roland functions
  62. FileSearchTwoCriteria(Criteria1, Criteria2, Exclusion, directory="", suffix="*")
  63. {
  64. ;outputdebug, filesearch2criteria Criteria1:%Criteria1% Criteria2:%Criteria2% Exclusion:%Exclusion% directory:%directory% suffix:%suffix%
  65. directory := directory!="" ? directory : a_workingDir
  66. ; loop thru all the files in this directory with this suffix
  67. Loop %directory%\*.%suffix%
  68. {
  69. ; check if our two criteria are in the file name
  70. if (InStr(a_loopFileName, Criteria1) AND InStr(a_loopFileName, Criteria2))
  71. {
  72. ; if the exclusion is included, then make sure that it is not there
  73. if (Exclusion and instr(a_loopFileName, Exclusion))
  74. continue
  75. return directory "\" a_loopFileName
  76. }
  77. }
  78. }