Giter VIP home page Giter VIP logo

fileman's Introduction

Fileman

Build Status codecov GoDoc Go Report Card

Fileman is a go package that provides handy functions for files, directories, and symbolic links.

Current Functionality

  • Copy
  • Paste
  • Delete
  • Cut
  • Move
  • Rename
  • Search
  • Duplicate
  • Get Type

Installation

go get -u github.com/Hermitter/fileman

Usage

Copy & Paste
// Copy: returns a struct that allows you to edit/view the name & contents of an item
copiedDir, err := fileman.CopyDir("/home/john/Desktop/someDirectory")
if err != nil {
  return err
}

copiedFile, err := fileman.CopyFile("/home/john/Desktop/someFile.txt")
if err != nil {
  return err
}

copiedSymLink, err := fileman.CopySymLink("/home/john/Desktop/someSymLink.txt")
if err != nil {
  return err
}

// Paste: will not overwrite existing items
// the names of the pasted items are copiedDir.Name, copiedFile.Name, copiedSymLink.Name
if err := copiedDir.Paste("/home/john/documents", false); err != nil {
  return err
}

if err := copiedFile.Paste("/home/john/documents", false); err != nil {
  return err
}

if err := copiedSymLink.Paste("/home/john/documents"); err != nil {
  return err
}
Rename, Move & Delete
// Rename
err := fileman.Rename("./old.txt", "new.txt")
if err != nil {
  fmt.Println(err)
  return
}

// Move
err = fileman.Move("./new.txt", "/home/john/documents")
if err != nil {
fmt.Println(err)
  return
}

// Delete
err = fileman.Delete("/home/john/documents/new.txt")
if err != nil {
  fmt.Println(err)
  return
}
Search
found, path := fileman.Search("needle.txt", "/home/john/haystack", 1)
if !found {
  fmt.Println("Search Failed!")
  return
}

fmt.Println("Found it here: " + path)
Duplicate
// The last part of the destination path will be the new name of the pasted item.
err := fileman.Duplicate("/home/john/media", "/home/john/backups/media", false)

if err != nil {
  return err
}
Get Type
// Boolean value determines if "symLink" should be included as a result.
itemType, err := fileman.GetType("/home/john/media", false)

if err != nil {
  fmt.Println(err)
  return
}

fmt.Println(itemType)// Can print "dir" or "file"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.