<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Glob文件匹配 - 编程技术参考——模具行业从业者必备知识手册]]></title><description><![CDATA[<p dir="auto">&lt;h2&gt;Glob&lt;/h2&gt;</p>
<p dir="auto">&lt;p&gt;Match files using the patterns the shell uses, like stars and stuff.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;&lt;a href="<a href="https://travis-ci.org/isaacs/node-glob.svg?branch=master" rel="nofollow ugc">https://travis-ci.org/isaacs/node-glob.svg?branch=master</a>"&gt;&lt;img src="<a href="https://travis-ci.org/isaacs/node-glob/" rel="nofollow ugc">https://travis-ci.org/isaacs/node-glob/</a>" alt="Build Status&lt;/a&gt;"&gt; &lt;a href="upload://rI9ZRHFeoGWwXs1TM0XJgyaYoRT.svg"&gt;&lt;img src="<a href="https://ci.appveyor.com/project/isaacs/node-glob" rel="nofollow ugc">https://ci.appveyor.com/project/isaacs/node-glob</a>" alt="Build Status&lt;/a&gt;"&gt; &lt;a href="upload://aQCQy9EpPyhAHrZgN9XtHWdRf4c.svg"&gt;&lt;img src="<a href="https://coveralls.io/github/isaacs/node-glob?branch=master" rel="nofollow ugc">https://coveralls.io/github/isaacs/node-glob?branch=master</a>" alt="Coverage Status&lt;/a&gt;"&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;This is a glob implementation in JavaScript.  It uses the &lt;code&gt;minimatch&lt;/code&gt;&lt;/p&gt;<br />
&lt;p&gt;library to do its matching.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;!&lt;a href="logo/glob.png"&gt;a fun cartoon logo made of glob characters&lt;/a&gt;&lt;/p&gt;</p>
<p dir="auto">&lt;h3&gt;Usage&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Install with npm&lt;/p&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
npm i glob<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;pre&gt;&lt;code&gt;<br />
var glob = require("glob")</p>
<p dir="auto">// options is optional<br />
glob("<strong>/*.js", options, function (er, files) {<br />
// files is an array of filenames.<br />
// If the <code>nonull</code> option is set, and nothing<br />
// was found, then files is ["</strong>/*.js"]<br />
// er is an error object or null.<br />
})<br />
&lt;/code&gt;&lt;/pre&gt;</p>
<p dir="auto">&lt;h3&gt;Glob Primer&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;"Globs" are the patterns you type when you do stuff like &lt;code&gt;ls <em>.js&lt;/code&gt; on&lt;/p&gt;<br />
&lt;p&gt;the command line, or put &lt;code&gt;build/</em>&lt;/code&gt; in a &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;Before parsing the path part patterns, braced sections are expanded&lt;/p&gt;<br />
&lt;p&gt;into a set.  Braced sections start with &lt;code&gt;{&lt;/code&gt; and end with &lt;code&gt;}&lt;/code&gt;, with any&lt;/p&gt;<br />
&lt;p&gt;number of comma-delimited sections within.  Braced sections may contain&lt;/p&gt;<br />
&lt;p&gt;slash characters, so &lt;code&gt;a{/b/c,bcd}&lt;/code&gt; would expand into &lt;code&gt;a/b/c&lt;/code&gt; and &lt;code&gt;abcd&lt;/code&gt;.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;The following characters have special magic meaning when used in a&lt;/p&gt;<br />
&lt;p&gt;path portion:&lt;/p&gt;</p>
<p dir="auto">&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;<em>&lt;/code&gt; Matches 0 or more characters in a single path portion&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;?&lt;/code&gt; Matches 1 character&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;[...]&lt;/code&gt; Matches a range of characters, similar to a RegExp range.&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  If the first character of the range is &lt;code&gt;!&lt;/code&gt; or &lt;code&gt;^&lt;/code&gt; then it matches&lt;/p&gt;<br />
&lt;p&gt;  any character not in the range.&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;!(pattern|pattern|pattern)&lt;/code&gt; Matches anything that does not match&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  any of the patterns provided.&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;?(pattern|pattern|pattern)&lt;/code&gt; Matches zero or one occurrence of the&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  patterns provided.&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;+(pattern|pattern|pattern)&lt;/code&gt; Matches one or more occurrences of the&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  patterns provided.&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;</em>(a|b|c)&lt;/code&gt; Matches zero or more occurrences of the patterns provided&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;@(pattern|pat*|pat?erN)&lt;/code&gt; Matches exactly one of the patterns&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  provided&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;**&lt;/code&gt; If a "globstar" is alone in a path portion, then it matches&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;p&gt;  zero or more directories and subdirectories searching for matches.&lt;/p&gt;<br />
&lt;p&gt;  It does not crawl symlinked directories.&lt;/p&gt;</p>
<p dir="auto">&lt;h4&gt;Dots&lt;/h4&gt;</p>
<p dir="auto">&lt;p&gt;If a file or directory path portion has a &lt;code&gt;.&lt;/code&gt; as the first character,&lt;/p&gt;<br />
&lt;p&gt;then it will not match any glob pattern unless that pattern's&lt;/p&gt;<br />
&lt;p&gt;corresponding path part also has a &lt;code&gt;.&lt;/code&gt; as its first character.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;For example, the pattern &lt;code&gt;a/.*/c&lt;/code&gt; would match the file at &lt;code&gt;a/.b/c&lt;/code&gt;.&lt;/p&gt;<br />
&lt;p&gt;However the pattern &lt;code&gt;a/&lt;em&gt;/c&lt;/code&gt; would not, because &lt;code&gt;&lt;/em&gt;&lt;/code&gt; does not start with&lt;/p&gt;<br />
&lt;p&gt;a dot character.&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;You can make glob treat dots as normal characters by setting&lt;/p&gt;<br />
&lt;p&gt;&lt;code&gt;dot:true&lt;/code&gt; in the options.&lt;/p&gt;</p>
<p dir="auto">&lt;h4&gt;Basename Matching&lt;/h4&gt;</p>
<p dir="auto">&lt;p&gt;If you set &lt;code&gt;matchBase:true&lt;/code&gt; in the options, and the pattern has no&lt;/p&gt;<br />
&lt;p&gt;slashes in it, then it will seek for any file anywhere in the tree&lt;/p&gt;<br />
&lt;p&gt;with a matching basename.  For example, &lt;code&gt;*.js&lt;/code&gt; would match&lt;/p&gt;<br />
&lt;p&gt;&lt;code&gt;test/simple/basic.js&lt;/code&gt;.&lt;/p&gt;</p>
<p dir="auto">&lt;h4&gt;Empty Sets&lt;/h4&gt;</p>
<p dir="auto">&lt;p&gt;If no matching files are found, then an empty array is returned.  This&lt;/p&gt;<br />
&lt;p&gt;differs from the shell, where the pattern itself is returned.  For&lt;/p&gt;<br />
&lt;p&gt;example:&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;    $ echo a&lt;em&gt;s&lt;/em&gt;d<em>f&lt;/p&gt;<br />
&lt;p&gt;    a&lt;em&gt;s&lt;/em&gt;d</em>f&lt;/p&gt;</p>
<p dir="auto">&lt;p&gt;To get the bash-style behavior, set the &lt;code&gt;nonull:true&lt;/code&gt; in the options.&lt;/p&gt;</p>
<p dir="auto">&lt;h4&gt;See Also:&lt;/h4&gt;</p>
<p dir="auto">&lt;ul&gt;<br />
&lt;li&gt;&lt;code&gt;man sh&lt;/code&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;man bash&lt;/code&gt; (Search for "Pattern Matching")&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;man 3 fnmatch&lt;/code&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;code&gt;man 5 gitignore&lt;/code&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href="<a href="https://github.com/isaacs/minimatch" rel="nofollow ugc">https://github.com/isaacs/minimatch</a>"&gt;minimatch documentation&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;</p>
<p dir="auto">&lt;h3&gt;glob.hasMagic(pattern, [options])&lt;/h3&gt;</p>
<p dir="auto">&lt;p&gt;Returns &lt;code&gt;true&lt;/code&gt; if there are a&lt;/p&gt;</p>
<p dir="auto">&lt;hr&gt;<br />
&lt;p&gt;踩过坑的来评论区说说。&lt;/p&gt;</p>
]]></description><link>https://forum.mj7.cn/topic/7208/glob文件匹配-编程技术参考-模具行业从业者必备知识手册</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 09:34:49 GMT</lastBuildDate><atom:link href="https://forum.mj7.cn/topic/7208.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Apr 2026 21:57:23 GMT</pubDate><ttl>60</ttl></channel></rss>