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

Author Topic: Trying to change file extensions  (Read 2313 times)

0 Members and 1 Guest are viewing this topic.

Krippers

    Topic Starter


    Starter

    Trying to change file extensions
    « on: July 14, 2008, 09:10:54 AM »
    Hi there. I have a tool that will process images from one format to another. I have the list of filenames to be processed but I'm having difficulty in getting the batch file to run properly the code is:
    Code: [Select]
    for /F "delims=," %%a in (imagelist.lst) do (
    set oldname = %%a
    set newname =%oldname:.*=%
    convert %%a %newname%.jpg
    )

    but it seems that newname does not set correctly. any Ideas?

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Trying to change file extensions
    « Reply #1 on: July 14, 2008, 09:28:30 AM »
    Be very careful about introducing spaces in a set command. Spaces are actual characters.

    The star (*) on the set newname statement does not act as a wildcard. You'll need to spell out exactly what the extension is, or parse the file name to extract the information.

    Good luck.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Krippers

      Topic Starter


      Starter

      Re: Trying to change file extensions
      « Reply #2 on: July 14, 2008, 09:34:22 AM »
      Thanks, I changed the spacing and got a better response but it's still reading in a value for newname that was set outside the script. Is there a better way of stripping any extension and replacing it with .jpg ?

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Trying to change file extensions
      « Reply #3 on: July 14, 2008, 11:29:34 AM »
      What is confusing the the comma delimiter. If you have one image name per line then this should work:

      Code: [Select]
      for /F "tokens=1-2 delims=." %%a in (imagelist.lst) do (
      convert %%a.%%b %%a.jpg
      )

      The for statement reads one line from the input file on each loop. If you have multiple image names separated by commas on each line, you'll need to parse the entire line. This will involve rethinking the structure of the batch file.

       8)

      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Krippers

        Topic Starter


        Starter

        Re: Trying to change file extensions
        « Reply #4 on: July 15, 2008, 02:18:32 AM »
        Thanks sidewinder, I appreciate the help :D

        I'm new to DOS scripting, coming from UNIX it's hard  ???

        OK, I can reformat the input file, at the moment it looks like this :
        Code: [Select]
        Test.eps,
        one.png,
        two.eps,

        So I'm going to knock out the end comma and try your solution on:
        Code: [Select]
        Test.eps
        one.png
        two.eps

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Trying to change file extensions
        « Reply #5 on: July 15, 2008, 03:38:03 AM »
        There is no need to change your data. A simple tweak of the batch code will account for the comma:

        Code: [Select]
        for /F "tokens=1-2 delims=.," %%a in (imagelist.lst) do (
        convert %%a.%%b %%a.jpg
        )

        Good luck.  8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Krippers

          Topic Starter


          Starter

          Re: Trying to change file extensions
          « Reply #6 on: July 15, 2008, 04:10:51 AM »
          Sidewinder you superstar !!!!  8) 8) 8) Thanks that worked perfectly.

          I really appreciate the help. Cheers :D