Path package usage in Go language

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Pathpackage mainimport ("FMT" "OS" "Path" "Path/filepath") func main () {//path operation Fmt.println ("Path action----------------- ") Fmt. Println (path. Base ("Http://www.baidu.com/file/aa.jpg"))//aa.jpgfmt.println (path. Clean ("c:\\file//abc///aa.jpg"))//c:\file/abc/aa.jpgfmt.println (OS. GETWD ())//d:\projects\gopath\source\demo\syntax\path <nil>fmt. Println (path. Dir ("Http://www.baidu.com/aa/aaa.jpg"))//http:/www.baidu.com/aafmt.println (path. Dir ("C:/a/b/c/d.txt"))//c:/a/b/cfmt. Println (path. Dir ("C:\\a/b.txt"))//c:\afmt. Println (path. EXT ("C:\\a/b.txt"))//.txtfmt. Println (path. Isabs ("C:/wind/aa/bb/b.txt"))//falsefmt. Println (path. Join ("C:", "AA", "BB", "Cc.txt"))//c:/aa/bb/cc.txtismatch, err: = path. Match ("c:/windows/*/", "c:/windows/system/") fmt. Println (IsMatch, err)//true <nil>fmt. Println (path. Split ("C:/windows/system/aaa.jpg"))//c:/windOws/system/aaa.jpg//filepath Operation Fmt.println ("filepath Operation-----------------") fmt. PRINTLN (filepath. Isabs ("C:\\wind\\aa\\bb\\b.txt"))//truefmt. PRINTLN (filepath.                                         Abs (".")) D:\Projects\GoPath\source\demo\syntax\path <nil>fmt. PRINTLN (filepath. Base ("C:\\aa\\baa.exe"))//baa.exefmt.println (filepath. Clean ("C:\\\\aa/c\\baa.exe"))//c:\aa\c\baa.exefmt.println (filepath. Clean ("Aa/c\\baa.exe"))//aa\c\baa.exefmt.println (filepath. Dir ("Aa/c\\baa.exe"))//aa\cfmt. PRINTLN (filepath. Evalsymlinks ("./path.exe"))//can be used to determine whether a file or folder exists. Path.exe <nil>fmt. PRINTLN (filepath. Ext ("./path.exe"))//.exefmt. PRINTLN (filepath. Fromslash ("C:\\windows\\aa//bb/cc//path.exe"))//replace \///C:\WINDOWS\AA\\BB\CC\\PATH.EXEFMT.PRINTLN in the path ( FilePath. Toslash ("C:\\windows\\aa/bb/cc/path.exe"))//Replace the path//with \ \  C:/WINDOWS/AA/BB/CC/PATH.EXEFMT.PRINTLN (filepath. VolumeName ("c:\\windows\\"))//Get the volume label//c:fmt. PRINTLN (filepath. Glob ("C:\\windows\\*.exe"))//Get all c:\\windows\\ directories under EXE file. Fmt. PRINTLN (filepath. Hasprefix ("C:\\aa\\bb", "c:\\"))//truefmt. PRINTLN (filepath. Isabs ("Http://www.baidu.com/aa.jpg"))//falsefmt. PRINTLN (filepath. Join ("A", "\\bb\\", "CC", "/D", "e\\", "Ff.txt"))//a\bb\cc\d\e\ff.txtfmt.println (filepath. Match ("c:/windows/*/", "c:/windows/system/"))//true <nil>fmt. PRINTLN (filepath.  Rel ("C:/windows", "c:/windows/system/"))//Gets the relative path to the path of the second parameter, relative to the previous path. System <nil>fmt. Println (String (filepath. Separator))//Windows returns \\FMT. PRINTLN (filepath. Split ("C:/windows/system/abc.exe"))//c:/windows/system/abc.exefmt.println (filepath. Splitlist ("C:/windows/system/abc.exe"))//[c:/windows/system/abc.exe]filepath. Walk (".. /.. /syntax ", Walkfunc)/* FiLe:.. /.. /syntax isdir:true size:0 File:.. \.. \syntax\painc isdir:true size:0 File:.. \.. \syntax\painc\main.go isdir:false size:813 File:.. \.. \syntax\painc\painc.exe isdir:false size:2498048 File:.. \.. \syntax\path isdir:true size:0 File:.. \.. \syntax\path\path.exe isdir:false size:2851328 File:.. \.. \syntax\path\path.go isdir:false size:3419*/}func walkfunc (path string, info OS. FileInfo, err Error) error {FMT. Println ("File:", Path, "Isdir:", info.) Isdir (), "Size:", info. Size ()) return nil}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.