查找名称为F ***.text的文件 [英] find a file with the name F***.text

查看:57
本文介绍了查找名称为F ***.text的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个按钮,当按下该按钮时,它将运行这段代码,这是它获取请求的路径并尝试找到文件名"txtDealerCode.Text +"* .wav",但我得到的只是"1111 * .wav" ,但我需要它,以便*表示任何含义,例如,它可能返回"1111abc"或"1111987",这是可能的吗??我已经看到人们在使用1111. *的情况下使用*作为文件类型,但是是否可以做到一半?

Hi,

i have a button which when pressed will run this bit of code, what this does is it gets the requested path and tries to find a filename "txtDealerCode.Text + "*.wav" but all i get is "1111*.wav", but i need it so that the * will mean anything so for example it might return "1111abc" or "1111987" is that possible?? i have seen it where people use 1111.* to get the file with * being the filetype but isit possible to do it half way through?

UserDirectory uDirectory = new UserDirectory();
string path = uDirectory.GetUserDirectory(txtProjectReference.Text, "CheckDirectory");
string fileName = txtDealerCode.Text + "*.wav";
string file = path + fileName;
Process.Start(file);




谢谢,
Bunker




Thanks,
Bunker

推荐答案

string []文件= Directory.GetFiles(path,txtDealerCode.Text +"* .wav");
string[] files = Directory.GetFiles(path, txtDealerCode.Text + "*.wav");


您的代码正在尝试启动文件名带有通配符的进程.你不能那样做.描述启动过程的文件路径中不允许使用通配符.

如果这是您真正想要做的,则必须使用GetFiles方法之一,并枚举此列表,然后分别对每个文件名使用Process.Start.不过,当我想到退回100个文件的可能性时,我真的感到非常畏缩.
You''re code is trying to launch a process with the filename with a wildcard in it. You can''t do that. Wildcards are not allowed in filepath describing the process to launch.

If this is what you really want to do, you have to use one of the GetFiles methods and enumerate over this list and use Process.Start on each of these filenames seperately. Though, I really cringe when I think about the possiblity of having 100 files returned.


比利,

将正则表达式与FileInfo/DirectoryInfo类一起使用.

http://www.regular-expressions.info/ [ http://msdn.microsoft.com/en-us/library/system.io. fileinfo.aspx [^ ]

http://msdn.microsoft.com/en-us/library/system.io. directoryinfo.aspx [^ ]
Hi Billy,

Use regular expressions along with FileInfo/DirectoryInfo classes.

http://www.regular-expressions.info/[^]

http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx[^]

http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx[^]


这篇关于查找名称为F ***.text的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆