Delphi 獲取指定目錄下檔案的大小

2021-06-01 01:43:33 字數 1446 閱讀 5228

這個函式可以獲得指定目錄下所有的檔案路徑+名稱,能夠遞迴搜尋:

procedure findallfile(const dir: string;list: tstringlist);

var hfindfile: thandle;

findfiledata: win32_find_data;

fullname,fname,s:string;

begin

s:=includetrailingpathdelimiter(dir);

hfindfile := findfirstfile(pchar(s+'*.*'), findfiledata);

if hfindfile <> 0 then begin

repeat

fname:=findfiledata.cfilename;

fullname:=s+fname;

if (fname='.') or (fname='..') then continue;

if (findfiledata.dwfileattributes and file_attribute_directory) = file_attribute_directory then

findallfile(fullname,list)

else

begin

list.add(fullname);

end;

until findnextfile(hfindfile, findfiledata) = false;

windows.findclose(hfindfile);

end;

end;

這個函式可以獲得指定檔案的大小:

function getfilesizebyname(afilename: string): int64;

var h: thandle;

dwhigh,dwlow:dword;

begin

dwhigh:=0;

if fileexists(afilename) then

begin

h:= fileopen(afilename,fmopenread or fmsharedenynone);

dwlow:=getfilesize(h,@dwhigh);

if (dwlow = $ffffffff) and (getlasterror() <> no_error) then

result:=0

else

result:= (dwhigh shl 32) + dwlow;

fileclose(h);

endelse

result := 0;

end;

要獲得目錄的總大小,可以先用第乙個函式獲得所有目錄下檔案的列表,然後遍歷這個列表,累加檔案尺寸。

Perl獲取目錄下檔案或者包含子目錄下檔案

1 my dir d my work temp 2my files 34 獲取給定目錄下檔案 5 files get dir files dir 67 獲取給定目錄以及子目錄下檔案 8 files get dir files x dir 9 10 獲取目錄下以及子目錄下檔案,返回的結果中包含路徑 1...

目錄下檔案計數

每個linux下的path中包含的系統變數都有好多路徑 root wl ms 7673 home wl 桌面 shell echo path usr local sbin usr local bin usr sbin usr bin sbin bin usr games usr local arm ...

刪除目錄下檔案

刪除當前目錄下的檔案 1.rm f 最經典的方法,刪除當前目錄下的所有型別的檔案 2.find type f delete或find type f exec rm f 用find命令查詢普通檔案並刪除or用find命令的處理動作將其刪除 3.find type f xargs rm f 用於引數列表...