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

Author Topic: Rename/replace  (Read 32516 times)

0 Members and 1 Guest are viewing this topic.

Helpmeh



    Guru

  • Roar.
  • Thanked: 123
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Familiar
  • OS: Windows 8
Re: Rename/replace
« Reply #30 on: December 31, 2009, 05:10:21 PM »
We've given the working code to the OP, he has used it but questions how it works. We (ST and I) have explained the code and the OP has left. No need to bump a dead topic.
Where's MagicSpeed?
Quote from: 'matt'
He's playing a game called IRL. Great graphics, *censored* gameplay.

BillRichardson



    Intermediate

    Thanked: 15
    Re: Rename/replace
    « Reply #31 on: December 31, 2009, 05:11:08 PM »
    Bill, if I was new to this forum I'd think you were about 5 years old.

    The correct grammar: "if I were" not "if I was"

    Example?  What post and statement are you referring to?

    Thanks for the kind words.
    Bill Richardson

    kpac

    • Web moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: Rename/replace
    « Reply #32 on: December 31, 2009, 05:12:13 PM »
    Sorry, I'm not getting involved in your mind games.

    BillRichardson



      Intermediate

      Thanked: 15
      Re: Rename/replace
      « Reply #33 on: December 31, 2009, 05:13:18 PM »
      We've given the working code to the OP, he has used it but questions how it works. We (ST and I) have explained the code and the OP has left. No need to bump a dead topic.

      Only the original poster can ever benefit from the code.
      Bill Richardson

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Rename/replace
      « Reply #34 on: December 31, 2009, 05:18:25 PM »
      Only the original poster can ever benefit from the code.

      err...


      THAT'S THE POINT!
      I was trying to dereference Null Pointers before it was cool.

      Salmon Trout

      • Guest
      Re: Rename/replace
      « Reply #35 on: December 31, 2009, 05:27:31 PM »
      The correct grammar: "if I were" not "if I was"

      Subjunctive often overlooked these days, esp. in Leftpondia.

      ghostdog74



        Specialist

        Thanked: 27
        Re: Rename/replace
        « Reply #36 on: December 31, 2009, 05:29:17 PM »
        We've given the working code to the OP, he has used it but questions how it works.
        ok, maybe i am blind, but which post was it that he questions the code provided??

        Quote
        We (ST and I) have explained the code and the OP has left. No need to bump a dead topic.
        that's not really correct. the way i see it, a topic can be "bumped" IF there are other ways, or better ways to solve the problem. this is a forum remember? There's no way you can dictate Mr A's or Mr B's solution is the one and only. And what do you mean dead topic? This thread is not more than 3 days old...

        Salmon Trout

        • Guest
        Re: Rename/replace
        « Reply #37 on: December 31, 2009, 05:31:01 PM »
        GD74, we're having a whack at Billrich. Whose side are you on?

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Rename/replace
        « Reply #38 on: December 31, 2009, 05:40:30 PM »
        I've considered seeing things from Ol' rich's point of view.

        Really, I have.

        I struggled for hours.

        But no matter what I did...

        I simply could not get my head that far... (it goes on, but I'll let your imaginations fill in the missing portion!)

        Also, the calendar stating "new years day" doesn't bring back the patience I lost.
        I was trying to dereference Null Pointers before it was cool.

        ghostdog74



          Specialist

          Thanked: 27
          Re: Rename/replace
          « Reply #39 on: December 31, 2009, 05:50:17 PM »
          GD74, we're having a whack at Billrich. Whose side are you on?

          lol, ST, i am not siding anyone. just looking at facts as i already mentioned.
          Maybe i have missed something, but whatever it is, let's just chill for today ok? Enjoy it as much as we can, and tomorrow is a better day.

          one stupid guy

            Topic Starter


            Greenhorn

            Re: Rename/replace
            « Reply #40 on: January 04, 2010, 09:40:37 AM »
            I never meant to start a little war, I just wanted to rename some files. My thanks to all who provided input. I'm no hippy, but I hope there is peace in 2010, be it here on this forum and worldwide.

            Now, back to my original issue. I've been working with the solution provided first (thanks to Salmon Trout and Helpmeh). As I "get" some of the coding, I've been able to follow/understand it a bit better. Yes I want to rename these files, but I also want to learn a skill that I can apply to other situations in the future. The additional elucidation on the meaning of each element of the code has been infinitely useful (please keep it coming).

            Still, I'm missing something clearly. I took a three files as a test, and put them into a folder;

            File_1_test.txt
            File_2_test_.txt
            _File_3_test.txt

            all now reside in C:/test

            In the end, I want the files to be named:
            File 1 test.txt
            File 2 test.txt
            File 3 test.txt

            I'm using WinXP, so I used the DOS emulator and navigated to the folder (C:/test). I then typed in the code provided, all in one big long line of input text to the emulator (if I hit enter to mimic the carriage returns in the code provided, it would execute the code only partially or not at all).

            i.e., I literally typed in
            "setlocal enabledelayedexpansion for /f "delims=" %%A in (*.txt) do (set oldname=%%A set newname=!oldname:_= ! ren "!oldname!" "!newname!")"
            Then I hit enter.
            It didn't crap out per se, but it didn't actually do anything. The filenames remain unchanged.


            Take a second to roll your eyes at my ignorance as needed, then please enlightened me if you're willing and able.
            My thanks to all,

            Salmon Trout

            • Guest
            Re: Rename/replace
            « Reply #41 on: January 04, 2010, 10:02:06 AM »
            That is not the way to run the code.

            The code that I posted was intended to be used as a "batch file" or "command script". This is a text file which can be executed. It would have a .bat or .cmd extension. Here is how to run it

            1. Start Notepad
            2. In this page here, highlight the code that follows, click "Edit" in the  the menu at the top and choose "Copy".

            Code: [Select]

            @echo off
            echo Ready to rename files
            echo.
            pause
            echo.
            echo Renaming files...
            echo.
            setlocal enabledelayedexpansion
            for /f "delims=" %%A in (*.txt) do (
                set oldname=%%A
                set newname=!oldname:_= !
                echo Renaming !oldname! to !newname!
                ren "!oldname!" "!newname!"
                )
            echo.
            echo All done
            echo.
            pause

               


            3. Click in Notepad, click "edit" and choose "Paste"
            4. The code should appear in Notepad. I have dressed it up a bit to make it more friendly.
            5. Now, in Notepad, choose File, Save As.. and save it in the folder where the files are that you wish to rename. Call it something with a .bat extension for example MyRename.bat. Don't call it Rename.bat!
            6. Open Windows Explorer in the folder where the files are.
            7. Double click the icon for the batch file you have just saved.

            one stupid guy

              Topic Starter


              Greenhorn

              Re: Rename/replace
              « Reply #42 on: January 04, 2010, 10:16:37 AM »
              Totally cool. I figured I was missing something painfully obvious.
              I appreciate the recipe.

              I created the .bat file as directed (I think), placed it in the c:/test directory with the three test files, and I got the following:
              "The system cannot find the file *.txt."

              What did I miss this time?

              Salmon Trout

              • Guest
              Re: Rename/replace
              « Reply #43 on: January 04, 2010, 10:19:30 AM »
              My mistake!!! Sorry

              Code: [Select]
              @echo of
              echo Ready to rename files
              echo.
              pause
              echo.
              echo Renaming files...
              echo.
              setlocal enabledelayedexpansion
              for /f "delims=" %%A in ( 'dir /b *.txt' ) do (
                  set oldname=%%A
                  set newname=!oldname:_= !
                  echo Renaming !oldname! to !newname!
                  ren "!oldname!" "!newname!"
                  )
              echo.
              echo All done
              echo.
              pause
                 

              one stupid guy

                Topic Starter


                Greenhorn

                Re: Rename/replace
                « Reply #44 on: January 04, 2010, 10:42:02 AM »
                Call me crazy, but that's really cool. It works, pure and simple.
                Many, many thanks.

                To further my understanding, what does the switch b do (/b)?

                Now, just to be picky, I'd love to have certain [first] letters capitalized.

                For example, if the files are currently as below:
                file 1 - test one.txt
                File 2 - test two.txt
                file 3 - test three.txt

                I would like:
                File 1 - Test one.txt
                File 1 - Test two.txt
                File 1 - Test three.txt

                Please don't waste further time on my trivial problems, but if you have a ready solution I'd happily take it, along with an understanding of how/why it works, so that I can learn.


                Again, my gratitude.