change count/ to getFileCount, initial write

This commit is contained in:
oct2pus 2024-04-09 23:00:40 -05:00
parent 016b68e8c3
commit ef120ac755
9 changed files with 41 additions and 0 deletions

0
checkFileCount/5 Normal file
View File

1
checkFileCount/arg[2] Normal file
View File

@ -0,0 +1 @@
1

View File

@ -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

View File

@ -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

BIN
checkFileCount/golf Executable file

Binary file not shown.

0
checkFileCount/test/1 Normal file
View File

0
checkFileCount/test/2 Normal file
View File

0
checkFileCount/test/3 Normal file
View File

0
checkFileCount/test/4 Normal file
View File