delphi 修改文件夹名和文件名
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,FileCtrl,ShellAPI;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
countd,countf:integer;
sum:integer;
implementation
{$R *.dfm}
//调用方法:ShellFileOperation('c:/afile.txt', 'd:/afile2.txt', FO_COPY); FO_MOVE
procedure ShellFileOperation(fromFile: string; toFile: string; Flags: Integer);
var
shellinfo: TSHFileOpStructA;
begin
with shellinfo do
begin
wnd := Application.Handle;
wFunc := Flags;
pFrom := PChar(fromFile);
pTo := PChar(toFile);
end;
SHFileOperation(shellinfo);
end;
// Example, Beispiel:
function RenDirectory(const OldName,NewName:string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_RENAME;
pFrom := PChar(OldName+#0);
pTo := pchar(NewName+#0);
fFlags := FOF_NOCONFIRMATION+FOF_SILENT;
end;
Result := (SHFileOperation(fo) = 0);
end;
procedure search(dir:string);
var
targetpath:string;{目标路径名}
sr:TsearchRec;
begin
{第一阶段:找出初始dir目录下的所有文件,
其中dir变量值由edit1的Text属性确定}
targetpath:=extractfilepath(dir);{分解出目标路径名}
if findfirst(dir,faanyfile,sr)=0 then
repeat
if((sr.name<>'.')and(sr.name<>'..'){排除父目录和本目录两个假文件}
and((filegetattr(targetpath+sr.name)and fadirectory)<>fadirectory)){只取文件}
then
begin
sum:=sum+1;
RenameFile(targetpath+sr.name, targetpath+inttostr(sum));
countf:=countf+1;
end
until findnext(sr)<>0;
if findfirst(dir,faanyfile,sr)=0 then
repeat
if((sr.name<>'.')and(sr.name<>'..')){排除父目录和本目录两个假文件}
and((filegetattr(targetpath+sr.name)and fadirectory)=fadirectory){排除文件}
then
begin
sum:=sum+1;
RenDirectory(targetpath+sr.name, targetpath+inttostr(sum));
search(targetpath+inttostr(sum)+'/*.*');{递归调用}
//search(targetpath+sr.name+'/*.*');{递归调用}
countd:=countd+1;
end
until findnext(sr)<>0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
curpath,S: string;
dt:TDateTime;
fdt:double;
begin
S := '';
if SelectDirectory('选择要修改名字的文件夹', '', S) then
begin
countf:=0;
countd:=0;
randomize;
sum:= 10000+Random(1000000-10000+1); ;
search(s);{调用Search()函数}
showmessage('共更改目录:'+inttostr(countd)+' 个,文件:'+inttostr(countf)+' 个')
end;
end;
end.
//RenameFile('Oldname', 'Newname');
//CopyFile(PChar('Oldname'), PChar('Newname'), False);
//MoveFile(PChar('Oldname'), PChar('Newname'));
delphi 修改文件夹名和文件名的更多相关文章
- python--批量修改文件夹名
python代码如下: import os , re import os.path rootdir = r'C:\Users\Administrator\Desktop\222' # rootdir ...
- Excel VBA批量修改文件夹下的文件名
今天,有同事提出想批量修改文件名,规则比较简单,在第五位后加“-”即可, 上网没找到相关工具,就自己做了个excel,用宏代码修改. 代码如下: Private Sub CommandButton1_ ...
- matlab 修改文件夹下所有文件名大写为小写
1. path = './DIR/';Files = dir(fullfile(path,'*.m'));LengthFiles = length(Files);for count_i = 1 : L ...
- C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名
原文:C# 文件操作(全部) 追加.拷贝.删除.移动文件.创建目录 修改文件名.文件夹名 本文也收集了目前最为常用的C#经典操作文件的方法,具体内容如下:C#追加.拷贝.删除.移动文件.创建目录.递归 ...
- C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!
https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...
- Python小代码_15_遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间
遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间 import osimport datetime def print_tree(dir_path): for ...
- 树莓派Ubuntu 16.04 MATA系统 修改用户文件夹名后,提示configure it with blueman-service
自从修改了树莓派的Ubuntu 16.04 MATA 系统的 /home/ 下的用户文件夹名后,使用vncserver远程操作,看到桌面每次都提示 Configured directory for i ...
- opencart修改后台文件夹名
在使用opencart进行二次开发时,若需要修改后台目录的文件夹名是可以操作的.具体步骤如下: 1.将网站后台文件夹名字改成opencartadmin 2.在该文件夹下找到config.php文件如图 ...
- Win10系统修改主机名、用户名称和密码、以及C盘中的用户文件夹名
写在前面 近期重新安装了Ubuntu16.04系统,同时也修改了Windows10系统的用户名.密码,还有C盘用户文件夹名称.对于Linux和windows系统来说,修改名称基本都是三部分,主机名.用 ...
随机推荐
- 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753
下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...
- LinuxMint 编译 LittlevGL GUI
编译必须 安装arm-linux-gcc-4.4.3.tar.gz PC simulator You can try out the Littlev Graphics Library using on ...
- postman使用--添加headers、授权、cookies
添加headers Request Headers(请求头)用来说明服务器要使用的附加信息,比较重要的信息有:Cookie,Referer,User-Agent等.在postman中可以在请求下方的H ...
- VS2015提示:未安装Style的Visual Studio语言支持,代码编辑Intellisense将不可用。服务器控件的标记Intellisense可能不起作用
一.问题 最近在VS2015打开文件,提示未安装Style的Visual Studio语言支持,代码编辑Intellisense将不可用.服务器控件的标记Intellisense可能不起作用. Int ...
- canvas使用自定义字体没有效果
字体样式没有显示主要是因为字体还没有加载完成~ css @font-face { font-family: myFont; src: local('sen.ttf'), url("sen.t ...
- visual studio中使用vim快捷键
vsvim下载链接: https://marketplace.visualstudio.com/items?itemName=JaredParMSFT.VsVim 下载,关闭visual studio ...
- 如何让线程A等待B执行结束后执行?
1. 使用条件变量 判断是否任务B已经做完,然后再执行任务A. 测试代码可看:https://blog.csdn.net/guochao6531/article/details/78075882 2. ...
- JS打包与代码分割
参考来源:https://github.com/ruanyf/webpack-demos#demo01-entry-file-source 后面的代码:https://github.com/94713 ...
- Java学习之正则表达式
Java正则表达式字符串模式. 正则表达式可以用来搜索.编辑和处理文本. 正则表达式不尽限于一种语言,但在每一种语言中又细微的差别. java.util.regex包中主要有这3个类: Pattern ...
- Dividing coins (01背包)
It’s commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...