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

Author Topic: How to rename the file with file size  (Read 11538 times)

0 Members and 1 Guest are viewing this topic.

itkesavan

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows XP
    How to rename the file with file size
    « on: November 28, 2013, 07:58:58 AM »
    Pleas help me with the command for renameing the file using file size (note: i want to skip the 0KB file).

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: How to rename the file with file size
    « Reply #1 on: November 28, 2013, 04:12:50 PM »
    Supply some more information.

    Is this in a single folder, or a tree of folders?
    Do you want "abc & def.jpg" to become "1,456,213.jpg" ?

    Night



      Greenhorn

      • Experience: Experienced
      • OS: Windows 7
      Re: How to rename the file with file size
      « Reply #2 on: November 29, 2013, 05:33:54 AM »
      Pleas help me with the command for renameing the file using file size (note: i want to skip the 0KB file).

      If I understood you correctly, this is what you're looking for. This will rename all the files that are larger than 0 bytes.

      for /R %t in (*.*) do if %~zt neq 0 ren "%t" new.*
      pause


      Or using a batch file:

      @echo off
      for /R %%t in (*.*) do if %%~zt neq 0 ren "%%t" new.*
      echo.
      echo.
      echo   Done!
      pause


      /R switch is only necessary if you need to do this recursively. Of course, you can change the renaming to something other than "new", and the extension type instead of all extensions.
      « Last Edit: November 29, 2013, 05:46:46 AM by Night »

      itkesavan

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows XP
        Re: How to rename the file with file size
        « Reply #3 on: November 29, 2013, 09:47:43 AM »
        got the logic. files are there in same folder. help in the below with proper code please using the file name and folder name where i have to give what

        file available at d:\test folder,  filename abc*.txt (total 2 file) in this one will be 0KB.

        Please help with batch script

        patio

        • Moderator


        • Genius
        • Maud' Dib
        • Thanked: 1769
          • Yes
        • Experience: Beginner
        • OS: Windows 7
        Re: How to rename the file with file size
        « Reply #4 on: November 29, 2013, 11:06:43 AM »
        Sure smells like homework to me...
        " Anyone who goes to a psychiatrist should have his head examined. "

        itkesavan

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Windows XP
          Re: How to rename the file with file size
          « Reply #5 on: November 29, 2013, 02:43:18 PM »
          not home work needs to do it where i have similar problem where need to do daily...

          itkesavan

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Windows XP
            Re: How to rename the file with file size
            « Reply #6 on: November 30, 2013, 08:35:43 AM »
            any help on this need it urgently... pls

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: How to rename the file with file size
            « Reply #7 on: December 01, 2013, 05:15:58 AM »
            I asked a question on how you want the files named (and Night has provided you with an almost complete solution - it needs the filename format implemented).

            Your description is not clear.

            itkesavan

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows XP
              Re: How to rename the file with file size
              « Reply #8 on: December 01, 2013, 06:05:46 AM »
              I got what night has said but i dont know where to give the folder location and file name

              just tell you what i want

              I have file in D:\test folder, inside this folder there are soo meny files, from that i have to rename abc*.txt (total 2 file) in this one file will be 0KB. so the script needs to skip the 0kb file and rename only the file which has data. hope now you got my request. please help me with clear batch script because the script which night has given in that i dont know where to give floder location and file name.

              Thanks in advance

              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: How to rename the file with file size
              « Reply #9 on: December 01, 2013, 06:17:28 AM »
              .

              itkesavan

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Windows XP
                Re: How to rename the file with file size
                « Reply #10 on: December 01, 2013, 10:19:51 AM »
                not got reply

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: How to rename the file with file size
                « Reply #11 on: December 01, 2013, 10:27:11 AM »
                A big part of solving a problem is being able to describe how a solution would be found. That is way in the old school you would make a sketch of a logical sires of steps that would define the solution. After having made a concise logical outline. the coding becomes easy.

                itkesavan

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Windows XP
                  Re: How to rename the file with file size
                  « Reply #12 on: December 01, 2013, 10:32:35 AM »
                  I m a starter on batch script just learning. needs this urgently....

                  Lemonilla



                    Apprentice

                  • "Too sweet"
                  • Thanked: 70
                  • Computer: Specs
                  • Experience: Experienced
                  • OS: Windows 7
                  Re: How to rename the file with file size
                  « Reply #13 on: December 01, 2013, 03:15:01 PM »
                  I m a starter on batch script just learning. needs this urgently....
                  I don't think you are reading the replies.  If you look at different command's help menus you should be able to figure this out.  To see the help menus you need to type the command (Most listed in the 'help' command) with a "/?" following.  You will want to look up 'for','if','ren','dir'.  I have full faith in your ability to read and comprehend these commands.  I wish you luck, but know that the members of this forum do not read minds and cannot understand what you want without you asking.

                  Quote from: patio
                  God Bless the DOS Helpers...
                  Quote
                  If it compiles, send the files.

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: How to rename the file with file size
                  « Reply #14 on: December 01, 2013, 10:23:18 PM »
                  This command line based on Night's code should work.

                  for %t in (d:\temp\abc*.txt) do if %~zt neq 0 ren "%t" "new name%~xt"

                  Please provide a good explanation in future and people might be more inclined to help.
                  If you look at your subject line and first post it looks like you want to rename filenames with the filesize.

                  itkesavan

                    Topic Starter


                    Rookie

                    • Experience: Beginner
                    • OS: Windows XP
                    Re: How to rename the file with file size
                    « Reply #15 on: December 10, 2013, 06:36:46 AM »
                    Hi i tried with below batch script it is not working. from next time i will try to give better explain

                    @echo off
                    D:
                    cd temp
                    for /R %%t in (D:\temp\abc*.txt) do if %%~zt neq 0 ren "%%t" "new name%~xt"
                    echo.
                    echo   Done!
                    pause

                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Re: How to rename the file with file size
                    « Reply #16 on: December 10, 2013, 06:48:48 AM »
                    One of your % signs is not doubled.


                    itkesavan

                      Topic Starter


                      Rookie

                      • Experience: Beginner
                      • OS: Windows XP
                      Re: How to rename the file with file size
                      « Reply #17 on: December 10, 2013, 07:05:43 AM »
                      Hi I tried with below batch script, it is not working. Sorry for that from next time i ill explain better.

                      @echo off
                      D:
                      cd temp
                      for /R %%t in (D:\temp\abc*.txt) do if %%~zt neq 0 ren "%%t" "new name%~xt"
                      echo.
                      echo   Done!
                      pause


                      itkesavan

                        Topic Starter


                        Rookie

                        • Experience: Beginner
                        • OS: Windows XP
                        Re: How to rename the file with file size
                        « Reply #18 on: December 10, 2013, 07:40:20 AM »
                        Sorry next time i ill explain better about problem. I have tried with below bacth script but still it is not working. Pls help me

                        @echo off
                        D:
                        cd temp
                        for /R %%t in (D:\temp\abc*.txt) do if %%~zt neq 0 ren "%%t" "new name%~xt"
                        echo.
                        echo   Done!
                        pause


                        patio

                        • Moderator


                        • Genius
                        • Maud' Dib
                        • Thanked: 1769
                          • Yes
                        • Experience: Beginner
                        • OS: Windows 7
                        Re: How to rename the file with file size
                        « Reply #19 on: December 10, 2013, 07:42:04 AM »
                        Stop repeating yourself...
                        It appears you aren't learning...and just want someone else to do it for you.
                        " Anyone who goes to a psychiatrist should have his head examined. "

                        itkesavan

                          Topic Starter


                          Rookie

                          • Experience: Beginner
                          • OS: Windows XP
                          Re: How to rename the file with file size
                          « Reply #20 on: December 10, 2013, 07:52:08 AM »
                          I am learning only.... when i tried with the solution i m not getting it, so only i m asking help....

                          FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

                          learning now only basics....

                          foxidrive



                            Specialist
                          • Thanked: 268
                          • Experience: Experienced
                          • OS: Windows 8
                          Re: How to rename the file with file size
                          « Reply #21 on: December 10, 2013, 08:38:14 AM »
                          Did you see my comment above? 
                          English may not be your first language but if you don't understand something then ask for clarification and mention which part you don't understand.

                          When a batch file doesn't perform as you expect, then describe what happened and what error messages occurred.  Help us to help you, and be interactive.

                          itkesavan

                            Topic Starter


                            Rookie

                            • Experience: Beginner
                            • OS: Windows XP
                            Re: How to rename the file with file size
                            « Reply #22 on: December 10, 2013, 10:43:31 AM »
                            @echo off
                            D:
                            cd temp
                            for /R %%t in (D:\temp\abc*.txt) do if %%~zt neq 0 ren "%%t" "new name%~xt"
                            echo.
                            echo   Done!
                            pause

                            i need a clarification on the am i missed anything in it. because when I execute noting is happening no error message also.
                            can you correct me on the above where i am wrong

                            Salmon Trout

                            • Guest
                            Re: How to rename the file with file size
                            « Reply #23 on: December 10, 2013, 10:52:16 AM »
                            Quote
                            "new name%~xt"

                            Something wrong here

                            Also after you have fixed that, if there is more than one file in d:\temp that satisfies abc*.txt, only the first will get renamed (to new name.txt), all the others will not be be renamed, and the script will halt at the first such and give an an error message:

                            A duplicate file name exists, or the file
                            cannot be found.




                            itkesavan

                              Topic Starter


                              Rookie

                              • Experience: Beginner
                              • OS: Windows XP
                              Re: How to rename the file with file size
                              « Reply #24 on: December 13, 2013, 06:28:08 AM »
                              yes there are 2 files in it, on that on is 0 KB. the script wat have not renames only the 0 KB file first so that only i m asking help to rename the file with file size so i can skip the 0KB file. but the above script not working pls provide any script or if any correction pls tell me....

                              Night



                                Greenhorn

                                • Experience: Experienced
                                • OS: Windows 7
                                Re: How to rename the file with file size
                                « Reply #25 on: December 15, 2013, 08:16:33 AM »
                                Yeah, I wasn't sure what he was trying to say so I gave him a possible solution.

                                patio

                                • Moderator


                                • Genius
                                • Maud' Dib
                                • Thanked: 1769
                                  • Yes
                                • Experience: Beginner
                                • OS: Windows 7
                                Re: How to rename the file with file size
                                « Reply #26 on: December 15, 2013, 10:56:21 AM »
                                Yeah, I wasn't sure what he was trying to say so I gave him a possible solution.

                                 HuHH ? ?
                                And how exactly did you do that ? ?
                                " Anyone who goes to a psychiatrist should have his head examined. "

                                itkesavan

                                  Topic Starter


                                  Rookie

                                  • Experience: Beginner
                                  • OS: Windows XP
                                  Re: How to rename the file with file size
                                  « Reply #27 on: December 17, 2013, 07:56:58 AM »
                                  Any correction needs to be do on the below. because it is not working.

                                  @echo off
                                  D:
                                  cd temp
                                  for /R %%t in (D:\temp\abc*.txt) do if %%~zt neq 0 ren "%%t" "new name%~xt"
                                  echo.
                                  echo   Done!
                                  pause


                                  Lemonilla



                                    Apprentice

                                  • "Too sweet"
                                  • Thanked: 70
                                  • Computer: Specs
                                  • Experience: Experienced
                                  • OS: Windows 7
                                  Re: How to rename the file with file size
                                  « Reply #28 on: December 17, 2013, 01:49:43 PM »
                                  One of your % signs is not doubled.

                                  A good way to debug is to remove '@echo off', and see what actually is being run.
                                  Quote from: patio
                                  God Bless the DOS Helpers...
                                  Quote
                                  If it compiles, send the files.

                                  itkesavan

                                    Topic Starter


                                    Rookie

                                    • Experience: Beginner
                                    • OS: Windows XP
                                    Re: How to rename the file with file size
                                    « Reply #29 on: December 19, 2013, 08:56:48 AM »
                                    after i remove @echo off
                                    alos it is not showing any error. Please help me with it.

                                    foxidrive



                                      Specialist
                                    • Thanked: 268
                                    • Experience: Experienced
                                    • OS: Windows 8
                                    Re: How to rename the file with file size
                                    « Reply #30 on: December 19, 2013, 09:45:17 PM »
                                    I posted some time back
                                    Quote
                                    One of your % signs is not doubled.

                                    Did you fix that?