Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

xDonThomas/tfc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tfc (Folder Cleaner)

tfc is a lightweight and flexible Go package that allows you to clean up and manage files and directories. It supports file and directory removal, creation, and cleanup operations based on access time.

Features

  • ✅ Remove a list of specific files or directories.
  • 🧹 Remove files based on last access time.
  • 📂 Create directories and files dynamically.
  • 📝 Create files with content.
  • 🧪 Fully configurable using functional options.

Installation

go get github.com/xxxAlvaDevxxx/tfc

Usage

package main

import (
	"log"
	"time"

	"github.com/xxxAlvaDevxxx/tfc"
)

func main() {
	err := tfc.Clean("example-dir",
		tfc.WithRemoveListFiles(true),
		tfc.WithFilesToRemove([]string{"temp.txt", "old.log"}),
		tfc.WithRemoveListDirs(true),
		tfc.WithDirsToRemove([]string{"cache", "tmp"}),
		tfc.WithRemoveFilesWithATimeFromADirectory(true),
		tfc.WithFilesWithATimeFromADirectory([]string{"session.txt"}),
		tfc.WithFilesWithATimeFromADirectoryDuration(48*time.Hour),
		tfc.WithCreateDir(true),
		tfc.WithDirToCreate("logs"),
		tfc.WithCreateFile(true),
		tfc.WithFileToCreate("logs/output.log"),
		tfc.WithCreateFileWithContent(true),
		tfc.WithFileToCreateWithContent("logs/info.txt"),
		tfc.WithFileContent("Folder cleaned successfully."),
	)
	if err != nil {
		log.Fatal(err)
	}
}

API Overview

Cleaning Functions

Clean(dir string, opts ...Option) error: Main function to clean and manage directory contents.

Options

Option Description
WithRemoveListFiles(bool) Enable or disable file removal.
WithFilesToRemove([]string) Specify list of files to remove.
WithRemoveListDirs(bool) Enable or disable directory removal.
WithDirsToRemove([]string) Specify list of directories to remove.
WithRemoveFilesWithATimeFromADirectory(bool) Enable time-based cleanup.
WithFilesWithATimeFromADirectory([]string) Files to be checked against duration.
WithFilesWithATimeFromADirectoryDuration(time.Duration) Threshold duration for cleanup.
WithCreateDir(bool) Enable directory creation.
WithDirToCreate(string) Directory path to create.
WithCreateFile(bool) Enable file creation.
WithFileToCreate(string) File path to create.
WithCreateFileWithContent(bool) Enable creation of file with content.
WithFileToCreateWithContent(string) File path for writing content.
WithFileContent(string) Content to write into file.

Utilities

  • ListFiles(dir string) ([]string, error): List files in a directory.
  • ListDirs(dir string) ([]string, error): List subdirectories in a directory.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages