io + os)Python’s shutil maps to os.Rename, io.Copy, and helpers like os.ReadFile/WriteFile.
src, err := os.Open("in.txt")
if err != nil {
return err
}
defer src.Close()
dst, err := os.Create("out.txt")
if err != nil {
return err
}
defer dst.Close()
if _, err := io.Copy(dst, src); err != nil {
return err
}
return dst.Sync()
There is no single stdlib call; copy bytes then os.Chtimes, os.Chmod as needed. For full fidelity across platforms, third-party packages exist.
err := os.Rename("a", "b")
Cross-device renames may fail — fall back to copy+delete.
err := os.RemoveAll("dir")
Walk with filepath.WalkDir (or fs.WalkDir) and sum os.DirEntry / FileInfo sizes.
archive/zip and archive/tar for packing, not shutil.make_archive one-liner — but straightforward.