Is there a difference 'app/**/*.html' and 'app/**/**/*.html' as a gulp.src file list? - node.js

My config file for gulp watch looks like this:
var files = [
'app/**/*.html',
'app/**/**/*.html',
'app/**/**/**/*.html'
];
I'm confused about the difference with ** and *
Could all of these be just one line if I use ** ?

The pattern is call "globbing". Gulp-watch uses the "node-glob" module for that:
https://github.com/isaacs/node-glob#glob-primer
* Matches 0 or more characters in a single path portion
** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.
So, in your case the three patterns are redundant, they would produce the same fileset.

To be short
** represents all Folder
*.js represents all File with .js extension
*.* represents all file with any extension
https://www.npmjs.com/package/glob#glob-primer

Related

glob for all folders within a folder except one named folder

I am writing my Karma conf based on
http://karma-runner.github.io/1.0/config/preprocessors.html
The key for the preprocessor is a glob string.
This works for all folders within the build folder:
build/**/!(*.spec|*.bundle|*.min).js
However, I don't want all folders. I wanted folder 1,2,4,5 NOT folder 3
Can I write that in a single string (as seems to be required by karma)?
Something like
build/(folder1|folder2|folder4|folder5)/!(*.spec|*.bundle|*.min).js
or even better
build/** but not folder 3/!(*.spec|*.bundle|*.min).js
This covers it
https://github.com/karma-runner/karma-coverage/issues/13
Quoting it
You can make this work using brace expansion. For #chevalric's case, the following pattern will do it:
src/*/{*.js,!(test)/**/*.js}
This expands to two patterns:
src/*/*.js # Match files in the module root
src/*/!(test)/**/*.js # Match files in all subfolders except test/
Also it later says ..
src/*/!(test)/**/*.js
worked
However, for me, I could not test that this worked for various reasons.

Vim: Can't set 'path' correctly to make 'gf' work

I'm trying to get gf working with paths that look like this:
foo/bar.js
The file is located here: /Users/dimal/dev/project/src/foo/bar.js
So I set my path like this:
set path+=/Users/dimal/dev/project/src
It seems like gf should find the file but it doesn't.
E447: Can't find file "foo/bar.js" in path
Why?
I've tried other variations:
/Users/dimal/dev/project/src/**
/Users/dimal/dev/project/src/**/*
gf commands searches for files in the paths include via :set path.
set path command accepts wildcards like *. (* means any character) So, if you wanted to include all files under subdirectories of a directory, you can give
:set path+=directory/**
For a depth of three levels under a directory, that is , to include files under any subdirectory of subdirectory of subdirectory of current directory, you can specify like directory/**3
Maximum depth allowed is 100.
A command like
:set path+=/Users/dimal/dev/project/src/**3
will allow you to search for file named bar.js in src/subdirectory/subdirectory/subdirectory as well, not just in src/.

What is file globbing?

I was just wondering what is file globbing? I have never heard of it before and I couldn't find a definition when I tried looking for it online.
Globbing is the * and ? and some other pattern matchers you may be familiar with.
Globbing interprets the standard wild card characters * and ?, character lists in square brackets, and certain other special characters (such as ^ for negating the sense of a match).
When the shell sees a glob, it will perform pathname expansion and replace the glob with matching filenames when it invokes the program.
For an example of the * operator, say you want to copy all files with a .jpg extension in the current directory to somewhere else:
cp *.jpg /some/other/location
Here *.jpg is a glob pattern that matches all files ending in .jpg in the current directory. It's equivalent to (and much easier than) listing the current directory and typing in each file you want manually:
$ ls
cat.jpg dog.jpg drawing.png recipes.txt zebra.jpg
$ cp cat.jpg dog.jpg zebra.jpg /some/other/location
Note that it may look similar, but it is not the same as Regular Expressions.
You can find more detailed information here and here

What does ** mean in a path?

ive been setting up Grunt for my web app to auto build it and im seeing paths like
/path/to/file/**/*.js
i understand what one wildcard means, but what does 2 in a row mean?
/path/to/file/**/*.js matches any number of directories between /path/to/file/ and /*.js. As opposed to /path/to/file/*/*.js, which matches a single directory between /path/to/file/ and /*.js.
this matchers called "glob pattern" they are widely used in shell script and in CLI tools like grunt or npm .they '**' means -- "Matches zero or more directories, but will never match the directories . and .. "
you can read more in the docs
glob pattern

Execute program on Files in subDirectory

I have following architecture of files in a directory.
Directory
/A/abc.xyz
/B/abc.xyz
/C/abc.xyz
/D/abc.xyz
/E/abc.xyz
I want to execute a program on acb.xyz in each SubDirectory. Save Output files in different directory i.e. Directory/processed with the name of SubDirectory appended in the name of output files.
Can it be written in following way? Need corrections.
for i in `ls "Directory/"`
do
program.pl $i/abc.xyz > processed/$i-abc.xyz
done
for dir in Directory/*; do
program.pl "$dir/abc.xyz" > "processed/${dir##*/}-abc.xyz"
done
The ${dir##*/} part strips the leading directory names from $dir, so Directory/A becomes just A. I added quotes to ensure directory names with whitespace don't cause issue (a good habit, even if you know there are no spaces).
As an alternative to the string munging you could simplify this if you first change directory:
cd Directory
for dir in *; do
program.pl "$dir/abc.xyz" > "processed/$dir-abc.xyz"
done

Resources