duan19850312 2017-03-06 03:20
浏览 40

去获取目录名作为参数

Go obtain a directory name from the сyrillic as an argument

How to get the full path, not cut garbage. Example: The path as a program argument /home/spouk/spouk.download/torrent/Сергей Лукьяненко, Собрание сочинений/

I get in the trimmed version of the program, how to fix? /Home/spouk/spouk.download/torrent/Сергей

example simple code

package main

import (
    "flag"
    "fmt"
)

func main() {
    wordPtr := flag.String("path", "foo", "a string")
    flag.Parse()
    fmt.Printf("Flag: -path=`%v`
flag.Args: %v
", *wordPtr, flag.Args())
    fmt.Printf("Rune: %v
", []rune(*wordPtr))
}
  • 写回答

2条回答 默认 最新

  • duanfenhui5511 2017-03-06 04:19
    关注

    This is not a matter of the Go code but how you pass it into your program, try passing the path in double quotes "…"

    ./main -path="/home/spouk/spouk.download/torrent/Сергей Лукьяненко, Собрание сочинений/"
    > Flag: -path=`/home/spouk/spouk.download/torrent/Сергей Лукьяненко, Собрание сочинений/`
    > flag.Args: []
    > Rune: [47 104 111 109 101 47 115 112 111 117 107 47 115 112 111 117 107 46 100 111 119 110 108 111 97 100 47 116 111 114 114 101 110 116 47 1057 1077 1088 1075 1077 1081 32 1051 1091 1082 1100 1103 1085 1077 1085 1082 1086 44 32 1057 1086 1073 1088 1072 1085 1080 1077 32 1089 1086 1095 1080 1085 1077 1085 1080 1081 47]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?