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系统来说,修改名称基本都是三部分,主机名.用 ...
随机推荐
- 事件绑定、取消的二种形式 & call
<script> //call 函数下的一个方法,call方法第一个参数可以改变函数执行过程中的内部this的指向,call方法第二个参数开始就是原来函数的参数列表. function f ...
- nginx 的编译安装及基本操作
下载nginx [root@nginx ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz --2019-05-02 21:52:23-- h ...
- SQL Server数据库的除法默认向下取整,要返回小数的解决方法
num1; / 1000.0 num2; * 1.0 num3; num4; 结果:
- ie8不支持伪类选择器的解决方案
引用jQuery的插件jquery.pseudo.js插件内容: (function($){ var patterns = { text: /^['"]?(.+?)["']?$/, ...
- sql数据表的设计思路
好的表结构分的比较细致,个人理解大概主要分为主表.明细.历史记录表.中间表,辅助表结构应该分为:类型表.状态表.统计表.统计明细表等.为了一个功能加那么多表实在是多余,如果写一个非常复杂的业务逻辑还是 ...
- Linux下安装Redis5.0.2
1.下载redis 地址 http://download.redis.io/releases/redis-5.0.2.tar.gz 2.解压tar -zxf redis-5.0.2.tar.gz 3. ...
- ECSHOP二次开发文档【文件结构说明和数据库表分析】
最近公司又把之前的ecshop进行二次开发,之前看过一些ecshop的东西,但是都过了很久差不多都忘完了,现在得把之前的重新捡回来,特此搜到这些文档,接下来的开发工作中会方便不少. Ecshop文件结 ...
- python3.x Day6 IO多路复用
IO多路复用import asyncio 这个是异步IO模块 这个还不知道怎么用 select poll epoll 都是IO多路复用 windows 仅支持select linux2.6以后 支持e ...
- Python开发环境之pyenv环境搭建
首先到Github上下载Pyenv相应的一键安装脚本, 安装完毕,设置环境变量,设置环境变量,可以添加到个人家目录的.bashrc或.bash_profile及系统的全局的/etc/profile, ...
- 洛谷 1067 NOIP2009 普及组 多项式输出
[题解] 一道简单的模拟题.需要判一些特殊情况:第一项的正号不用输出,x的一次项不用输出指数,系数为0的项不用输出等等,稍微细心一下就好. #include<cstdio> #includ ...