glob

Why does glob lstat matching entries?

与世无争的帅哥 提交于 2019-12-04 04:10:01
Looking into behavior in this question , I was surprised to see that perl lstat() s every path matching a glob pattern: $ mkdir dir $ touch dir/{foo,bar,baz}.txt $ strace -e trace=lstat perl -E 'say $^V; <dir/b*>' v5.10.1 lstat("dir/baz.txt", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0 lstat("dir/bar.txt", {st_mode=S_IFREG|0664, st_size=0, ...}) = 0 I see the same behavior on my Linux system with glob(pattern) and <pattern> , and with later versions of perl. My expectation was that the globbing would simply opendir/readdir under the hood, and that it would not need to inspect the actual

Globbing using braces on Ruby 1.9.3

烂漫一生 提交于 2019-12-04 03:22:06
Recent versions of Ruby support the use of braces in globbing, if you use the File::FNM_EXTGLOB option From the 2.2.0 documentation File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB However, the 1.9.3 documentation says it isn't supported in 1.9.3: File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported (also, trying to use File::FNM_EXTGLOB gave a name error) Is there any way to glob using braces in Ruby 1.9.3, such as a third-party gem? The strings I want to match against are from S3, not a local file system, so I can't just ask the

Bash: Expand braces and globs with spaces in filenames?

大兔子大兔子 提交于 2019-12-04 03:08:25
问题 I have some files that look like: /path/with spaces/{a,b,c}/*.gz And I need all files matching the glob under a subset of the a,b,c dirs to end up as arguments to a single command: mycmd '/path/with spaces/a/1.gz' '/path/with spaces/a/2.gz' '/path/with spaces/c/3.gz' ... The directories I care about come in as command line params and I have them in an array: dirs=( "$@" ) And I want to do something like: IFS=, mycmd "/path/with spaces/{${dirs[*]}}/"*.gz but this doesn't work, because bash

How to match nothing if a file name glob has no matches [duplicate]

痴心易碎 提交于 2019-12-04 01:05:09
This question already has answers here : Closed 5 months ago . How to skip the for loop when there are no matching files? (2 answers) I want to loop over all files matching extension jpg or txt . I use: for file in myDir/*.{jpg,txt} do echo "$file" done Problem: If the directory contains no jpg file at all, the loop will have one iteration with output myDir/*.jpg . I thought * will be replaced by an arbitrary file (and if no file exists it cannot be expanded). How can I avoid the unwanted iteration? Use this to avoid the unwanted iteration: shopt -s nullglob From man bash : nullglob : If set,

Ruby list directory with Dir['*'] including dotfiles but not . and

…衆ロ難τιáo~ 提交于 2019-12-03 23:35:57
How do I get Dir['*'] to include dotfiles, e.g., .gitignore , but not . and .. ? I.e., is there a better way to do: `ls -A`.split "\n" perhaps with Dir ? The following solutions are close but both include . & .. : Dir.glob('*', File::FNM_DOTMATCH) Dir['{.*,*}'] So, the following works: Dir.glob('*', File::FNM_DOTMATCH) - ['.', '..'] But, is there still a better way to do this? I'm wondering this to fix line 9 of a Meteor Homebrew Formula . You can't with Dir[] , but you can with Dir.glob , which Dir[] calls: Dir.glob("*", File::FNM_DOTMATCH) You can get rid of the . & .. easily: Dir.glob("*",

Glob /* doesn't match files starting with dot

非 Y 不嫁゛ 提交于 2019-12-03 15:16:38
问题 I'm using gulp to copy all files from one dir to another using code like this: gulp.src([ 'app/**/*' ]).pipe(gulp.dest('dist')); Glob docs say * match all files, but in fact files which have names starting with dot, like .gitignore , are not copied. How can it be worked around? 回答1: If you add the option dot: true , it should work. Eg: gulp.task('something', function () { return gulp.src([ 'app/**/*' ], { dot: true }).pipe(gulp.dest('dist')); }); Reference 来源: https://stackoverflow.com

PHP glob() in bracketed directories

前提是你 提交于 2019-12-03 14:43:45
On a Windows machine, the following script: <?php mkdir("c:\\[test]"); file_put_contents("c:\\[test]\\test.txt", "some content"); chdir("c:\\[test]"); echo getcwd()."\n"; var_dump(glob('*')); ?> Displays this: C:\[test] array(0) { } When this is expected: C:\[test] array(1) { [0]=> string(8) "test.txt" } I understand that glob treats brackets as special characters, when found in the pattern parameter. The pattern * matches any file in the current working directory. However, glob() behaves as though it was run with the pattern c:\\[test]\\* The brackets are then being interpreted as part of the

RegEx pattern in glob function

心不动则不痛 提交于 2019-12-03 13:32:41
I recive a filename in a function. I want to return all files similar to this file (by filename) from other directory. I wrote this: $thumbDir = $this->files_path.'thumbs/'; $toglob = $thumbDir.pathinfo($name, PATHINFO_FILENAME ).'_[0-9]+\x[0-9]+_thb.'.pathinfo($name, PATHINFO_EXTENSION); foreach (glob($toglob) as $key => $value) { echo $value; } But it doesn't work. I search files which their filename is: oldFileName_[one or more digits]x[one or more digits]_thb.oldFileNameExtension I will be very grateful if someone help me with this :) Sam glob() is really a quasi-regex engine. From a

How to make mercurial ignore all hidden files?

那年仲夏 提交于 2019-12-03 12:03:25
问题 I hate seeing nearly every directory in my repository list each file twice, once with a dot in front of it and once without. I tried adding .* to my .hgignore file, but it has no effect. Is this the wrong syntax, and more importantly, is it a bad idea to try this in the first place? Thanks. 回答1: You've got almost the right answer in the comments from gavinb, but the match was a little to broad. However, key concept about ignoring after the face was provided by RogerPage, again in a comment

Why zsh tries to expand * and bash does not?

a 夏天 提交于 2019-12-03 11:30:45
I just encountered the following error with zsh when trying to use logcat. Namely, when typing: adb logcat *:D I get the following error in zsh zsh: no matches found: *:D I have to escape the * like : adb logcat \*:D While using bash, I do not get the following error. Why would it be like this? zsh warns you by default if you use a glob with no matches. Bash, on the other hand, passes the unexpanded glob to the app, which is a potential problem if you don't know for certain what will match (or if you make a mistake). You can tell zsh to pass the unevaluated argument like bash with setopt