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

glob php - return all types of images from directory

I have a php function to grab images from a folder for a carousel and build the carousel on those images. I have a thumbnail folder and a main img folder. My question is, how can I modify this code or what to add in order to recognise more image…
Luke
  • 555
  • 1
  • 5
  • 23
22
votes
1 answer

Glob Sync Pattern on multiple directories

I am trying to achieve a glob sync pattern that allows me to meet the following criteria, but unfortunately, im having a hard time working out why the pattern isn't working. Glob Pattern glob.sync("./src/handlebar/{a, b, c, d}/**/*.hbs") File Path…
jagmitg
  • 4,236
  • 7
  • 25
  • 59
22
votes
2 answers

Read multiple csv files and Add filename as new column in pandas

I have several csv files in a single folder and I want to open them all in one dataframe and insert a new column with the associated filename. So far I've coded the following: import pandas as pd import glob, os df = pd.concat(map(pd.read_csv,…
amwade2
  • 251
  • 1
  • 3
  • 6
22
votes
1 answer

Add all files under a folder to a CMake glob?

I've just read this: CMake - Automatically add all files in a folder to a target? With the answer suggesting a file glob, e.g.: file(GLOB "*.h" "*.cpp") now, what if I want my target to depend on all files of a certain type under a certain folder -…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
22
votes
8 answers

Globbing/pathname expansion with colon as separator

How can I convert a string containing glob characters such as /var/lib/gems/*/bin into a colon-separated string of filenames (i.e. PATH compatible) matching the pattern? i.e. echo /var/lib/gems/*/bin will return /var/lib/gems/1.8/bin…
mjs
  • 63,493
  • 27
  • 91
  • 122
22
votes
5 answers

How can I use a glob to ignore files that start with an underscore?

I am using this file matching in gulp: 'content/css/*.css' But I would like to only include the files that do not start with an underscore. Can someone tell me how I can do this? Here's the code: gulp.task('less', function () { …
Alan2
  • 23,493
  • 79
  • 256
  • 450
22
votes
1 answer

use python glob to find a folder that is a 14 digit number

I have a folder with subfolders that are all in the pattern YYYYMMDDHHMMSS (timestamp). I want to use glob to only select the folders that match that pattern.
mikec
  • 3,543
  • 7
  • 30
  • 34
21
votes
2 answers

Node/JavaScript glob file/path matching syntax, wildcards, etc

I just found http://gruntjs.com/configuring-tasks#globbing-patterns, which is the most helpful reference I've found. I keep seeing: For more on glob pattern syntax, see the node-glob and minimatch documentation. Yet, I can't seem to find an…
Michael Lewis
  • 4,252
  • 6
  • 28
  • 39
21
votes
6 answers

Brace expansion in python glob

I have python 2.7 and am trying to issue: glob('{faint,bright*}/{science,calib}/chip?/') I obtain no matches, however from the shell echo {faint,bright*}/{science,calib}/chip? gives: faint/science/chip1 faint/science/chip2 faint/calib/chip1…
astabada
  • 1,029
  • 4
  • 13
  • 26
20
votes
2 answers

How do I use directory globbing in JDK7

I have been trying to use the new globbing feature in JDK7, starting from the documentation and examples I can get globs such as "glob:*.dat" to work with the Files.walkFileTree(startingDir, finder); example but I have been unable to get the "**"…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
20
votes
2 answers

How to move and rename documents placed in several nested folders into a new single folder with python?

I have several files across several folders like this: dir ├── 0 │   ├── 103425.xml │   ├── 105340.xml │   ├── 109454.xml │ │── 1247 │   └── doc.xml ├── 14568 │   └── doc.xml ├── 1659 │   └── doc.xml ├── 10450 │   └── doc.xml ├── 10351 │   └──…
tumbleweed
  • 4,624
  • 12
  • 50
  • 81
20
votes
5 answers

Globbing in C++/C, on Windows

Is there a smooth way to glob in C or C++ in Windows? E.g., myprogram.exe *.txt sends my program an ARGV list that has...ARGV[1]=*.txt in it. I would like to be able to have a function (let's call it readglob) that takes a string and returns a…
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212
19
votes
4 answers

glob() — Sort by Name

How can I reverse the sort by filename? Currently it displays all the text files in alphabetical / numerical order, but I'm trying to have it display in descending order instead. Right now, I have...
FrozenTime
  • 231
  • 1
  • 2
  • 9
19
votes
2 answers

How do I find all files that have a certain extension in Go, regardless of depth?

I have a directory structure that looks like this: /root /folder_1 file_name_1.md /folder_2 file_name_2.md /folder_3 file_name_3.md /folder_4 /sub_folder_1 file_name_4_1.md file_name_4.md Is there a glob function…
Malekai
  • 4,765
  • 5
  • 25
  • 60
19
votes
5 answers

Python glob include hidden files and folders

I try to loop over all files matching a certain extension, including those inside hidden folders. So far I haven't found a way to do this with iglob. This works for all folder except those starting with a dot: import glob for filename in…
SeeDoubleYou
  • 1,253
  • 2
  • 15
  • 25