1

I'm currently stuck on an issue with a DOS batch script I’ve been working on, and I need help renaming the files.

Here is the renaming scheme I’m searching for:

Original filenames are more than 30. I wrote only 4.
For example, what do I do for put "kyt-" before last words?

all file name : pajiro kart 05 abd.txt

results: : pajiro kart 05 kyt-abd.txt

or

all file name : pajiro kart 05 acd.txt

results: : pajiro kart 05 kyt-acd.txt

2
  • comment me after you have done the following: put all the filenames into your question so we only have to do this once: dir /b pajiro* > files.txt
    – somebadhat
    Dec 16, 2019 at 16:55
  • add all filenames to question.
    – somebadhat
    Dec 16, 2019 at 17:27

1 Answer 1

0

Windows 10 64-bit

How to rename files with a cmd for loop. How to insert a string into a filename using a cmd for loop.

cmd:

for /f "tokens=1,2 delims= " %a in ('dir /b pajiro*') do ren "%a %b" "%a kyt-%b"

script:

for /f "tokens=1,2 delims= " %%a in ('dir /b pajiro*') do ren "%%a %%b" "%%a kyt-%%b"
exit /b 

test files:

pajiro abd
pajiro adc
pajiro acc
pajiro ahc

results:

pajiro kyt-abd
pajiro kyt-acc
pajiro kyt-adc
pajiro kyt-ahc
3
  • it's work but If have space in words not work how can I rename with words that have space? Example: pajiro kart 05 results: : pajiro kart 05 kyt-abd pajiro kart 05 ==> pajiro kart 05 kyt-abd
    – davidpac
    Dec 16, 2019 at 16:34
  • added all file names to question. please answer now
    – davidpac
    Dec 16, 2019 at 20:40
  • I'm waiting for your answer
    – davidpac
    Dec 17, 2019 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .