I have 1000's of files without extensions. but these files are named as below
xxxxxxxxxxxxxxxx12345-xxxxxxxxxxxxxxxxxxxxx
or
xxxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxx12345
my request is
search for files containing 12345 in their names and rename them with unique
names of xxxxxxxxxx.txt (10 Char name) with .txt extension.
source and destination folder's are the same E:\test
is this possible
if so please help
thanx in advance
joe
renaming extention of a file
Moderator: DosItHelp
Re: renaming extention of a file
joe wrote:files without extensions ... search for files containing 12345 in their names
Code: Select all
for /f "delims=" %%i in ('dir /a-d /b "E:\test\*12345*"') do if "%%~xi"=="" echo %%i
... isn't clear to me. Not even a numeric name would be easy to calculate because the the biggest number in batch is 2147483647 which is already 10 digits.joe wrote:...rename them with unique
names of xxxxxxxxxx.txt (10 Char name) with .txt extension
Steffen
Re: renaming extention of a file
I'll start you off, this will find files with your required patterns:All you need to do now is determine how you intend to create unique ten character file names and changetoDepending upon how the files are generated you could possibly use a combination of date and time to generate the unique names.
Code: Select all
@Echo Off
If /I Not "%CD%"=="E:\test" (PushD "E:\test" 2>Nul||Exit/B)
For /F "Delims=" %%A In ('Where .:"????????????????12345-?????????????????????"^
"????????????????12345-?????????????????????"') Do If "%%~xA"=="" Echo [%%A]
Timeout -1
Code: Select all
Echo [%%A]
Code: Select all
Ren "%%A" "UniqueName.txt"
Re: renaming extention of a file
ok steffen any name as u suggested.. but should not repeat over writing files
Re: renaming extention of a file
I'm afraid I wasn't clear enough. A 10 digits number is already limited in batch. So if you would say 9 digits are sufficient it would be much easier. Also consider Compo's suggestion. The file time could be unique enough (and could be composed to a 10 digits file name) if you could make sure there don't exist 2 or more files with "modified" time stamp within the same minute. This way you also don't need to iterate over all files to find the latest number.
Steffen
Steffen