Hi,
I'm working on over 28,000 online tests. Each test is in one subfolder. Each subfolder consists of one index.html file in addition to 3 sub subfolders which contain the test data. I am in a dire need to rename all the index.html files to their subfolders name, so that when publishing the entire tests online, each test can be accessed through its very index.html file name. For example, if the subfolder's name is: TMC-WQ-AOP-T1, its index.html file would be renamed to TMC-WQ-AOP-T1.html instead.
Can I get some precious assistance with this request please?
Many thanks in advance.
T.
Batch to rename index.html files to their subforders' names
Moderator: DosItHelp
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Batch to rename index.html files to their subforders' names
Place that batch file in the parent folder and run it.
Note: The code will only display the command lines without doing any renaming operation yet. If you are convinced it would do what you're looking for then remove ECHO and PAUSE from the code in order to perform the renaming if you run the updated code.
Steffen
Code: Select all
@echo off &setlocal EnableExtensions DisableDelayedExpansion
for /f "delims=" %%i in ('dir /a-d /b /s "index.html"') do (
for %%j in ("%%~dpi.") do ECHO ren "%%~i" "%%~nxj%%~xi"
)
PAUSE
Steffen
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Batch to rename index.html files to their subforders' names
Thank you very much aGerman for your prompt response to my question. In fact, I followed your instructions and placed the batch file in the parent folder and ran it after removing the echo and pause as advised, but nothing has been changed. I attempting placing the batch file down in the subdirectories themselves, but no index.html file has been affected to be renamed.
I may add that tests subdirectories with their index file and other sub subdirectories vary in their location in the parent folder. In other words, they may be in the first subdirectory from the parent directory or the ninth subdirectory from the parent. So I believe the batch should recursively search for the index.html file.
Once again, thank you very much.
T.
I may add that tests subdirectories with their index file and other sub subdirectories vary in their location in the parent folder. In other words, they may be in the first subdirectory from the parent directory or the ninth subdirectory from the parent. So I believe the batch should recursively search for the index.html file.
Once again, thank you very much.
T.
Re: Batch to rename index.html files to their subforders' names
The /S option of DIR means that it searches recursively. I already tested the script and everything worked out for me. By saying "parent folder" I meant the root folder in your folder structure that contains the index.html files (regardless of how many levels deep in the folder structure, because /S searches in all subsequent levels).
Steffen
Steffen
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Batch to rename index.html files to their subforders' names
Thank you very much Steffen for your genius code; it did run soothly and all the index.html files were renamed after their folders as exactly as desired.
Pardon me for a silly mistake that I made before running your code which made it not to run at first time.
Please accept my deep gratitude.
T.
Pardon me for a silly mistake that I made before running your code which made it not to run at first time.
Please accept my deep gratitude.
T.