glob

Is there an equivalent of java.util.regex for "glob" type patterns?

Is there a standard (preferably Apache Commons or similarly non-viral) library for doing "glob" type matches in Java? When I had to do similar in Perl once, I just changed all the "." to "\.", the "*" to ".*" and the "?" to "." and that sort of thing, but I'm wondering if somebody has done the work for me. Similar question: http://stac...

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 vector of strings, each containing a filename. This way, if I have files a.txt b.txt c.txt i...

Why does Perl's glob return undef for every other call?

I'm not necessarily looking for a better way to do this, rather an explanations of the output would greatly be appreciated. Recently, a senior programmer asked me why his code worked but only for one instance. What I came to find out was that it worked every other occurrence. Here is my example: #!/usr/bin/perl -w use strict; my @li...

php doesn't scan relative path for files

Here is my current code (that i am very proud of for my first attempt at php) <?php $files = glob("/jobops/*.txt"); $indexcount = count($files); sort($files); print("<br>"+$indexcount+"<br>"); foreach ($files as &$file) { print("<a href=\"$file\">$file</a><br>"); } ?> the problem is glob again works fine in the root directory (whe...

Is there any guarantee that results of globbing will be sorted in Perl?

Is there any guarantee that the array of filenames returned from a glob (e.g. <*>) will be sorted? I can't find that sorting is mentioned one way or the other in the documentation, but it seems to be the case in every directory I've tried it on. I'm talking about using this syntax: @files = <*>; If I need the files to be sorted, wou...

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

This question is a spin-off from this one. Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now I pretty much always use readdir. After thinking over this recent question I realized th...

How does glob return 'filenames' that don't exist?

This answer indicates that glob can sometimes return 'filenames' that don't exist. @deck = glob "{A,K,Q,J,10,9,8,7,6,5,4,3,2}{\x{2660},\x{2665},\x{2666},\x{2663}}"; However, that code returns an empty list when I run it. What am I missing? This run was from the command prompt using -e, on Windows XP, with ActiveState Perl version ...

Bash globbing - autoexpand for a few specific cases?

I understand that the wildcard * (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period. There are two use cases that I would think are useful, but I don't know how to properly do: How can you glob for... "All files in the current folder, incl...

What Perl glob expression matches all the files that look like /home/test-N.txt?

I am a beginner to Perl syntax and have a basic wildcard question. I am looking for an expression that would allow me to retrieve all of the following files. /home/test-1.txt /home/test-2.txt /home/test-3.txt I am just interested in the actual wildcard expression, not the file I/O. ...

graceful degradation for globbing on terminal

Whenever glob pattern match fails, it stops the whole job. For instance, $ mv *.jpg *.png folder1 && blahblah mv: cannot stat `*.jpg': No such file or directory *.png isn't moved to folder1 and blahblah is not run. And the script below works only for the case when both .[A-z]* and * succeed. #!/bin/bash cd $1 du -sk .[A-z]* *| sort...

Specify glob size range in Regex

How do I define a minimum and maximum (possibly unbounded) number of times a certain pattern should repeat itself? I know there's ? and *, with which I could build the pattern by repeating it a certain amount of times, but I know there's a special notation for it using {}, I just can't remember how it is. ...

Get the longest non-glob string at the start of a string

I'm trying to create a script to convert from $GIT_DIR/info/exclude to .gitignore files. I'd like to put the .gitignore files as close to the pattern target as possible, meaning that a glob like /a/b/*/*.c should be put in /a/b/.gitignore. To do this accurately, I need something which can return the longest substring from the start which...

Filter Hidden Files with Bash (for Batch Image Resize Script)

I'm writing a script to batch resize images. Originally I was applying an operation for file in $(ls $1), but I would like to be able to use globbing, so I'm looking at something more like for file in $(echo $1). The problem is that dotglob may or may not be enabled, so echo * could return hidden files (notably, .DS_Store), which cause c...

PHP foreach glob to load images from a folder not working quite right

Hi, I need to load images from 2 different folders, each thumbnail has its associated large version (same name, different folder). I have 3 files in the large pics folder and 3 files in the thumbs folder and I'm getting 9 links! Each thumbnail gets repeated 3 times or x times the quantity of pics in the main folder This is the code: <?...

Can PHP's glob() do a not wildcard?

I know I can do this glob('/dir/somewhere/*.zip'); but is there a way to return all files that are not ZIPs? Or should I just iterate through and filter off ones with that extension? Thanks ...

find . -type f in ruby

I want to grab a list of all the files under a particular directory. Dir.glob works great, but there doesn't seem to be a way to limit results to just files (excluding directories). Heres's what I have right now: files = Dir.glob('my_dir/**/*').reject { |f| File.directory?(f) } Is there a more elegant way to accomplish this? ...

What are the comparative advantages of glob('foo*') vs <foo*> ?

I was just looking at Can someone tell me how to create an array of directory contents?. Unsurprisingly, file globs were offered as an answer. What surprised me was that the post recommended using glob() rather than <*>. I use use <*> because that is what I learned a long time ago and have never thought about it. Which is not a good ...

How do I find the first 5 files in a directory with PHP?

How would I list the first 5 files or directories in directory sorted alphabetically with PHP? ...

Why am I leaking memory with this python loop?

I am writing a custom file system crawler, which gets passed millions of globs to process through sys.stdin. I'm finding that when running the script, its memory usage increases massively over time and the whole thing crawls practically to a halt. I've written a minimal case below which shows the problem. Am I doing something wrong, or h...

Use a Glob() to find files recursively in Python?

This is what I have: Glob(os.path.join('src','*.c')) but I want to search the subfolders of src. Something like this would work: Glob(os.path.join('src','*.c')) Glob(os.path.join('src','*','*.c')) Glob(os.path.join('src','*','*','*.c')) Glob(os.path.join('src','*','*','*','*.c')) But this is obviously limited and clunky. ...