Skip to content

yogisinha/files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

files

Small package to find files older than a specific time

Example program using this package

package main

import (
	"archive/zip"
	"fmt"
	"log"
	"os"

	"github.com/yogisinha/filesfinder"
)

func main() {

	path := "/path/to/some/folder"
	fs := os.DirFS(path)
	f, _ := filesfinder.New(
		fs, // first argument is fs.FS type

		/* second is the list of time options letting the user specify the time
		as a combination of years, months, days, hours and minutes */
		filesfinder.WithDays(10),
		filesfinder.WithHours(5),
	)
	// above example will find files older than 10 days, 5 hrs.
	results, err := f.OlderThan()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	for _, res := range results {
		fmt.Printf("%s		%s\n", res.Path, res.ModTime)
	}
	fmt.Println("Erros:")
	for _, res := range results {
		if res.Error != nil {
			fmt.Printf("%s\n", res.Error)
		}
	}

	// Also zip file path can be used.
	path = "/path/to/some/zipfile.zip"
	zr, err := zip.OpenReader(path)
	defer zr.Close()
	if err != nil {
		log.Fatal("Error : ", err)
	}
	f, _ = filesfinder.New(
		zr,
		filesfinder.WithDays(10),
	)
	results, err = f.OlderThan()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	for _, res := range results {
		fmt.Printf("%s		%s\n", res.Path, res.ModTime)
	}

}

cmd/main.go provides a CLI to find the older files

To find the files older than 10 days, 5 hrs

$ go run cmd/main.go -h  // for cmd line switches help
$ go run cmd/main.go -d=10 -h=5 /path/to/folder

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages