copy

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Example (CopyDir)
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"

	"github.com/shiyou0130011/io/copy"
)

func main() {
	sourceFolder, err := ioutil.TempDir(os.TempDir(), "source-*")
	if err != nil {
		log.Println("Cannot create source folder")
	}
	defer os.RemoveAll(sourceFolder)
	targetFolder, err := ioutil.TempDir(os.TempDir(), "target-*")
	if err != nil {
		log.Fatal("Cannot create target folder")
	}
	defer os.RemoveAll(targetFolder)

	ioutil.WriteFile(filepath.Join(sourceFolder, "foo.txt"), []byte("Foo"), 0644)
	ioutil.WriteFile(filepath.Join(sourceFolder, "bar.txt"), []byte("Foo"), 0644)

	err = copy.Dir(sourceFolder, targetFolder)
	if err != nil {
		log.Fatal(err)
	}
	files, err := os.ReadDir(targetFolder)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Target folder has %d files", len(files))

}
Output:
Target folder has 2 files

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(sourceFolder string, outputFolder string) error

Dir is for Copying the source folder to output folder

It will return error when one of sub-file or sub-folder cannot be copied

func FS

func FS(f fs.ReadFileFS, path string, outputFolderPath string)

FS is for copying the file (path is the FS's path) to outputFolderPath It can be copy folder or file

func File

func File(sourceFolderPath string, outputFolderPath string, relativeFilePath string) error

File is for copying the file from sourceFolderPath to outputFolderPath

It will return error when the file cannot be copied

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL