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

Author Topic: Removing File Extension from a Filename ...  (Read 69102 times)

0 Members and 1 Guest are viewing this topic.

eagle

    Topic Starter


    Greenhorn
  • Make it an AWESOME DAY!!!!!
    Removing File Extension from a Filename ...
    « on: March 14, 2009, 12:28:53 PM »
    I am currently using batch commands for many functions where normal windows actions are more time consuming.  i.e.  Copying an entire directory (15,000+ files) to a different drive, etc.  I am even using them to back up specific files instead of going through the windows explorer method.

    I have been using batch commands on a beginner to a somewhat intermediate level.

    I have been trying to figure out a way to use batch commands to remove the ".tif" file extension from the file name; but have been failing miserably. >:(

    There are other files in the directory, but I only wish to remove the file extensions from the tiff files.  (i.e.  214G6.tif).  There are instances where I am only doing this for one or 2 files, but it is more often that I am doing this for 5-50 files at a time. 

    Is there such a method?  Or am I needing to use programming to get this job done?

    If I do need to use programming, is there a particular style that may be of greater interest for me to look into?

    macdad-



      Expert

      Thanked: 40
      Re: Removing File Extension from a Filename ...
      « Reply #1 on: March 14, 2009, 12:37:43 PM »
      No its possible in batch.

      Code: [Select]
      @echo off
      echo Remove Extension from What file(include extension)?
      set /p file=?
      set noext=%file:~0,-4%
      ren %file% %noext%
      echo Done
      pause

      Hope this Helps
      ,Nick(macdad-)
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      Dias de verano

      • Guest
      Re: Removing File Extension from a Filename ...
      « Reply #2 on: March 14, 2009, 12:56:25 PM »
      Quote
      set noext=%file:~0,-4%

      Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore.

      eagle

        Topic Starter


        Greenhorn
      • Make it an AWESOME DAY!!!!!
        Re: Removing File Extension from a Filename ...
        « Reply #3 on: March 14, 2009, 01:44:05 PM »
        Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

        Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?

        devcom



          Apprentice

          Thanked: 37
          Re: Removing File Extension from a Filename ...
          « Reply #4 on: March 14, 2009, 01:53:03 PM »
          here is other script with drag and drop feature:
          Code: [Select]
          @echo off
          SETLOCAL ENABLEDELAYEDEXPANSION

          set fName=%1
          if '%1' equ '' set /p fName=Enter file name:
           
          for /f "tokens=* delims= " %%F in ('echo %fName%') do (
          echo REN %%~nxF %%~nF
          )

          pause

          if its working just change echo REN to REN
          Download: Choice.exe

          eagle

            Topic Starter


            Greenhorn
          • Make it an AWESOME DAY!!!!!
            Re: Removing File Extension from a Filename ...
            « Reply #5 on: March 14, 2009, 02:00:29 PM »
            Thank You for your added input. 

            Is there a way to drag & drop multiple files for the task to be performed at one time?

            or ...

            for the batch command to automatically seek out ALL .tif file extensions, then rename them for me.
            « Last Edit: March 14, 2009, 02:24:36 PM by eagle »

            devcom



              Apprentice

              Thanked: 37
              Re: Removing File Extension from a Filename ...
              « Reply #6 on: March 14, 2009, 02:08:47 PM »
              you just drag your file over the script.bat file and it renames it automatically

              Quote
              Is there a way to isolate the tif files only? ... Or does this remove file extensions for ALL files?
              and by the isolate files you can use
              Code: [Select]
              dir /b C:\path\to\files\*.tif
              Download: Choice.exe

              macdad-



                Expert

                Thanked: 40
                Re: Removing File Extension from a Filename ...
                « Reply #7 on: March 14, 2009, 02:21:42 PM »
                Assumes that extensions have only a dot + 3 chars, no good for .jpeg therefore.

                thats true..but he's using it on a 3 char extension, and:

                Awesome ... TY ... I have been told by SOOOOOO many people that this could not be done.

                If he needed it to do more than just dot + 3 char extensions, i would of re-wrote the code.
                If you dont know DOS, you dont know Windows...

                Thats why Bill Gates created the Windows NT Family.

                eagle

                  Topic Starter


                  Greenhorn
                • Make it an AWESOME DAY!!!!!
                  Re: Removing File Extension from a Filename ...
                  « Reply #8 on: March 14, 2009, 04:52:53 PM »
                  Much appreciation goes out to those helping with this.

                  Well, I got the first recommendation to work.  Unfortunately, having to enter the entire file name is not really time effective.

                  The 2nd recommendation did not work with dragging the file and dropping onto the ".bat" file

                  I did get the 2nd recommendation to work ONLY if I run the batch file, then I am able to drag & drop the file to be changed.  Click on the cmd.exe window; Then Hit enter.

                  I removed the pause, and inserted a call command to loop it. 

                  After I hit enter to remove the .tif, it loops back for the next file to be dragged & dropped. 

                  Here is what I have at this point ...
                  Code: [Select]
                  @echo off
                  SETLOCAL ENABLEDELAYEDEXPANSION

                  set fName=%1
                  if '%1' equ '' set /p fName=Enter file name:

                  for /f "tokens=* delims= " %%F in ('echo %fName%') do (
                  REN %%~nxF %%~nF
                  )

                  call RemoveFileExtension.bat

                  Is there a way to automate things more?

                  ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done.  OR ... Do I have to keep feeding the files one at a time?

                  I must apologize for my lack of understanding here ... it has been more than 20+ years since I did this stuff, or even other forms of programming.  Before finding this website, I have been at my wits end ... LOL
                  « Last Edit: March 14, 2009, 05:14:13 PM by eagle »

                  Dias de verano

                  • Guest
                  Re: Removing File Extension from a Filename ...
                  « Reply #9 on: March 14, 2009, 06:08:39 PM »
                  ideally, I would like to click on the .bat file, then it automatically finds the tiff files in the directory where the bat file is, changes the file names, and I am done. 

                  Code: [Select]
                  for /f "delims==" %%F in ('dir /b *.tif') do ren "%%~nxF" "%%~nF"

                  eagle

                    Topic Starter


                    Greenhorn
                  • Make it an AWESOME DAY!!!!!
                    Re: Removing File Extension from a Filename ...
                    « Reply #10 on: March 14, 2009, 06:48:35 PM »
                    TY TY TY TY ... There's Mundane work, then there is working smart ... Kudos to ALL to have contributed and most importantly were quite patient with me. 8) :D ;D :-* ;)

                    macdad-



                      Expert

                      Thanked: 40
                      Re: Removing File Extension from a Filename ...
                      « Reply #11 on: March 15, 2009, 07:29:42 AM »
                      Anytime  ;)
                      If you dont know DOS, you dont know Windows...

                      Thats why Bill Gates created the Windows NT Family.

                      johnwalter



                        Newbie

                        • Experience: Beginner
                        • OS: Unknown
                        Re: Removing File Extension from a Filename ...
                        « Reply #12 on: August 17, 2012, 06:50:23 AM »
                        Fileviewpro is simplest way to convert or view all types file without any problem so don't wasting your time, i think it will be great move to use this.

                        « Last Edit: August 17, 2012, 09:30:55 AM by patio »

                        patio

                        • Moderator


                        • Genius
                        • Maud' Dib
                        • Thanked: 1769
                          • Yes
                        • Experience: Beginner
                        • OS: Windows 7
                        Re: Removing File Extension from a Filename ...
                        « Reply #13 on: August 17, 2012, 09:30:41 AM »
                        The Topic is over 3 years old...

                        SPAM link removed.
                        " Anyone who goes to a psychiatrist should have his head examined. "