package main

import (
"fmt"
"os"
) func main() { //获得当前工作路径(当前工程根目录)
dir, err := os.Getwd()
fmt.Println(dir,err) //获得任意环境变量
pathValue := os.Getenv("Path")
//pathValue := os.Getenv("shit")//空字符串
fmt.Println(pathValue) //获得全部环境变量
environ := os.Environ()
fmt.Println(environ) //打印当前设备在网络中的主机名
name, err := os.Hostname()
fmt.Println(name,err) //获取当前用户的临时文件夹位置
temporaryDirectory := os.TempDir()
fmt.Println("劳资的临时文件夹是",temporaryDirectory) //在windows下,顺斜线“/”和反斜线“\”都是合法的路径分隔符,而在Linux下只认“/”
fmt.Println(os.IsPathSeparator('/'))
fmt.Println(os.IsPathSeparator('\\')) fileInfo, err := os.Stat("F:/BlockChain/code/W2/day2/新建文本文档.txt")
fmt.Println(fileInfo,err)
fmt.Println(fileInfo.IsDir())//false 该文件不是文件夹
fmt.Println(fileInfo.Name())//新建文本文档 (2).txt
fmt.Println(fileInfo.Size())//6 内容大小是6字节
fmt.Println(fileInfo.Mode())//-rw-rw-rw- 文件主人-主人同组用户-其他人的访问权限
fmt.Println(fileInfo.ModTime())//2018-12-25 08:53:58.54 +0800 CST 文件最后修改时间 }

输出:

F:\BlockChain\code <nil>
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\python3.5\python.exe;D:\python3.5\;D:\Git\cmd;D:\go\bin;;%GOPATH%\bin;D:\go\bin
[=::=::\ ALLUSERSPROFILE=C:\ProgramData APPDATA=C:\Users\Administrator\AppData\Roaming asl.log=Destination=file CommonProgramFiles=C:\Program Files\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files COMPUTERNAME=PC-20140101MYSM ComSpec=C:\Windows\system32\cmd.exe FP_NO_HOST_CHECK=NO GOPATH=F:\BlockChain\code\W1\day4\ourmath;D:\go GOROOT=D:\Go HOMEDRIVE=C: HOMEPATH=\Users\Administrator LOCALAPPDATA=C:\Users\Administrator\AppData\Local LOGONSERVER=\\PC-20140101MYSM NUMBER_OF_PROCESSORS=8 OS=Windows_NT Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\python3.5\python.exe;D:\python3.5\;D:\Git\cmd;D:\go\bin;;%GOPATH%\bin;D:\go\bin PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 94 Stepping 3, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=5e03 ProgramData=C:\ProgramData ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ PUBLIC=C:\Users\Public SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\Windows TEMP=C:\Users\ADMINI~1\AppData\Local\Temp TMP=C:\Users\ADMINI~1\AppData\Local\Temp USERDOMAIN=PC-20140101MYSM USERNAME=Administrator USERPROFILE=C:\Users\Administrator windir=C:\Windows windows_tracing_flags=3 windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log _DFX_INSTALL_UNSIGNED_DRIVER=1]
PC-20140101MYSM <nil>
劳资的临时文件夹是 C:\Users\ADMINI~1\AppData\Local\Temp
true
true
&{新建文本文档.txt 32 {108929552 30775863} {108929552 30775863} {108929552 30775863} 0 0 0 0 {0 0} F:/BlockChain/code/W2/day2/新建文本文档.txt 0 0 0 false} <nil>
false
新建文本文档.txt
0
-rw-rw-rw-
2019-11-13 23:28:40.0106 +0800 CST

  

最新文章

  1. useful commands for Kubernetes beginners
  2. background-position (转)
  3. getGLES1ExtensionString: Could not find GLES 1.x config!
  4. Android笔记——我的Android课的开始
  5. mysql中获取一天、一周、一月时间数据的各种sql语句写法
  6. Java多线程基础知识(三)
  7. [MSSQL2005]再看CTE
  8. MyBatis动态SQL使用,传入参数Map中的Key判断
  9. get 与 post
  10. dispatch_once单例初始化
  11. hud 1166 敌兵布阵
  12. nodemon
  13. 使用RDS不得不知的注意事项
  14. c++中类模版中的static数据成员的定义
  15. SQL Server 2008性能故障排查(三)——I/O
  16. windows系统如何安装运行filebeat
  17. 【lintcode17/18】Subset, SubsetII
  18. Echarts简单案例
  19. shell条件控制和循环结构
  20. 2018.12.30 bzoj3028: 食物(生成函数)

热门文章

  1. POJ1466 最大点权独立集
  2. Python小游戏 -- 猜数字
  3. Wordpress主题编辑器漏洞复现
  4. idea中修改代码大小设置
  5. 内存回收导致关键业务抖动案例分析-论云原生OS内存QoS保障
  6. PowerBI开发 第十九篇:基于Page创建Tooltip
  7. JVM垃圾回收的三种方式
  8. JavaWeb——MySQL约束
  9. centos 7.6 安装最新版docker 19.03
  10. SQLFlow的几种关系