在移動一個檔案夾(內含檔案)的時候,檔案夾為什么只能保留八位
比如:D:\temp\12345678999 移動到 D:\temp\rz\
新的檔案夾名稱為12345678
中文的檔案夾只能保留8個漢字
uj5u.com熱心網友回復:
為了能拷貝目錄下帶有子目錄的情況,先定義一個輔助的拷貝函式,它是遞回執行的,直到把目錄下的所有檔案和子目錄都拷貝完。---- 1.1拷貝目錄的遞回輔助函式:DoCopyDir
function DoCopyDir(sDirName:String;
sToDirName:String):Boolean;
var
hFindFile:Cardinal;
t,tfile:String;
sCurDir:String[255];
FindFileData:WIN32_FIND_DATA;
begin
//先保存當前目錄
sCurDir:=GetCurrentDir;
ChDir(sDirName);
hFindFile:=FindFirstFile( '*.* ',FindFileData);
if hFindFile < > INVALID_HANDLE_VALUE then
begin
if not DirectoryExists(sToDirName) then
ForceDirectories(sToDirName);
repeat
tfile:=FindFileData.cFileName;
if (tfile= '. ') or (tfile= '.. ') then
Continue;
if FindFileData.dwFileAttributes=
FILE_ATTRIBUTE_DIRECTORY then
begin
t:=sToDirName+ '\ '+tfile;
if not DirectoryExists(t) then
ForceDirectories(t);
if sDirName[Length(sDirName)] < > '\ ' then
DoCopyDir(sDirName+ '\ '+tfile,t)
else
DoCopyDir(sDirName+tfile,sToDirName+tfile);
end
else
begin
t:=sToDirName+ '\ '+tFile;
CopyFile(PChar(tfile),PChar(t),True);
end;
until FindNextFile(hFindFile,FindFileData)=false;
FindClose(hFindFile);
end
else
begin
ChDir(sCurDir);
result:=false;
exit;
end;
//回到原來的目錄下
ChDir(sCurDir);
result:=true;
end;
---- 1.2拷貝目錄的函式:CopyDir
function CopyDir(sDirName:String;
sToDirName:string):Boolean;
begin
if Length(sDirName) < =0 then
exit;
//拷貝...
Result:=DoCopyDir(sDirName,sToDirName);
end;
uj5u.com熱心網友回復:
用一個api MoveFileExfunction MoveFileEx(
lpExistingFileName: PChar; // 來源檔案名,指向一個以零結尾的字串的指標。
lpNewFileName: PChar; // 目標檔案名,指向一個以零結尾的字串的指標。
dwFlags: DWORD // 移動標記,見定義
): BOOL; stdcall; // 回傳執行結果,成果或失敗
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/108846.html
標籤:非技術區
上一篇:我的碼,我的媽……
