I am getting an error when I try to use the exec
package to run a mv
command.
Here is an example of what I am trying to do:
cmd := exec.Command("mv", "./source-dir/*", "./dest-dir")
output, err := cmd.CombinedOutput()
cmd.Run()
err returns the following
exit status 1
output returns this mv: rename ./source-dir/* to ./dest-dir/*: No such file or directory
I can actually get the script to work when I change this line:
cmd := exec.Command("mv", "./source-dir/*", "./dest-dir")
to the following:
cmd := exec.Command("mv", "./source-dir/file.txt", "./dest-dir")
The command works and moves the file successfully but using the wildcard doesn't work. It appears that the asterisk isn't being used as a wildcard in the command. Why is that? Is there another way to use wildcards in GO? If not then how else would I be able to recursively move all files from the source-dir
to the dest-dir
?
Thanks