When exporting CAD or PDF files in batches using Revit, the generated file names often include unwanted prefixes. To address this, a simple batch script was created to automate file name manipulation. This script can efficiently add prefixes, remove prefixes, and replace specific strings within file names.
Below is the core batch script code for these operations:
:: Add prefix
cmdAddPrefix
echo Type the file extension to process:
set /p type=
echo Enter the prefix to add:
set /p prefix=
echo Processing files...
for /f "delims=" %%i in ('dir /a /b *.%type%') do (
echo Original file: %%i
ren "%%i" "%prefix%%%i"
set /a fileNum+=1
)
goto commit
:: Remove prefix
cmdDelPrefix
echo Type the file extension to process:
set /p type=
echo Enter the prefix to remove:
set /p prefix=
set str=%prefix%
set preNum=0
:: Calculate length of prefix
:next
if not "%str%"=="" (
set /a preNum+=1
set "str=%str:~1%"
goto next
)
setlocal enabledelayedexpansion
echo Processing files...
for /f "delims=" %%i in ('dir /a /b %prefix%*.%type%') do (
set var=%%i
set "var=!var:~%preNum%!"
echo Original file: %%i
ren "%%i" "!var!"
set /a fileNum+=1
)
goto commit
:: Replace string in file names
cmdReplaceStr
echo Type the file extension to process:
set /p type=
echo Enter the string to replace:
set /p str=
echo Enter the replacement string:
set /p str1=
setlocal enabledelayedexpansion
echo Processing files...
for /f "delims=" %%i in ('dir /a /b *.%type%') do (
set var=%%i
set "var=!var:%str%=%str1%!"
echo Original file: %%i
ren "%%i" "!var!"
set /a fileNum+=1
)
goto commit
xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat













Must log in before commenting!
Sign Up