我是Perl语法的初学者,并且有一个基本的通配符问题.我正在寻找一个允许我检索所有以下文件的表达式.
/home/test-1.txt /home/test-2.txt /home/test-3.txt
我只对实际的通配符表达式感兴趣,而不是文件I/O.
嘿.我正在使用glob.glob函数来获取我提供的路径上的所有.txt文件的列表.我正在为函数提供正则表达式C:\build\*.txt,但它只适用于根目录,我想在c:\ build \中找到所有文本文件,c:\build\files\ha.txt例如.
这怎么可能?Thankss.
之前已经问过同样的问题,但解决方案对我不起作用.
我想通过将其添加到.hgignore文件来指示Mercurial忽略名为.metadata的文件夹.这是我的.hgignore文件:
glob:.hgignore
glob:.hgignore~
glob:.metadata/*
Run Code Online (Sandbox Code Playgroud)
我已成功测试了忽略.hgignore和.hgignore~的工作原理.如果我删除前两行并运行hg状态,它们会显示出来.如果我包含前两行并运行hg状态,它们就会消失.但它不适用于.metadata文件夹.上面的语法是下面引用的解决方案中报告的语法.它对我不起作用.我也尝试过glob:.metadata /.
临时解决方法是不在.metadata文件所在的工作空间上使用Mercurial.;-)
欢迎任何建议,谢谢!
编辑:解决方案所以看起来这是有效的:
glob:.metadata
Run Code Online (Sandbox Code Playgroud)
它也更简单,因此更漂亮.感谢greut指出它.
这是在Windows上 - 我如何在perl中使用".zip"结束所有文件?
这是当前代码,并且出于此问题的目的,不可更改 - 所有可以更改的是$ pattern变量的值.
my @arr = map { glob( $_ ) } $pattern;
Run Code Online (Sandbox Code Playgroud)
另外一个问题,这段代码中map函数的用途是什么?它有效,但我不明白.
我有这个简单的界限:
$images = glob($directory . "*.html");
Run Code Online (Sandbox Code Playgroud)
它返回一个像这样的文件列表:
例如1
17001400300120110004600.html
17001400300120110004700.html
17001400300120110004800.html
17001400300120110004900.html
17001400300120110005000.html
Run Code Online (Sandbox Code Playgroud)
问题是我不需要有序列表.我需要一个随机列表,如下所示:
例如2
17001400300120110004700.html
17001400300120110005000.html
17001400300120110004900.html
17001400300120110004600.html
17001400300120110005800.html
Run Code Online (Sandbox Code Playgroud)
我已尝试使用NOSORT ( $images = glob($directory . "*.html", GLOB_NOSORT); )flag但返回了第一个示例中的有序列表.
我怎样才能获得随机列表?
我希望同时使用GLOB_NOSORT并GLOB_BRACE与glob()功能,这可能吗?
原因是我不希望通过glob()函数进行任何排序,我当前的代码如下所示:
$filetypes = '{*.txt,*.pdf,*.doc,*.docx,*.zip,*.jpeg,*.jpg,*.gif,*.ping,*.zip,*.rar}';
//assign $files to results of glob()
$files = glob($structure.$filetypes, GLOB_BRACE);
usort($files, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
print_r($files);
Run Code Online (Sandbox Code Playgroud)
上面的代码不会根据对文件进行排序filemtime()。
谢谢
我有这个非常简单的c程序:
#include <stdio.h>
int main (int argc, char ** argv){
printf ("%s\n",argv[1]);
}
Run Code Online (Sandbox Code Playgroud)
在Linux/bash上运行时如下:
./a.out *
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
a.c
Run Code Online (Sandbox Code Playgroud)
为什么?
我使用'rename'命令重命名一组文件; 例如:
inputcac1010.inp.log inputcac1110.inp.log inputcac1210.inp.log inputcac1310.inp.log
inputcac1020.inp.log inputcac1120.inp.log inputcac1220.inp.log inputcac1320.inp.log
inputcac1030.inp.log inputcac1130.inp.log inputcac1230.inp.log inputcac1330.inp.log
inputcac1040.inp.log inputcac1140.inp.log inputcac1240.inp.log inputcac1340.inp.log
inputcac1050.inp.log inputcac1150.inp.log inputcac1250.inp.log inputcac1350.inp.log
inputcac1060.inp.log inputcac1160.inp.log inputcac1260.inp.log inputcac1360.inp.log
inputcac1070.inp.log inputcac1170.inp.log inputcac1270.inp.log inputcac1370.inp.log
inputcac1080.inp.log inputcac1180.inp.log inputcac1280.inp.log inputcac1380.inp.log
inputcac1090.inp.log inputcac1190.inp.log inputcac1290.inp.log inputcac1390.inp.log
inputcac1100.inp.log inputcac1200.inp.log inputcac1300.inp.log inputcac1400.inp.log
Run Code Online (Sandbox Code Playgroud)
必须重命名为
inputcac1010.log inputcac1110.log inputcac1210.log inputcac1310.log
inputcac1020.log inputcac1120.log inputcac1220.log inputcac1320.log
inputcac1030.log inputcac1130.log inputcac1230.log inputcac1330.log
inputcac1040.log inputcac1140.log inputcac1240.log inputcac1340.log
inputcac1050.log inputcac1150.log inputcac1250.log inputcac1350.log
inputcac1060.log inputcac1160.log inputcac1260.log inputcac1360.log
inputcac1070.log inputcac1170.log inputcac1270.log inputcac1370.log
inputcac1080.log inputcac1180.log inputcac1280.log inputcac1380.log
inputcac1090.log inputcac1190.log inputcac1290.log inputcac1390.log
inputcac1100.log …Run Code Online (Sandbox Code Playgroud) 我正在运行该命令find . -name *.bak并收到错误"Paths must precede expression"错误.这个问题已得到解答,答案非常好,但我不明白为什么bash在运行find命令之前扩展了外卡?原始的例子.
它说find . -name *.bak扩大到find . -name tim.bak example.bak.有人可以解释为什么它被扩展,我不明白为什么这个功能为globs是个好主意.
我试图匹配/ dev / ttyS0以外的以下路径,即/ dev / ttyS1到/ dev / ttyS99。在我的Linux终端中,我使用:
ls /dev/ttyS[1-9][0-9]*
Run Code Online (Sandbox Code Playgroud)
这不会返回任何东西。下面的表达式虽然将/ dev / ttyS1返回到/ dev / ttyS9。
ls /dev/ttyS[1-9]
Run Code Online (Sandbox Code Playgroud)
关于如何使第一个表达式起作用的任何想法?