glob

How to search file in folder by using php?

雨燕双飞 提交于 2020-01-05 07:31:51
问题 I have a folder called allfiles , and there are some files in this folder, such as 1212-how-to-sddk-thosd.html 3454-go-to-dlkkl-sdf.html 0987-sfda-asf-fdf-12331.html 4789-how-to-fdaaf-65536.html I use scandir to list all files, and now I need to find the file by with keywords, example to-dlkkl is the keyword, and I will get the file 3454-go-to-dlkkl-sdf.html . Glob seems not work, and opendir and readdir are not work well, any ideas? 回答1: Use loop foreach and strpos function: $files = scandir

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

佐手、 提交于 2020-01-02 07:21:11
问题 How would I list the first 5 files or directories in directory sorted alphabetically with PHP? 回答1: Using scandir() : array_slice(array_filter(scandir('/path/to/dir/'), 'is_file'), 0, 5); The array_filter() together with the is_file() function callback makes sure we just process files without having to write a loop, we don't even have to care about . and .. as they are directories. Or using glob() - it won't match filenames like .htaccess : array_slice(glob('/path/to/dir/*.*'), 0, 5); Or

Can NOT List directory including space using Perl in Windows Platform

一曲冷凌霜 提交于 2020-01-02 01:49:07
问题 In order to list pathes in Windows,I wrote below Perl function(executed under StrawBerry runtime environment). sub listpath { my $path = shift; my @list = glob "$path/*"; #my @list = <$path/*>; my @pathes = grep { -d and $_ ne "." and $_ ne ".." } @list; } But it can't parse directory including space correctly, for example: When I issued following code: listpath("e:/test/test1/test11/test111/test1111/test11111 - Copy"); The function returned an array including two elements: 1: e:/test/test1

Glob wildcards in windows npm

浪子不回头ぞ 提交于 2020-01-01 03:10:07
问题 I'm trying to get npm to do a build browserify on a folder of scripts. The problem is, I'm on windows and doing folder/*.js doesn't seem to work. I've tried globally installing glob, but whenever I run a build command, the error comes back saying "Cannot find module 'c:\www\project\static\js\components*.js'. Here's my package.json: { "name": "TEST", "description": "ITS ME MARIO", "author": "JJ", "version": "0.0.1", "dependencies": { "connect": "1.8.5", "express": "2.5.2", "jade": "0.20.0",

Quicker to os.walk or glob?

夙愿已清 提交于 2019-12-31 08:28:53
问题 I'm messing around with file lookups in python on a large hard disk. I've been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size directories). Has anyone got any experience with them both and could say which is more efficient? As I say, glob seems to be slower, but you can use wildcards etc, were as with walk, you have to filter results. Here is an example of looking up core dumps. core = re.compile(r"core\.\d*") for root, dirs

Escape spaces in glob() in PHP?

家住魔仙堡 提交于 2019-12-31 05:21:06
问题 I have the following function in PHP, which is working great except for files with spaces in their names ( Good picture.jpg for example). Here it is: function getphotolist($currentalbum) { $photos = glob($currentalbum.'/*.[Jj][Pp][Gg]'); $albumparts = explode('_', $currentalbum); switch (array_key_exists(2,$albumparts)) { case false: usort($photos,"cmpexiftime"); break; case true: usort($photos,"cmpexiftimer"); break; } $photolist = ""; foreach($photos as $photo){ $phototitle = explode('_'

WordPress php glob(); not working?

£可爱£侵袭症+ 提交于 2019-12-30 07:33:33
问题 I have created a function in WordPress where I wish to obtain all the images within a given directory, for which I am using the PHP glob function, for some reason I cannot get this to work, is the glob() function disabled for use within WordPress? The Code that Doesn't Work... function getAccreditaionLogos(){ define('ACCREDPATH', get_stylesheet_directory_uri() . '/img/accreditations/'); $images = glob(ACCREDPATH . '*.png'); foreach($images as $key => $img): $get_icons = '<li><img src="'.$img.

Python, how to implement something like .gitignore behavior

末鹿安然 提交于 2019-12-29 06:46:49
问题 I need to list all files in the current directory (.) (including all sub directories), and exclude some files as how .gitignore works (http://git-scm.com/docs/gitignore) With fnmatch (https://docs.python.org/2/library/fnmatch.html) I will be able to "filter" files using a pattern ignore_files = ['*.jpg', 'foo/', 'bar/hello*'] matches = [] for root, dirnames, filenames in os.walk('.'): for filename in fnmatch.filter(filenames, '*'): matches.append(os.path.join(root, filename)) how can I

grunt (minimatch/glob) folder exclusion

好久不见. 提交于 2019-12-27 17:07:28
问题 I have a situation where I'm trying to use grunt to lint a codebase, excluding specific folders. grunt uses minimatch (similar to bsdglob) under the hood to match files, but I can't seem to figure out how to do a .gitignore style exclude of a folder. I'd like to ingest this: ignoreme and match these: /folder/path/here/to/something/ok.js /another/folder/path.js /test.js but not match these: /folder/ignoreme/something.js /folder/path/here/to/ignoreme/metoo/file.js This will match everything,

PHP get file listing including sub directories

只愿长相守 提交于 2019-12-27 14:48:51
问题 I am trying to retrieve all images in a directory, including all subdirectories. I am currently using $images = glob("{images/portfolio/*.jpg,images/portfolio/*/*.jpg,images/portfolio/*/*/*.jpg,images/portfolio/*/*/*/*.jpg}",GLOB_BRACE); This works, however the results are: images/portfolio/1.jpg images/portfolio/2.jpg images/portfolio/subdirectory1/1.jpg images/portfolio/subdirectory1/2.jpg images/portfolio/subdirectory2/1.jpg images/portfolio/subdirectory2/2.jpg images/portfolio