举例:我有一个目录里 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 Spring Framework V0.2.0 is released!
- 使用ShellExecute向另外一个EXE程序传递参数。
- 如何读取在WORD中的"姓名:"
- 大家帮忙看一下
- 为什么这段代码按了按钮后没有反应?
- ADO连接网络数据库出错?在线等
- 有哪位知道如何在DBGRID(或者DBGRIDEH)中将金额字段显示成像“现金日记帐”那样的格式?
- 一个Interbase数据库兼容Date数据类型的问题,在线等待
- 如何通过条形码获取商品信息并把记录添加到GXGRID
- 哪里有中文书详细说明控件的使用的啊,哎,烦死了。
- 调用 包含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;