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
1 answer

Ignore partial filename only if in specific directory

I wish to ignore: settings/local_*.py apps/settings/local_*.py path_to/settings/local_*.py But I don't wish to ignore: local_*.py something/else/local_*.py And also I don't wish to ignore: settings/non_local_*.py ... Is this beyond gitignore? Of…
frnhr
  • 12,354
  • 9
  • 63
  • 90
1
vote
1 answer

Globbing patterns in selenium

1) "glob:at row [0-9]" does not match "at row 7" 2) "glob:at row *" does match "at row 7" Why does "glob:at row [0-9]" not match "at row 7"? How do I fix it?
Deepan Chakravarthy
  • 4,154
  • 7
  • 25
  • 21
1
vote
1 answer

How to prevent glob patterns from expanding while splitting colon separated glob patterns by colon?

Here is my shell script written for POSIX shell. I am aiming at POSIX shell compatibility. There is a PATTERNS variable that contains colon separated glob patterns. This variable is a user input. I cannot change this. The rest of the code is my code…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
1
vote
1 answer

scandir() display file found/not found error messge

I have 100 files and I am scanning them and picking the correct file out of them. I am using the following code: $dir = 'myDir'; $files1 = scandir($dir); $scanned_directory = array_diff($files1, array('..', '.')); foreach…
krv
  • 2,830
  • 7
  • 40
  • 79
1
vote
1 answer

php - get sub-sub-folder and specific files name and path

I would to retrieve from a path all sub (and sub-sub) directories and all files (only with .php and .css extensions) in (last sub) it. The structre is the following: my_path/sub-folder1/ // I want to get the sub folder name (and check if…
freaky
  • 990
  • 3
  • 17
  • 44
1
vote
1 answer

Perl DosGlob fails after first evaluation

I have a script which poplulates filenames and last modified time of the respective file under a particular directory. I have used DosGlob module to specify the regex. Sample directory structure…
Irfan N
  • 93
  • 1
  • 1
  • 7
1
vote
3 answers

php glob not returning all files

I looked at similar questions here and around the web, but none of the solutions have worked. I'm using glob to return 177 images from a folder. Only some return. Sometimes nothing returns. Every time I reload the page, a few more images are loaded.…
1
vote
1 answer

why doesn't my code work when i have a subfolder statring with numeric values in PATH?

I am reading a folder of multiple images and here's the part of code where i read the folder specified in path, path = 'C:\main\folder\sub-folder\08001\V.1\abc\2015' for infile in glob.glob( os.path.join(path, '*.tif') ): Img = gdal.Open(…
PythonLearner
  • 85
  • 1
  • 1
  • 5
1
vote
1 answer

Array with directories and subdirectories PHP slow

I created this function: function expandDirectories2($base_dir) { $directories = array(); $folders = glob($base_dir."*", GLOB_ONLYDIR); foreach($folders as $file) { if($file == '.' || $file == '..') continue; …
MM PP
  • 4,050
  • 9
  • 35
  • 61
1
vote
2 answers

Match file name with glob function

I have the following filenames: foo.ext foo-1.ext foo-2.ext foo-3.ext Currently the code $name = "foo-[0-9].*"; glob($name as a $filename){ echo $filename; } Only matches foo1-ext foo2-ext foo3-ext But no foo.ext How do I modify my glob to…
Toki
  • 165
  • 1
  • 1
  • 6
1
vote
3 answers

PHP pagination using glob to retrieve images

I'm trying to retrieve images from a folder using glob() and i want it to be paginated so it only displays 3 images per page. From digging around on the internet and here on S.O. i've got the code below. The problem is that it only pulls three…
Catfish
  • 18,876
  • 54
  • 209
  • 353
1
vote
1 answer

python open file matching pattern excluding substring

I need to open some files inside a folder in python Say, I have the following files in the…
1
vote
2 answers

I split a large Json file to more correctly edit the information. Now that I edit it, how can I merge them back in php?

I had a master Json that I split into individual files to more accurately/correctly edit the information. I did my edits and now would like to combine them back into one master json in php. The current way I have set up is by globing the jsons, then…
daylon
  • 65
  • 8
1
vote
1 answer

Text file to csv with glob. Need to change delimiter depending on section of file being read

I have a text file that doesn't have a standard delimiter. I need to be able to check if the current line is equal to a certain phrase and if it is, the code should use a certain delimiter until another phrase is found. delimiters used are ','…
Shane
  • 41
  • 9
1
vote
1 answer

Iterate over specific files in a directory

I need to get all images that begin with "t_" using glob. What pattern should I use to do this? //get any image files that begin with "t_" -- (t_image.jpg) not (image.jpg) $images = glob("" . $dir . "*.jpg"); foreach($images…
Luke Burns
  • 1,911
  • 3
  • 24
  • 30
1 2 3
99
100