glob

Linux file names & file globbing

别来无恙 提交于 2019-12-10 15:58:57
问题 I have a list of files named: file000 file001 file002 file003 ... file1100 How can I match all files that have a number greater than 800 but less than 1000 ? I am using linux bash Thank you Edit Actually, my files are named like: ab869.enc cp936.enc g122345.enc x2022.enc abc8859-14.enc aax5601.enc cp936-1.enc so the first solution dont match the correct files :( How can I match files that have number between 800-999 ? 回答1: *[89][0-9][0-9].enc That uses Bash's "pathname expansion" feature (aka

Find a file in a directory using python by partial name

∥☆過路亽.° 提交于 2019-12-10 11:48:08
问题 I have a directory with several hundred thousand files in it. They all follow this format: datetime_fileid_metadata_collect.txt A specific example looks like this : 201405052359559_0002230255_35702088_collect88.txt I am trying to write a script that pulls out and copies individual files when all I provide it is a list of file ids. For example I have a text document fileids.txt that constains this fileids.txt 0002230255 0001627237 0001023000 This is the example script I have written so far.

Globbing accented files in Bash

久未见 提交于 2019-12-10 10:16:24
问题 I'm trying to verify a file exists in Bash . I know the file name (in a variable) but not the extension (can be .pmdl or .umdl ). on OSX, this works: $> ls ecole.pmdl $> filename="ecole" $> ls "$filename."[pu]mdl ecole.pmdl But it doesn't when the file name contains an accent: $> ls école.pmdl $> filename="école" $> ls "$filename."[pu]mdl ls: école.[pu]mdl: No such file or directory However it works if I don't use globbing: $> ls "$filename."pmdl école.pmdl I'm looking for a simple solution

nullglob disables pathname tab-completion

杀马特。学长 韩版系。学妹 提交于 2019-12-10 09:23:29
问题 I have found that shopt -s nullglob apparently disables tab-completion for files and directories, and shopt -u nullglob restores it. Why does tab-completion for directories apparently rely on nullglob being unset? I am using Bash 4.2.37(1)-release on Debian 7. 回答1: This is apparently a known issue with bash-completion and is listed as an objective to be fixed in the 3.0 version. But apparently it has been that way since at least 2012. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug

Ruby list directory with Dir['*'] including dotfiles but not . and

允我心安 提交于 2019-12-09 14:31:07
问题 How do I get Dir['*'] to include dotfiles, e.g., .gitignore , but not . and .. ? I.e., is there a better way to do: `ls -A`.split "\n" perhaps with Dir ? The following solutions are close but both include . & .. : Dir.glob('*', File::FNM_DOTMATCH) Dir['{.*,*}'] So, the following works: Dir.glob('*', File::FNM_DOTMATCH) - ['.', '..'] But, is there still a better way to do this? I'm wondering this to fix line 9 of a Meteor Homebrew Formula. 回答1: You can't with Dir[], but you can with Dir.glob,

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

半城伤御伤魂 提交于 2019-12-09 14:27:39
问题 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 <*> because that is what I learned a long time ago and have never thought about it. Which is not a good reason. What syntax do you prefer for globbing, and why? 回答1: Personally, I think that <> is badly overloaded. It sort of means "read from an iterator" but there's a

Why doesn't Perl file glob() work outside of a loop in scalar context?

。_饼干妹妹 提交于 2019-12-09 10:09:13
问题 According to the Perl documentation on file globbing, the <*> operator or glob() function, when used in a scalar context, should iterate through the list of files matching the specified pattern, returning the next file name each time it is called or undef when there are no more files. But, the iterating process only seems to work from within a loop. If it isn't in a loop, then it seems to start over immediately before all values have been read. From the Perl docs: In scalar context, glob

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

人走茶凉 提交于 2019-12-09 08:09:14
问题 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. 回答1: Since glob doesn't support regular expressions, you'll have to brute-force creating the match string. One way is to take advantage of the fact that character ranges in [] are expanded: C:\temp\py>mkdir 12345678901234 C:\temp\py>C:\Python26\python.exe Python 2.6.2 Stackless 3.1b3 060516 (release26-maint, Apr 14 2009, 21:19:36) [M C

RegEx pattern in glob function

左心房为你撑大大i 提交于 2019-12-09 05:59:53
问题 I recive a filename in a function. I want to return all files similar to this file (by filename) from other directory. I wrote this: $thumbDir = $this->files_path.'thumbs/'; $toglob = $thumbDir.pathinfo($name, PATHINFO_FILENAME ).'_[0-9]+\x[0-9]+_thb.'.pathinfo($name, PATHINFO_EXTENSION); foreach (glob($toglob) as $key => $value) { echo $value; } But it doesn't work. I search files which their filename is: oldFileName_[one or more digits]x[one or more digits]_thb.oldFileNameExtension I will

Prevent globbing in a bash script

走远了吗. 提交于 2019-12-09 03:45:49
问题 I am trying to write a script that will operate on selected files. #!/bin/bash #ytest lastArgNo=$# sPattern=${!lastArgNo} echo "operating on $sPattern" #do operation on $sPattern for sFile in $sPattern do #do something with each file done If I start this script with Parameters *.JPG I get operating on IMG_1282.JPG which is the last file found for pattern *.JPG and only this file is being processed. I need the actual file pattern that is given on the commandline. Thanks in advance. 回答1: You