[英]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
File2 文件2
FileN FileN
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.