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 修改文件夹名和文件名的更多相关文章

  1. python--批量修改文件夹名

    python代码如下: import os , re import os.path rootdir = r'C:\Users\Administrator\Desktop\222' # rootdir ...

  2. Excel VBA批量修改文件夹下的文件名

    今天,有同事提出想批量修改文件名,规则比较简单,在第五位后加“-”即可, 上网没找到相关工具,就自己做了个excel,用宏代码修改. 代码如下: Private Sub CommandButton1_ ...

  3. matlab 修改文件夹下所有文件名大写为小写

    1. path = './DIR/';Files = dir(fullfile(path,'*.m'));LengthFiles = length(Files);for count_i = 1 : L ...

  4. C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名

    原文:C# 文件操作(全部) 追加.拷贝.删除.移动文件.创建目录 修改文件名.文件夹名 本文也收集了目前最为常用的C#经典操作文件的方法,具体内容如下:C#追加.拷贝.删除.移动文件.创建目录.递归 ...

  5. C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!

    https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...

  6. Python小代码_15_遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间

    遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间 import osimport datetime def print_tree(dir_path): for ...

  7. 树莓派Ubuntu 16.04 MATA系统 修改用户文件夹名后,提示configure it with blueman-service

    自从修改了树莓派的Ubuntu 16.04 MATA 系统的 /home/ 下的用户文件夹名后,使用vncserver远程操作,看到桌面每次都提示 Configured directory for i ...

  8. opencart修改后台文件夹名

    在使用opencart进行二次开发时,若需要修改后台目录的文件夹名是可以操作的.具体步骤如下: 1.将网站后台文件夹名字改成opencartadmin 2.在该文件夹下找到config.php文件如图 ...

  9. Win10系统修改主机名、用户名称和密码、以及C盘中的用户文件夹名

    写在前面 近期重新安装了Ubuntu16.04系统,同时也修改了Windows10系统的用户名.密码,还有C盘用户文件夹名称.对于Linux和windows系统来说,修改名称基本都是三部分,主机名.用 ...

随机推荐

  1. JS:输出9*9乘法表

    <html> <head> <title>9*9 multiplication table</title> </head> <body ...

  2. Spread / Rest 操作符

    Spread / Rest 操作符指的是 ...,具体是 Spread 还是 Rest 需要看上下文语境. 当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组) function foo ...

  3. 【搜索】P1468 派对灯 Party Lamps

    P1468 派对灯 Party Lamps 我们来分析一下对灯的操作 1.对所有灯的,这时吧所有灯看成一个整体 2.奇偶数的操作,这时可以把每两个数看成一个循环节 3.对3X+ 1的操作,这时可以把每 ...

  4. 微信小程序---宿主环境

    (1)宿主环境 我们称微信客户端给小程序所提供的环境为宿主环境.小程序借助宿主环境提供的能力,可以完成许多普通网页无法完成的功能.之前把小程序涉及到的文件类型阐述了一遍,接下来结合demo项目来讲一下 ...

  5. Vickers Vane Pump Tips - Vane Pump Maintenance Note

    The    Vickers Vane Pump    describes the matters needing attention in the maintenance of the vane p ...

  6. 关于Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't available. Compilation of Maven projects is supported only&

    总是出现Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't avai ...

  7. No-10.高级变量类型

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...

  8. c++的if语句中的110为什么不等于110?

    从上图可以看出,当表达式1.1*x被直接放进if的判断括号中时1.1*x不等于y,但是将1.1*x赋值给z时,z与y相等,这是为什么?(以下为不等价时的代码) #include<stdio.h& ...

  9. 教你轻松在React Native中集成统计(umeng)的功能(最新版)

    关于在react-native中快速集成umeng统计,网上的文章或者教程基本来自----贾鹏辉老师的文章http://www.devio.org/2017/09/03/React-Native-In ...

  10. LeetCode(11) Container With Most Water

    题目 Given n non-negative integers a1, a2, -, an, where each represents a point at coordinate (i, ai). ...