Thursday, November 6, 2025

Prefix all subfolders in a folder using Windows Batch Scripting

The following batch script shows how to prefixes all folders with "Java_".

@echo off
set "prefix=Java_"

REM The /D switch iterates over directory names only.
REM The * wildcard matches all folders.
FOR /D %%i in (*) DO (
    echo "%prefix%%%i"
)

@pause

To really prefix all subfolders of the folder, use REN instead of ECHO command with following minor change:

@echo off
set "prefix=Java_"

REM The /D switch iterates over directory names only.
REM The * wildcard matches all folders.
FOR /D %%i in (*) DO (
    REN "%%i " "%prefix%%%i"
)

@pause

Tips

  • REN command is used to rename file or folder. For more details run the command REN/?

No comments:

Post a Comment

Hot Topics