摘要载入中…    请稍等…












内容载入中…    请稍等…

如长时间看不到内容,请关闭浏览器,重新打开此页!

芯友首页 应用软件 编程开发 网络硬件 资源下载 动漫音乐 精美图库 芯友论坛 视频教程 电脑技术QQ群:65314343
 ★★photoshop学友-10万图书免费看★★
 位置:编程开发>Deiphi>Deiphi系统文件
◎→ 本类最新
得到已安装的应用程序列表
采用多线程技术来关闭applicatio
创建“控制面板”的新项目
程序删除自身
得到Windows用户名和序列号
得到Win9X里缓存中的密码
从文件中获取最后一次访问信息
得到文件的版本信息程序
动态调整显示器的分辨率
防止关闭windows
◎→ 相关资源
VB窗体文章
HTML入门教程
JavaScript入门教程
VbScript入门教程
ASP.net入门教程
C语言入门教程
Deiphi实例教程
Deiphi窗体文章
Deiphi数据库编程
Deiphi网络编程
◎→ 热门资源
得到已安装的应用程序列表
定制系统菜单
SEO实践增加外链方法
采用多线程技术来关闭applicatio
不用注册新部件就能增加新的方法
不用MediaPlayer播放Midi
从实作标题栏按钮开始浅谈组件的
从实作标题栏按钮开始浅谈组件的
“Delphi 书评”
为Delphi程序添加自动滚动的工具

常用文件目录操作


日期:2008-5-31 18:28:06    来源:
   
 -->实现应用程序的文件拖放功能
 -->用photoshop圆你的汽车梦(目录)
 -->Google正在开发手机操作系统

常用文件目录操作


1-得到短文件名
function GetShortFileName(const FileName : string) : string;
var
  aTmp: array[0..255] of char;
begin
  if GetShortPathName(PChar(FileName),aTmp,Sizeof(aTmp)-1)=0 then
     Result:= FileName
  else
     Result:=StrPas(aTmp);
end;
2-长文件名
function GetLongFileName(const FileName : string) : string;
var
  aInfo: TSHFileInfo;
begin
  if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then
     Result:= string(aInfo.szDisplayName)
  else
     Result:= FileName;
end;

删除到回收站
uses ShellAPI;

procedure SendToRecycleBin(FileName: string);
var
  SHF: TSHFileOpStruct;
begin
  with SHF do begin
    Wnd := Application.Handle;
    wFunc := FO_DELETE;
    pFrom := PChar(FileName);
    fFlags := FOF_SILENT or FOF_ALLOWUNDO;
  end;
  SHFileOperation(SHF);
end;

得到文件最后改动时间
procedure TForm1.Button1Click(Sender: TObject);
var
  FileHandle : THandle;
  LocalFileTime : TFileTime;
  DosFileTime : DWORD;
  LastAccessedTime : TDateTime;
  FindData : TWin32FindData;
begin
  FileHandle := FindFirstFile('AnyFile.FIL', FindData);
  if FileHandle <> INVALID_HANDLE_VALUE then
  begin
    Windows.FindClose(Handle);
    if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
    begin
      FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
      FileTimeToDosDateTime(LocalFileTime,
      LongRec(DosFileTime).Hi,LongRec(DosFileTime).Lo);
      LastAccessedTime := FileDateToDateTime(DosFileTime);
      Label1.Caption := DateTimeToStr(LastAccessedTime);
    end;
  end;
end;

得到目录大小
function TFileBrowser.DirSize(Dir:string):integer;
  var
  SearchRec : TSearchRec;
  Separator : string;

begin
  if Copy(Dir,Length(Dir),1)='\' then
    Separator := ''
  else
    Separator := '\';
  if FindFirst(Dir+Separator+'*.*',faAnyFile,SearchRec) = 0 then
  begin
    if FileExists(Dir+Separator+SearchRec.name) then
    begin
      DirBytes := DirBytes + SearchRec.Size;
      {Memo1.Lines.Add(Dir+Separator+SearchRec.Name);}
    end
    else
      if DirectoryExists(Dir+Separator+SearchRec.name) then
      begin
        if (SearchRec.name<>'.') and (SearchRec.name<>'..') then
          DirSize(Dir+Separator+SearchRec.name);
      end;
    end;
。;  while FindNext(SearchRec) = 0 do
    begin
      if FileExists(Dir+Separator+SearchRec.name) then
      begin
        DirBytes := DirBytes + SearchRec.Size;
        {Memo1.Lines.Add(Dir+Separator+SearchRec.Name);}
      end
      else
        if DirectoryExists(Dir+Separator+SearchRec.name) then
        begin
          if (SearchRec.name<>'.') and (SearchRec.name<>'..') then
            DirSize(Dir+Separator+SearchRec.name);
        end;
      end;
    end;
  end;
  FindClose(SearchRec);
end;
扫描驱动器
  private
    { Private declarations }
    FScanAborted: Boolean;

  public
    { Public declarations }
    function ScanDrive( root, filemask: string; hitlist: TStrings ): Boolean;


function TForm1.ScanDrive( root, filemask: string; hitlist: TStrings ):
Boolean;
  function ScanDirectory( var path: string ): Boolean;
    var
      SRec: TSearchRec;
      pathlen: Integer;
      res: Integer;
    begin
      label1.caption := path;
      pathlen:= Length(path);
      { first pass, files }
      res := FindFirst( path+filemask, faAnyfile, SRec );
      if res = 0 then
      try
        while res = 0 do begin
          hitlist.Add( path + SRec.name );
          res := FindNext(SRec);
        end;
      finally
        FindClose(SRec)
      end;
      Application.ProcessMessages;
      Result := not (FScanAborted or Application.Terminated);
      if not Result then Exit;

      {second pass, directories}
      res := FindFirst( path+'*.*', faDirectory, SRec );
      if res = 0 then
      try
        while (res = 0) and Result do begin
          if ((Srec.Attr and faDirectory) = faDirectory) and
             (Srec.name[1] <> '.')
          then begin
            path := path + SRec.name + '\';
           &nbsp;Result := ScanDirectory( path );
            SetLength( path, pathlen );
          end;
          res := FindNext(SRec);
        end;
      finally
        FindClose(SRec)
      end;
    end;
begin
  FScanAborted := False;
  Screen.Cursor := crHourglass;
  try
    Result := ScanDirectory(root);
  finally
    Screen.Cursor := crDefault
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   ch: Char;
   root: string;
begin
   root := 'C:\';
   for ch := 'A' to 'Z' do begin
     root[1] := ch;
     case GetDriveType( Pchar( root )) of
       DRIVE_FIXED, DRIVE_REMOTE:
         if not ScanDrive( root, edit1.text, listbox1.items ) then
           Break;
     end;
   end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin // aborts scan
  fScanAborted := True;
end;

改目录名
var
  OldName,NewName : string;

  .
  .
  OldName := 'C:\UTILITIES';
  NewName := 'C:\UTILS';
  if MoveFile(PChar(OldName), PChar(NewName)) then
ShowMessage('Directory renamed!')
                                     else ShowMessage('Failure
renaming directory!');
  .
  .
end.  

临时文件
function DGetTempFileName (const Folder, Prefix : string; const Unique: UINT) : string;
var
   FileName : array[0..MAX_PATH] of Char;
begin
   if GetTempFileName (PChar (Folder), PChar (Prefix), Unique, FileName) = 0 then
       raise Exception.Create ('GetTempFileName error');
   Result := FileName;
end; 

 [1]

从文件中获取最后一次访问信息

搜索WebDAV目录

BIOS和操作系统引导

--->CHM浏览器(CHM Explorer) V1.8.0.180┊批量反编译CHM文件┊简体中文绿色特别版
--->WinHex V13.4 SR-4[1026]┊检查和修复文件、恢复删除文件┊英文绿色特别版
--->XPad text editor V2.5┊功能易上手/操作界面漂亮的文本编辑┊汉化绿色免费版
--->金山WPS文件转换器
--->超级电视 V5.60┊可收看全球精彩电视节目、软件操作简便┊简体中文绿色特别版
Tags:  文件 目录 操作
{$enumber$}


芯友网版权所有 1999-2006 | 著作权与商标声明 | 法律声明 | 服务条款 | 隐私声明 | 联系我们