Created
October 15, 2013 22:54
-
-
Save harshavardhana/6999923 to your computer and use it in GitHub Desktop.
Filewalk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"path/filepath" | |
"os" | |
"flag" | |
"fmt" | |
) | |
type fileattr struct { | |
fileinfo os.FileInfo | |
path string | |
} | |
var filelist []fileattr | |
func Append(slice []fileattr, data fileattr) []fileattr { | |
l := len(slice) | |
if data.path != "" { | |
newSlice := make([]fileattr, l+1) | |
copy(newSlice, slice) | |
slice = newSlice | |
slice[l] = data | |
} | |
return slice | |
} | |
func filevisit(path string, f os.FileInfo, _ error) error { | |
var attr fileattr | |
attr.path = path | |
attr.fileinfo = f | |
if (attr.fileinfo.IsDir()) { | |
return nil | |
} | |
filelist = Append(filelist, attr) | |
return nil | |
} | |
func main() { | |
flag.Parse() | |
dir := flag.Arg(0) | |
if flag.NArg() < 1 { | |
fmt.Printf("Please provide arguments in this fashion <dir_checksum>\n") | |
os.Exit(255) | |
} else if flag.NArg() > 1 { | |
fmt.Printf("Please provide arguments in this fashion <dir_checksum>\n") | |
os.Exit(255) | |
} | |
filepath.Walk(dir, filevisit) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice :)