Questions tagged [glob]

globs, more properly called [shell] patterns, and also known as wildcard expressions, are instances of a pattern-matching language used in many, esp. POSIX-like shells, to match filenames and strings: e.g., *.c is a glob for C source files and matches any file whose suffix (extension) is .c

Glob patterns are distantly related to regular expressions, but have simpler, incompatible syntax and offer fewer features.

Their typical use is to match multiple filenames or paths based on an abstract pattern; e.g.:

  • *.cpp
  • log-user*-[0-9][0-9].gz

A major difference between globs and regular expressions (tag: ) is there are far fewer meta-characters for globbing, and there are no duplication symbols (quantifiers). Most notably, * and ? by themselves match any (possibly empty) sequence of characters and any single character, respectively.

Wikipedia has a page on glob patterns.

On Unix systems, the POSIX pattern notation defines the notation for POSIX-compatible shells.

Generally, it is the shell itself that processes a glob pattern specified as an unquoted argument to a command: it expands it to all matching filenames and passes them as individual arguments to the command given, a process known as filename or pathname expansion.

Note that use of patterns in POSIX-like shells is not restricted to filename expansion: they are also used in parameter expansions (e.g., ${HOME##*/} to strip the directory path from a path) and string-matching operations (such as with case ... esac).

3201 questions
1
vote
3 answers

Get latest 15 files in a directory that are recently added to it php

Suppose there's a directory named "abc" This directory contains number of files. Out of all these files, I just want latest "X" or latest 15 files in an array(if possible using glob function) in php. Every help will be greatly appreciable.
gehlotparesh
  • 142
  • 3
  • 13
1
vote
2 answers

Check filename inside a folder contains a pattern using glob()

I need to check the files inside a folder contains '_' symbol. I have used the glob function to get the files from server location. But I am unaware to check the filenames contains the symbol anywhere within the filename. I have files having names…
Techy
  • 2,626
  • 7
  • 41
  • 88
1
vote
1 answer

php glob function and non-ascii characters

I am using php glob() function to find matching files in a directory. glob("*.txt"); It works for filenames with ascii characters e.g. sports.txt, frys.txt etc. However, it does not work with filenames that contain non-ascii character such as…
FoxShrill
  • 91
  • 1
  • 8
1
vote
1 answer

How can I get the top path of glob path?

e.g. a/b/c* -> a/b a/b/c*/*/*b -> a/b Why I need this is because I want to get the abs path of globed filename. Code example: files, _ := filepath.Glob(p) top := __magic here__ for _, f := range files { abs, _ := filepath.Abs(path.Join(top,…
wener
  • 7,191
  • 6
  • 54
  • 78
1
vote
1 answer

extract lines from sub-folders using os.walk() module in Python?

I want to open a series of sub-folders in a folder and find some text files and print some lines of the text files. I am using this: from glob import glob import fileinput with open('output.txt', 'w') as out: for line in…
Miller
  • 275
  • 1
  • 11
1
vote
2 answers

How to store all result from a loop and each result separated by a comma?

Currently I have this working PHP code for search photos inside a folder by name: $dirname = "photos"; $filenames = glob("$dirname/*{380,381,382,383,384,385}*", GLOB_BRACE); foreach ($filenames as $filename) { echo $filename . "
"; } I…
BackTrack57
  • 395
  • 1
  • 5
  • 16
1
vote
3 answers

R: Brace expansion in Sys.glob()

Is it possible to have R's Sys.glob() function expand braces? What I mean is a pattern similar to /home/foo/{a,b}/bar.txt should find files /home/foo/a/bar.txt and /home/foo/b/bar.txt should they both exist. By default R does not expand the…
frankc
  • 11,290
  • 4
  • 32
  • 49
1
vote
1 answer

Regular expressions in PySpark textFile command

I'm trying to figure out how far I can push this command in selecting multiple files of interest. For example I'm using the following wildcard to pick up all files that are of interest across multiple directories, but I'd like to use regular…
disruptive
  • 5,687
  • 15
  • 71
  • 135
1
vote
3 answers

foo[E1,E2,...]* glob matches desired contents, but foo[E1,E2,...]_* does not?

I saw something weird today in the behaviour of the Bash Shell when globbing. So I ran an ls command with the following Glob: ls GM12878_Hs_InSitu_MboI_r[E1,E2,F,G1,G2,H]* | grep ":" the result was as…
FoldedChromatin
  • 217
  • 1
  • 4
  • 12
1
vote
2 answers

Using glob() to fetch filenames without "v[0-9]"

I know how to use glob() to fetch all image files in a directory, but I want to save retrieval time and only fetch the ones I need in the first place. I am building a car dealership website, and there is a directory where all the vehicle photos get…
SISYN
  • 2,209
  • 5
  • 24
  • 45
1
vote
2 answers

Filtering filenames in PHP

I'm trying to group a bunch of files together based on RecipeID and StepID. Instead of storing all of the filenames in a table I've decided to just use glob to get the images for the requested recipe. I feel like this will be more efficient and…
Bodi
  • 271
  • 3
  • 10
1
vote
1 answer

Finding 1 and only 1 character, Python

I have many files named file_1, file_2, another_file_1, another_file_2 etc. How can I find the files which end with 1 and only 1. At the moment I'm using the glob function in a loop, such as for i in range(len(number_of_files)): files =…
1
vote
1 answer

Unexpected output with glob.glob

Im trying to provide wildcard support to one of CLI scripts and I am using pythons glob module for it. For a test i tried this: >>> import glob >>> for f in glob.glob('/Users/odin/Desktop/test_folder/*.log'): ... print…
letsc
  • 2,515
  • 5
  • 35
  • 54
1
vote
2 answers

negative pattern matching to exclude certain files using glob

I am using glob to get all images from a directory. However, some of the images in the directory are thumbnails which are identified by a "-m" immediately before the file extension and I want to exclude these from the file list. So, for example…
e4effect
  • 29
  • 11
1
vote
1 answer

ZSH: how to repeat argument together with expanded filenames

So I'm a neuroimager and I want to open a large number of files. For example: fslview T1.nii.gz _coil_8/run1.nii.gz _coil_8/run2.nii.gz _coil_32/run1.nii.gz _coil_32/run2.nii.gz So I can do this easier using a glob expression in zsh as…
Gilles
  • 343
  • 1
  • 4
  • 12
1 2 3
99
100