BIM World
A Professional BIM Learning Platform


Batch File Processing Operations

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
Like(0) 打赏
BIM WORLD » Batch File Processing Operations

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up