EDIT:
New Code thanks to the help of @Magoo
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
echo NOTE: This will create all necessary project template folders.
echo[
set /p projNumName=" Enter Project Number & Name (ex. 23-000_My Project Name): "
SET projectName=%projNumName%
SET sourcedir="Y:\2023 Projects\%projectName%"
MkDir "Y:\2023 Projects\%projNumName%"
xcopy "W:\_PROJECT TEMPLATES-do not delete_\ProjTemplate\" "Y:\2023 Projects\%projectName%\" /e
PUSHD "%sourcedir%"
FOR /f "delims=" %%e IN ('dir /s /b /a:-d "Y:\2023 Projects\%projectName%\*template*" ' ) DO (
SET "filename=%%~nxe"
SET "filename=!filename:template=%projectname%!"
REN "%%e" "!filename!"
)
FOR /f "delims=" %%e IN ('dir /s /b /ad "Y:\2023 Projects\%projectName%\*template*" ^|sort /rev' ) DO (
SET "dirname=%%~nxe"
SET "dirname=!dirname:template=%projectname%!"
REN "%%e" "!dirname!"
)
)
popd
dir/s /b /on "Y:\2023 Projects\%projectName%"
echo[
echo[
echo[
echo Template folders and files have been copied to your project folder.
echo[
echo[
echo[
echo[
PAUSE
GOTO :EOF
end of edit
I found this post, but I don't have enough rep points to comment on it. It's effectively nearly identical to my situation. I can't use PowerShell, and I need to recursively search for a string ("Template") and replace it with another, which the user inputs.
Here are the important parts of the code I have so far:
@echo off
echo THIS WILL CREATE YOUR PROJECT FOLDERS
echo[
SET /p projectName="Enter Project Number and Name (ex. 23-000_My New Project): "
MkDir "Y:\%projectName%"
MkDir "T:\Final Project Files 2023\%projectName%"
xcopy "W:\_PROJECT TEMPLATES_\Template\" "Y:\%projectName%\" /e
echo[
echo Template folders and files have been copied to the new project folder.
echo[
echo Rename any instances of "Template" to match your new project name.
echo[
PAUSE
START "" "C:\Program Files\Bulk Rename Utility\Bulk Rename Utility.exe"
The code I have works for the situation, but I'm attempting to eliminate the last bit where Bulk Rename Utility launches and requires the user to manually bulk rename the folders and files that contain "Template".
What I get now is:
Y:\23-000_My New Project\Template-Folder1
Y:\23-000_My New Project\Template-Folder2
Y:\23-000_My New Project\Template-Folder2\Template.txt
I would like to have:
Y:\23-000_My New Project\23-000_My New Project-Folder1
Y:\23-000_My New Project\23-000_My New Project-Folder2
Y:\23-000_My New Project\23-000_My New Project-Folder2\23-000_My New Project.txt