delphi 路径问题

用delphi路径问题

 

  1. ExtractFilePath  //路径后面带有 "/"  (不管是在磁盘根目录还是哪里)  
  2. ExtractFileName  //文件名  
  3. ExtractFileExt   //扩展名  

例子:

  1. ExtractFilePath(ParamStr(0));  // C:/  
  2. ExtractFileName(ParamStr(0));  // Project.exe  
  3. ExtractFileExt(ParamStr(0));   // .exe 

ExtractFilePath   和GetCurrentDirectory 区别

ExtractFilePath(Application.ExeName)
返回当前程序可执行文件所在目录的全路径



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi中,要实现拖拽文件夹并获取其路径,可以按照以下步骤进行操作: 1. 添加控件:在窗体上添加一个TListBox控件用于显示拖拽的文件夹路径。 2. 设置TListBox为可接受拖拽文件:在TForm的OnCreate事件中添加以下代码,将TListBox的DragMode属性设置为dmAutomatic,使其可以接受文件拖拽操作。 ``` procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.DragMode := dmAutomatic; end; ``` 3. 处理拖拽事件:在TListBox的OnDragDrop事件中添加以下代码,用于处理拖拽文件夹的操作。 ``` procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer); var i: Integer; DropFiles: TStrings; begin DropFiles := TStringList.Create; try if Source is TListBox then begin DropFiles.AddStrings(TListBox(Source).Items); for i := 0 to DropFiles.Count - 1 do ListBox1.Items.Add(DropFiles[i]); end; finally DropFiles.Free; end; end; ``` 4. 显示文件夹路径:在TListBox的OnDragOver事件中添加以下代码,用于在拖拽过程中显示文件夹路径。 ``` procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := Source is TListBox; if Accept then begin if State = dsDragEnter then ListBox1.Items.Clear; ListBox1.Items.Add(GetDroppedFileName); end; end; ``` 5. 获取文件夹路径:最后,我们还需要添加一个函数GetDroppedFileName,用于获取文件夹路径。 ``` function TForm1.GetDroppedFileName: string; var DropHandle: THandle; FileCount, i: Integer; FileName: array[0..MAX_PATH] of Char; begin Result := ''; DropHandle := DragQueryFile(DragQueryFile(DragQueryFile(DragQueryFile(Handle, Cardinal(-1), nil, 0), 0, nil, 0), 0, @FileName[0], Length(FileName)), 0, nil, 0); if DropHandle <> Cardinal(-1) then begin FileCount := DragQueryFile(Handle, DragHandle, nil, 0); if FileCount > 0 then begin DragQueryFile(DragHandle, 0, @FileName[0], Length(FileName)); Result := FileName; end; end; DragFinish(DragHandle); end; ``` 以上就是在Delphi中使用拖拽操作获取文件夹路径的步骤和代码。希望能对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值