glob

PHP pagination using glob to retrieve images

坚强是说给别人听的谎言 提交于 2019-12-09 03:23:45
问题 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 images from the directory and when i click on the next page it shows the same 3 images. What would be the best way to fetch different images for each page using glob? $imagesDir = 'uploadedImages/thumbs/*'; $itemsPerPage = 3; $currentPage = isset($_GET[

How to use Perl glob to read remote location?

£可爱£侵袭症+ 提交于 2019-12-08 13:50:15
问题 my test script: my $loc = "\\\\ant\\d1_sp\\test__18716093"; ####$loc = "c:\\temp"; #this works good if I un-comment. system("dir $loc\\*.log"); #added system command just for debugging. my @test = glob qq("$loc\\*.log"); print "\narray=@test\n"; I want to save the file names in $loc into array for further processing, but its not doing so, what am I missing? output is: C:\>perl c:\temp\foo.pl Directory of \\ant\d1_sp\test__18716093 03/14/2016 01:09 PM 959 build_1.8980.log 03/14/2016 01:20 PM

What's the difference between * and .* in regular expressions?

烂漫一生 提交于 2019-12-08 13:37:40
I saw the wildcard of * been used in some command like: find *.jpg , which means find any files ended with .jpg . However, in regular expressions, .* also means that 0 or more times for any character. So, what's the difference between them? When is * been used and when is .* ? In regular expressions, * is the "zero or more" repetition marker. . is the "any single character (with caveats)" expression. In a find the * character is an "anything" wildcard and is not really a regular expression character. The ? is the "any single character" in search situations of this kind. Filename matching

Wordpress: Using glob() returns an empty array

大憨熊 提交于 2019-12-08 11:08:04
问题 I am trying to pull all images from a specified directory and then display them. I used the below piece of code in a regular website and it works <?php $dirname = "images/tile/tile2/"; $images = glob($dirname."*.jpg"); foreach($images as $image) { echo '<li><img src="'.$image.'" /><br /></li>'; }?> I have now moved this code and modified it to a wordpress site and I get an empty array. <?php $dirname = get_template_directory_uri()."/images/tile/tile1/"; $images = glob($dirname. "*.jpg"); //

nullglob and arrays

不想你离开。 提交于 2019-12-08 02:01:50
问题 I can create an array, then delete from this array $ foo=(a b c) $ unset foo[0] $ echo ${foo[*]} b c However if nullglob is set then I cannot delete from the array $ shopt -s nullglob $ foo=(a b c) $ unset foo[0] $ echo ${foo[*]} a b c 回答1: unset 'foo[0]' Bash thinks the var[1] is a glob, doesn't find a file that matches it, and per instruction of nullglob removes it, causing your script to run unset instead of unset var[1] - and nothing gets unset. The correct way to fix this issue is to

Java Globbing Pattern to Match Directory and File

假如想象 提交于 2019-12-07 18:50:34
问题 I'm using a recursive function to traverse files under a root directory. I only want to extract *.txt files, but I don't want to exclude directories. Right now my code looks like this: val stream = Files.newDirectoryStream(head, "*.txt") But by doing this, it will not match any directories, and the iterator() gets returned is False . I'm using a Mac, so the noise file that I don't want to include is .DS_STORE . How can I let newDirectoryStream get directories and files that are *.txt ? Is

get also element that don't match fnmatch

寵の児 提交于 2019-12-07 13:51:27
问题 I'm using a recursive glob to find and copy files from a drive to another def recursive_glob(treeroot, pattern): results = [] for base, dirs, files in os.walk(treeroot): goodfiles = fnmatch.filter(files, pattern) results.extend(os.path.join(base, f) for f in goodfiles) return results Works fine. But I also want to have access to the elements that don't match the filter. Can someone offer some help? I could build a regex within the loop, but there must be a simpler solution, right? Thanks in

How to define multiple patterns in php glob()

不打扰是莪最后的温柔 提交于 2019-12-07 12:28:41
问题 My code to get all images from a directory $dirname = "uploads/"; $images = glob("{$dirname}*.png, {$dirname}*.jpeg, {$dirname}*.jpg, {$dirname}*.gif"); foreach($images as $image) { echo "<img src='{$image}' class='files_main'>"; } This works for one type of image but fails with multiple please give the syntax of defining multiple patterns in the glob(). 回答1: You can use the GLOB_BRACE constant GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c' e.g. $dirname = 'uploads/'; glob("$dirname*.

Wildcard in dictionary key

微笑、不失礼 提交于 2019-12-07 10:54:17
问题 Suppose I have a dictionary: rank_dict = {'V*': 1, 'A*': 2, 'V': 3,'A': 4} As you can see, I have added a * to the end of one V. Whereas a 3 may be the value for just V, I want another key for V1, V2, V2234432, etc...I want to check it against: checker = 'V30' and get the value. what is the correct syntax for this? for k, v in rank_dict.items(): if checker == k: print(v) 回答1: You can use fnmatch.fnmatch to match Unix shell-style wildcards: >>> import fnmatch >>> fnmatch.fnmatch('V34', 'V*')

Listing files in a directory not matching pattern

时光总嘲笑我的痴心妄想 提交于 2019-12-07 10:29:13
问题 The following code lists down all the files in a directory beginning with "hello" : import glob files = glob.glob("hello*.txt") How can I select other files that ARE NOT beginning with "hello" ? 回答1: According to glob module's documentation, it works by using the os.listdir() and fnmatch.fnmatch() functions in concert, and not by actually invoking a subshell. os.listdir() returns you a list of entries in the specified directory, and fnmatch.fnmatch() provides you with unix shell-style