Please,why the result of go build\go run is different

package main

import (
   "fmt"
   "time"
   "strconv"
   "syscall"
   "io/ioutil"
)

func del_old7days(){
	currentTime := time.Now()
	oldTime := currentTime.AddDate(0, 0, -2)	
	timestr := oldTime.Format("2006-01-02/15:04:05")
	fmt.Println(timestr)
}
func GetLogicalDrives() []string {
    kernel32 := syscall.MustLoadDLL("kernel32.dll")
    GetLogicalDrives := kernel32.MustFindProc("GetLogicalDrives")
    n, _, _ := GetLogicalDrives.Call()
    s := strconv.FormatInt(int64(n), 2)
 
    var drives_all = []string{"A:", "B:", "C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", "N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:"}
    temp := drives_all[0:len(s)]
 
    var d []string
    for i, v := range s {
 
        if v == 49 {
            l := len(s) - i - 1
            d = append(d, temp[l])
        }
    }
    var drives []string
    for i, v := range d {
        drives = append(drives[i:], append([]string{v}, drives[:i]...)...)
    }
    return drives
 
}
func all_disk_path(path string){
	files,_:= ioutil.ReadDir(path)
	for _, file := range files {	
       if file.IsDir() {   	
		all_disk_path(path+"/"+file.Name())
	   } else {
	     fmt.Println(path+"/"+file.Name())
		 time.Sleep(time.Second)
	   }
	}
}
func main(){
	data :=GetLogicalDrives()
 	for _,value :=range data{
	
		all_disk_path(value)
	}
}

image

Where these q3q files come from? Is this some mallware?

it’s seem that some files was hidden

Put your go code between two lines one is ```go and the other is ```(backticks) so will it be formatted as go code in the post. Much easier for others to read

thank you very much

1 Like

Hi

C: is not the path of the root of the C: drive. C:\ is so asking for all files in C: with io.ReadDir will just return the files in the current directory (at least it does for me)

Joining paths should use filepath.Join() so you get the correct separator / on linux, macos and \ on windows.

Hope this helps.

thank you, C:/ is right