Using the rename command
Moderator: DosItHelp
Using the rename command
Hi
I have a file named Encoder_TestHarnessLog_19_12_13-083023.xml that I want to rename Test1_19_12_13-083023.xml from within a batch file
but cant see to Achieve this with the rename command.
Please can someone suggest a way of doing this?
I have a file named Encoder_TestHarnessLog_19_12_13-083023.xml that I want to rename Test1_19_12_13-083023.xml from within a batch file
but cant see to Achieve this with the rename command.
Please can someone suggest a way of doing this?
Re: Using the rename command
The following code might help you (although i suspect that you didn't describe the whole issue):
penpen
Code: Select all
rename "Encoder_TestHarnessLog_19_12_13-083023.xml" "Test1_19_12_13-083023.xml"
Re: Using the rename command
HI thanks
you are correct
I need to retain the date stamp ant the on the end of the original and include it it the second
you are correct
I need to retain the date stamp ant the on the end of the original and include it it the second
Re: Using the rename command
In this case you should provide a real example how it looks like before and after renaming (e.g. the number of underscores could be critical here), plus the rules of how to get from the old name to the new (e.g. does the new name always begin with "Test1_").
Steffen
Steffen
Re: Using the rename command
Ok let me clarify
Given a file name of
Encoder_TestHarnessLog_19_12_13-113027.xml
I want to generate a filename of
Test1_19_12_13-113027.xml
Where Test1 can be any string (ultimately a command line argument to a batch script
I hope this is clearer
Given a file name of
Encoder_TestHarnessLog_19_12_13-113027.xml
I want to generate a filename of
Test1_19_12_13-113027.xml
Where Test1 can be any string (ultimately a command line argument to a batch script
I hope this is clearer
Re: Using the rename command
This code only displays the RENAME command line. Remove ECHO and PAUSE to make it rename the file.
Note: According to your example file name and because you didn't comment to my remark that the number of underscores is critical, I assumed that the file names always have 2 underscores in front of the date.
Steffen
Code: Select all
@echo off &setlocal DisableDelayedExpansion
set "file=Encoder_TestHarnessLog_19_12_13-083023.xml"
set "prefix=Test1"
for %%i in ("%file%") do (
for /f "tokens=2* delims=_" %%j in ("%%~nxi") do (
ECHO rename "%%~fi" "%prefix%_%%k"
)
)
PAUSE
Steffen
Re: Using the rename command
Thanks - this is what I was looking for
Re: Using the rename command
I updated the code. There have been two useless variables.
Steffen
Steffen
Re: Using the rename command
Thanks
How do I close the question?
How do I close the question?
Re: Using the rename command
It's not intended to close a topic. If you want to mark your question as solved you may edit your initial post and prepend something like [solved] to the subject.
Steffen
Steffen