move: empty files finder to root
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Print the directories
|
||||
//
|
||||
// Create a program that can get multiple directory paths from
|
||||
// the command-line, and prints only their subdirectories into a
|
||||
// file named: dirs.txt
|
||||
//
|
||||
//
|
||||
// 1. Get the directory paths from command-line
|
||||
//
|
||||
// 2. Append the names of subdirectories inside each directory
|
||||
// to a byte slice
|
||||
//
|
||||
// 3. Write that byte slice to dirs.txt file
|
||||
//
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
//
|
||||
// go run main.go
|
||||
// Please provide directory paths
|
||||
//
|
||||
// go run main.go dir/ dir2/
|
||||
//
|
||||
// cat dirs.txt
|
||||
//
|
||||
// dir/
|
||||
// subdir1/
|
||||
// subdir2/
|
||||
//
|
||||
// dir2/
|
||||
// subdir1/
|
||||
// subdir2/
|
||||
// subdir3/
|
||||
//
|
||||
//
|
||||
// HINTS
|
||||
//
|
||||
// ONLY READ THIS IF YOU GET STUCK
|
||||
//
|
||||
// + Get all the files in a directory using ioutil.ReadDir
|
||||
// (A directory is also a file)
|
||||
//
|
||||
// + You can use IsDir method of a FileInfo value to detect
|
||||
// whether a file is a directory or not: go doc os.FileInfo.IsDir
|
||||
//
|
||||
// + You can use '\t' escape sequence for indenting the subdirs.
|
||||
//
|
||||
// + You can find a sample directory structure under:
|
||||
// solution/ directory
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
}
|
4
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/.gitignore
vendored
Normal file
4
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*
|
||||
!subdir1
|
||||
!subdir2
|
||||
!.gitignore
|
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir1/.gitignore
vendored
Normal file
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir1/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir2/.gitignore
vendored
Normal file
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir/subdir2/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
5
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/.gitignore
vendored
Normal file
5
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
*
|
||||
!subdir1
|
||||
!subdir2
|
||||
!subdir3
|
||||
!.gitignore
|
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir1/.gitignore
vendored
Normal file
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir1/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir2/.gitignore
vendored
Normal file
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir2/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir3/.gitignore
vendored
Normal file
2
17-project-empty-file-finder/exercises/3-print-directories/solution/dir2/subdir3/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
@@ -0,0 +1,9 @@
|
||||
dir/
|
||||
subdir1/
|
||||
subdir2/
|
||||
|
||||
dir2/
|
||||
subdir1/
|
||||
subdir2/
|
||||
subdir3/
|
||||
|
@@ -0,0 +1,51 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
paths := os.Args[1:]
|
||||
if len(paths) == 0 {
|
||||
fmt.Println("Please provide directory paths")
|
||||
return
|
||||
}
|
||||
|
||||
var dirs []byte
|
||||
|
||||
for _, dir := range paths {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
dirs = append(dirs, dir...)
|
||||
dirs = append(dirs, '\n')
|
||||
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
dirs = append(dirs, '\t')
|
||||
dirs = append(dirs, file.Name()...)
|
||||
dirs = append(dirs, '/', '\n')
|
||||
}
|
||||
}
|
||||
|
||||
dirs = append(dirs, '\n')
|
||||
}
|
||||
|
||||
err := ioutil.WriteFile("dirs.txt", dirs, 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user