模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    Glob文件匹配 - 编程技术参考——模具行业从业者必备知识手册

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>Glob</h2>

      <p>Match files using the patterns the shell uses, like stars and stuff.</p>

      <p><a href="https://travis-ci.org/isaacs/node-glob.svg?branch=master"><img src="https://travis-ci.org/isaacs/node-glob/" alt="Build Status</a>"> <a href="upload://rI9ZRHFeoGWwXs1TM0XJgyaYoRT.svg"><img src="https://ci.appveyor.com/project/isaacs/node-glob" alt="Build Status</a>"> <a href="upload://aQCQy9EpPyhAHrZgN9XtHWdRf4c.svg"><img src="https://coveralls.io/github/isaacs/node-glob?branch=master" alt="Coverage Status</a>"></p>

      <p>This is a glob implementation in JavaScript. It uses the <code>minimatch</code></p>
      <p>library to do its matching.</p>

      <p>!<a href="logo/glob.png">a fun cartoon logo made of glob characters</a></p>

      <h3>Usage</h3>

      <p>Install with npm</p>

      <pre><code>
      npm i glob
      </code></pre>

      <pre><code>
      var glob = require("glob")

      // options is optional
      glob("/*.js", options, function (er, files) {
      // files is an array of filenames.
      // If the nonull option is set, and nothing
      // was found, then files is ["
      /*.js"]
      // er is an error object or null.
      })
      </code></pre>

      <h3>Glob Primer</h3>

      <p>"Globs" are the patterns you type when you do stuff like <code>ls .js</code> on</p>
      <p>the command line, or put <code>build/
      </code> in a <code>.gitignore</code> file.</p>

      <p>Before parsing the path part patterns, braced sections are expanded</p>
      <p>into a set. Braced sections start with <code>{</code> and end with <code>}</code>, with any</p>
      <p>number of comma-delimited sections within. Braced sections may contain</p>
      <p>slash characters, so <code>a{/b/c,bcd}</code> would expand into <code>a/b/c</code> and <code>abcd</code>.</p>

      <p>The following characters have special magic meaning when used in a</p>
      <p>path portion:</p>

      <ul>
      <li><code></code> Matches 0 or more characters in a single path portion</li>
      <li><code>?</code> Matches 1 character</li>
      <li><code>[...]</code> Matches a range of characters, similar to a RegExp range.</li>
      </ul>
      <p> If the first character of the range is <code>!</code> or <code>^</code> then it matches</p>
      <p> any character not in the range.</p>
      <ul>
      <li><code>!(pattern|pattern|pattern)</code> Matches anything that does not match</li>
      </ul>
      <p> any of the patterns provided.</p>
      <ul>
      <li><code>?(pattern|pattern|pattern)</code> Matches zero or one occurrence of the</li>
      </ul>
      <p> patterns provided.</p>
      <ul>
      <li><code>+(pattern|pattern|pattern)</code> Matches one or more occurrences of the</li>
      </ul>
      <p> patterns provided.</p>
      <ul>
      <li><code>
      (a|b|c)</code> Matches zero or more occurrences of the patterns provided</li>
      <li><code>@(pattern|pat*|pat?erN)</code> Matches exactly one of the patterns</li>
      </ul>
      <p> provided</p>
      <ul>
      <li><code>**</code> If a "globstar" is alone in a path portion, then it matches</li>
      </ul>
      <p> zero or more directories and subdirectories searching for matches.</p>
      <p> It does not crawl symlinked directories.</p>

      <h4>Dots</h4>

      <p>If a file or directory path portion has a <code>.</code> as the first character,</p>
      <p>then it will not match any glob pattern unless that pattern's</p>
      <p>corresponding path part also has a <code>.</code> as its first character.</p>

      <p>For example, the pattern <code>a/.*/c</code> would match the file at <code>a/.b/c</code>.</p>
      <p>However the pattern <code>a/<em>/c</code> would not, because <code></em></code> does not start with</p>
      <p>a dot character.</p>

      <p>You can make glob treat dots as normal characters by setting</p>
      <p><code>dot:true</code> in the options.</p>

      <h4>Basename Matching</h4>

      <p>If you set <code>matchBase:true</code> in the options, and the pattern has no</p>
      <p>slashes in it, then it will seek for any file anywhere in the tree</p>
      <p>with a matching basename. For example, <code>*.js</code> would match</p>
      <p><code>test/simple/basic.js</code>.</p>

      <h4>Empty Sets</h4>

      <p>If no matching files are found, then an empty array is returned. This</p>
      <p>differs from the shell, where the pattern itself is returned. For</p>
      <p>example:</p>

      <p> $ echo a<em>s</em>df</p>
      <p> a<em>s</em>d
      f</p>

      <p>To get the bash-style behavior, set the <code>nonull:true</code> in the options.</p>

      <h4>See Also:</h4>

      <ul>
      <li><code>man sh</code></li>
      <li><code>man bash</code> (Search for "Pattern Matching")</li>
      <li><code>man 3 fnmatch</code></li>
      <li><code>man 5 gitignore</code></li>
      <li><a href="https://github.com/isaacs/minimatch">minimatch documentation</a></li>
      </ul>

      <h3>glob.hasMagic(pattern, [options])</h3>

      <p>Returns <code>true</code> if there are a</p>

      <hr>
      <p>踩过坑的来评论区说说。</p>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors