简体   繁体   English

将子目录中的pdf文件重命名为子目录的名称

[英]Rename the pdf file inside sub-directories to the name of the sub directory

I am using win 7 platform. 我正在使用Win 7平台。 Need your help to create a bat file which simplifies my job. 需要您的帮助来创建一个bat文件,从而简化我的工作。 My folders and files are arranged in this structure. 我的文件夹和文件以这种结构排列。

File1 文件1

  • folder1 ->abcd.pdf folder1-> abcd.pdf
  • folder2 ->shhd.pdf.............................. folderN ->gfdfgd.pdf folder2-> shhd.pdf .....................文件夹N-> gfdfgd.pdf

File2 文件2

  • folder1 ->gbg.pdf folder1-> gbg.pdf
  • folder2 ->kjc67z.pdf.............................. folderN ->iuxz4i.pdf folder2-> kjc67z.pdf .....................文件夹N-> iuxz4i.pdf

-- -

-- -

-- -

FileN FileN

  • folder1 ->ah455.pdf folder1-> ah455.pdf
  • folder2 ->jfhd45.pdf.............................. folderN ->juvxzr.pdf folder2-> jfhd45.pdf .....................文件夹N-> juvxzr.pdf

I want to generate a batch file which renames the pdf file to name of the folder it contains. 我想生成一个批处理文件,将pdf文件重命名为它包含的文件夹的名称。 For example, in the above structure "abcd.pdf" is renamed to folder1.pdf. 例如,在上述结构中,“ abcd.pdf”被重命名为folder1.pdf。 Respectively this is done for all pdf files. 分别对所有pdf文件执行此操作。

Also a folder named "test" is created inside each directory(file1,file2..etc) which contains all the renamed pdf files of its respective directory. 在每个目录(file1,file2..etc)中还会创建一个名为“ test”的文件夹,其中包含其各自目录的所有重命名的pdf文件。

If i copy all the folders inside File1 to Myfolder & run the bat file, a folder named test will be created and all the pdf file will be renamed and copied to test folder. 如果我复制内部文件1的所有文件夹MyFolder文件和运行批处理文件,文件夹命名为测试将被创建,所有的PDF文件将被重新命名并复制到测试文件夹中。

But what I want is, I want to run the bat file in H:\\ drive. 但是我想要的是,我想在H:\\驱动器中运行bat文件。 Lets assume H:\\ drive contains all the directories File1, File2....FileN with each directory containing a sub-directory as I had shown in the above structure. 假设H:\\驱动器包含所有目录File1,File2 .... FileN,每个目录都包含一个子目录,如我在上面的结构中所示。 If i run the bat file in H:\\ drive, then a folder named test has to be created inside each directory which contains the renamed pdf files of its respective sub-directories. 如果我在H:\\驱动器中运行bat文件,则必须在每个目录内创建一个名为test的文件夹,其中包含其各个子目录的重命名pdf文件。

@ECHO OFF &SETLOCAL
for /F "delims=" %%a in ('dir /b /s /a-d *.pdf') do (
     set "fname=%%~fa"
     for %%b in ("%%~dpa.") do set "nname=%%~nxb"
     setlocal enabledelayedexpansion
     ECHO ren "!fname!" "!nname!.pdf"
     endlocal
)

Note: you can rename only one pdf/folder. 注意:您只能重命名一个pdf /文件夹。


Some other code for the OP: OP的其他一些代码:

@ECHO OFF &SETLOCAL
MKDIR "H:\Myfolder\test"
for /f "delims=" %%i in ('DIR /b /a-d "H:\Myfolder"') do (
    ECHO %%i
    CD "H:\Myfolder\%%~i"
    ren *.pdf "%%~nxi.pdf"
    copy *.pdf "H:\Myfolder\test"
    cd H:\Myfolder
)
cd H:\Myfolder\test
del H:\Myfolder\test\test.pdf 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用子目录名重命名子目录中的文件,并为每个子目录重新启动增量编号 - Rename files in sub directories using sub directory name with incremental number restarting for each sub directory 使用批处理脚本将特定文件从源目录复制到目标目录和子目录 - Copy specific file from source directory to target directory and sub-directories using batch script 尝试使用Bat文件获取目录和子目录中所有文件的行数 - Trying to Get A Line Count for all Files in a Directory and Sub-Directories using a Bat File 使用批处理文件中文件名的前2个字符创建子目录 - Creating sub-directories using first 2 characters of a file name in a batch file 批处理脚本以查找文件所在的目录,将该目录和子目录中的所有文件复制到另一个目录 - batch script to find the directory where a file is located, copy all files located in that directory and sub-directories to another directory 将多个子目录中的文件复制到具有匹配的子目录名称的另一个目录 - Copy files in multiple sub-directories to another directory with matching sub-directory names 一组子目录中最新文件的修改日期 - Date modified of most recent file(s) in a set of sub-directories 如何将文件批量复制到多个子目录? - how can I batch copy a file into multiple sub-directories? 按文件类型从子目录复制到单个文件夹? - Copy by file type, from sub-directories, to a single folder? 蝙蝠文件来递归子目录并做一些事情 - Bat file to recurse sub-directories and do Something
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM