Windows Batch
--
Questions
--
Followers
Top Experts
I have a filename "0000000001_someothertext.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
First ten characters:
@echo off
setlocal enabledelayedexpansion
set Source=C:\Temp
for %%a in ("%Source%\*.pdf") do (
set NewFileName=%%~na
set NewFileName=!NewFileName:~0,10!%%~xa
ECHO ren "%%~a" !NewFileName!
)
Split at underscore:
@echo off
setlocal enabledelayedexpansion
set Source=C:\Temp
for %%a in ("%Source%\*.pdf") do (
for /f "tokens=1 delims=_" %%f in ("%%~na") do set NewFileName=%%f%%~xa
ECHO ren "%%~a" "!NewFileName!"
)
set filename=0000000001_someothertext.pdf
for %%a in ("%filename%") do set extension=%%~xa
ren "%filename%" %filename:~0,10%%extension%
set filename=0000000001_someothertext.pdf
ren "%filename%" "%filename:~0,10%.pdf"






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
ren "0000000001_someothertext.
and if you have more than one file then you could do:
ren "*_*.* " "??????????.*"
~bp
The first solution's neat though.
What version of DOS did that first appear in? I just tested it in 32-bit XP Pro and it worked fine.
set filename=0000000001_someothertext.pdf
ren "%filename%" "??????????.*"
Steve

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
~bp
Just curios, why did you chose that solution over http:#a38602319 ?
It's certainly your choice to accept what works for you, but seems like a simpler one solution should have been preferred over the more complex 2 line solution that requires delayed expansion of variables? Wanted to see if I was missing something.
~bp






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Windows Batch
--
Questions
--
Followers
Top Experts
Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.