change count/ to getFileCount, initial write
This commit is contained in:
parent
016b68e8c3
commit
ef120ac755
|
@ -0,0 +1 @@
|
|||
1
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env fish
|
||||
# $argv[1] = directory you want to scan
|
||||
# $argv[2] = minimum amount of files you want to keep
|
||||
|
||||
set files (count (./golf $argv[1]))
|
||||
|
||||
if test $files -gt $argv[2]
|
||||
set fileList (./golf $argv[1])
|
||||
set oldestDate (stat -c %W "$argv[1]/$fileList[1]")
|
||||
set fileIndex = 1
|
||||
|
||||
for i in (seq $files)
|
||||
set dateCreated (stat -c %W "$argv[1]/$fileList[$i]")
|
||||
if test $dateCreated -gt $oldestDate
|
||||
set oldestDate $dateCreated
|
||||
set fileIndex $i
|
||||
end
|
||||
end
|
||||
|
||||
rm "$argv[1]/$fileList[$fileIndex]"
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
files = number of files in arg[1] # likely going to be named sql-backup
|
||||
|
||||
if files > arg[2] # specified number of files to keep
|
||||
|
||||
fileList = array of files in arg[1]
|
||||
oldestDate = fileList[1] date created # doesn't matter which file
|
||||
fileIndex = 1 # or 0 but fish just uses index 1 for the beginning of an array
|
||||
|
||||
for i = 1; i > files; i++
|
||||
|
||||
dateCreated = fileList[i] date created
|
||||
if oldestDate < dateCreated
|
||||
oldestDate = dateCreated
|
||||
fileIndex = i
|
||||
end
|
||||
end
|
||||
|
||||
delete fileList[fileIndex]
|
||||
end
|
Binary file not shown.
Loading…
Reference in New Issue