Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: ugly rename file?  (Read 2401 times)

0 Members and 1 Guest are viewing this topic.

Alexey

  • Guest
ugly rename file?
« on: October 13, 2005, 12:49:35 AM »
Hi.

I need to rename files in my "dir1" directory.
The filename for example: 123_some_thing1_abracadabra.txt

I need to rename it in: 123_some_thing1.txt

Any sugestions?

Thanks in advance.



Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: ugly rename file?
« Reply #1 on: October 13, 2005, 05:49:18 AM »
Please do not post the same question more than once. It labels you a double poster or (gasp) a triple poster.:o

Provided all the file names have the same naming pattern (3 underscores, 1 dot) and the new names all have a pattern (2 underscores and 1 dot), you simply parse the filenames and then rebuild them like Humpty Dumpty:

Code: [Select]

@echo off
for /f "tokens=1-5 delims=_." %%a in ('dir1 *.txt /b') do (
     ren %%a_%%b_%%c_%%d.%%e %%a_%%b_%%c.%%e
)


Hope this helps. 8)
« Last Edit: October 13, 2005, 05:50:06 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

vibhor_agarwalin



    Adviser

    Re: ugly rename file?
    « Reply #2 on: October 13, 2005, 06:24:53 AM »
    Sidewinder can you help me with this tokens and delims.

    I have tried many times but somehow could get to exactly how it works.
    Vibhor Kumar Agarwal

    2k_dummy



      Specialist
    • A word, once spoken, can never be recalled.
    • Thanked: 14
      Re: ugly rename file?
      « Reply #3 on: October 13, 2005, 07:00:03 AM »
      You can always just right click the file name and rename it to whatever you want.
      If you don't stand for something, you'll fall for anything.
      _______________________________________ ________
      BlackViper

      Software and utilities

      GX1_Man

      • Guest
      Re: ugly rename file?
      « Reply #4 on: October 13, 2005, 07:51:46 AM »
      Triple posting gets the long walk to the Sin Bin. You need to discuss this with Fed to avoid prosecution.

      :o :o :o :o :o :o

      Alexey

      • Guest
      Re: ugly rename file?
      « Reply #5 on: October 14, 2005, 04:36:08 AM »
      Hi.

       Sotty for triple post, but it's not my fault. Brouser's i gess.

       I've come up with this solution? It realy works:
       DIR /B > f.txt
      for /F "eol=; tokens=1,2,3,4* delims=_" %%A in ('find ".vox" f.txt') do (
      IF %%E GTR 0 rename %%A_%%B_%%C_%%D_%%E %%A_%%B_%%C_%%D.vox
      )
      del f.txt

      Thanks for example.