举例:我有一个目录里 D:\目录\ 下面的文件 49088-1,49088-2,49088-3,49088-4,49088-5,49088-6,49089-1,49089-2,49089-3,49089-4,49089-5,49089-6 这样的文件 我数据库里存的是 49088 ,49089 的数 我怎么样才根据数据库的数据 查询出来对应的所有文件并得到文件名。
解决方案 »
- 请问谁有delphi的控件说明书啊!
- 一个DLL文件丢失,整个程序都运行不了吗?
- 先取有效数字,然后让小数转换为百分数?
- 关于随机问题
- 急!!!!我在把一张临时表中的所有数据(不多)插入的另一张表时出错了,谁知道原因啊?
- 我这样的菜鸟居然上了专家总榜,看来CSDN的高手是不多了!
- delphi模糊查找,模糊查找组件,模糊查找思路,
- 新手求助:电脑时间问题,
- 怎样在richedit容器中取得行间距,字间距;望各位赐教!
- 请教各位大师一个问题?以下代码总是出错,请多多指正,谢谢!!!
- 调用 包含GIF图片的窗口DLL时,GIF不能动作?
- 请问为什么我的这个更新表中一行的操作会变成更新整个表,请高手指教
可以这样处理 LeftStr('49088-1', Pos('-', '49088-1') - 1);{------------------------------------------------------------------------------------
名称: SearchFiles
功能: 搜索指定目录下的文件
参数: strSearchFiles: TStringList - 输出搜索到的文件路径结果列表(需要调用者负责初始化和释放)
strDir: string - 指定要搜索的目录
strExt: string - 指定要搜索的文件类型(默认搜索所有类型 *.*)
strExceptFiles: TStringList - 指定排除的文件名列表(如 Desktop.ini, Thumbs.db 等)
返回: Cardinal - 返回搜索到的文件个数
说明: 只搜索当前一级目录, 不搜索子目录, 需自行修改为递归调用.
-------------------------------------------------------------------------------------}
function SearchFiles(out strSearchFiles: TStringList; const strDir: string; const strExt: string = '*.*'; const strExceptFiles: TStringList = nil): Cardinal;
var
search: TSearchRec;
ret: Integer;
count: Integer;
i: Integer;
bIsFoundExcept: Boolean;
begin
// 先检要搜索的目录是否存在
if not DirectoryExists(strDir) then
begin
Result := 0;
Exit;
end; // 开始搜索
ret := FindFirst(strDir + '\' + strExt, faAnyFile, search);
if ret <> 0 then
begin
Result := 0;
Exit;
end;
while ret = 0 do
begin
// 排除文件夹
if (search.Name = '.') or
(search.Name = '..') or
(search.Attr = faDirectory) then
begin
ret := FindNext(search);
Continue; // 跳过
end; // 排除指定文件
if strExceptFiles <> nil then
begin
count := strExceptFiles.Count;
if count > 0 then
begin
bIsFoundExcept := False;
for i := 0 to count - 1 do
begin
if LowerCase(search.Name) = LowerCase(strExceptFiles[i]) then
begin
bIsFoundExcept := True;
Break;
end;
end;
if bIsFoundExcept then
begin
ret := FindNext(search);
Continue; // 跳过
end;
end;
end; // 添加到结果
if RightStr(strDir, 1) <> '\' then
begin
strSearchFiles.Add(strDir + '\' + search.Name);
end
else
begin
strSearchFiles.Add(strDir + search.Name);
end; // 继续搜索
ret := FindNext(search);
end;
FindClose(search); Result := strSearchFiles.Count;
end;