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

Author Topic: 2 question: for loop and accented letters  (Read 3754 times)

0 Members and 1 Guest are viewing this topic.

KiTiK

    Topic Starter


    Greenhorn

    2 question: for loop and accented letters
    « on: March 12, 2010, 07:58:53 AM »
    Hello evryone,
    this is KiTiK, i'm new here. And I'm new in batch scripting.
    I read how for loop works both typing for /? in dos and in the article on this site.
    But I still have some problem to get it entirely.
    My purpose is to check if the command tasklist exist, and to do it i wrote this code:
    Code: [Select]
    for /f "tokens=1,* delims=;" %%a in ("%PATH%") do (
    if exist %%a\tasklist.exe (echo there is) else (echo there is not)
    )
    this is good if the first entry in %path% is the system32 folder but i would like to check also in the other entries, but i connot understand how to do it without knowing the number of entries. Could you help me to understand it? It's puzzleing me

    Another simple question: how can my bat echo accented letters (è, ò, ù) properly? I didn't find a solution searching in google.
    Thanks in advance and sorry for my bad English

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: 2 question: for loop and accented letters
    « Reply #1 on: March 12, 2010, 08:57:33 AM »
    Quote
    this is good if the first entry in %path% is the system32 folder but i would like to check also in the other entries, but i connot understand how to do it without knowing the number of entries.

    The is no need to know the number of entries in the path. You can use the $Path notation which will search the entire path until a match is found:

    Code: [Select]
    @echo off
    for %%a in (tasklist.exe) do if not "%%~$PATH:a"=="" echo %%~$PATH:a
    )

    $Path will only search until a match is found. If you have multiple copies of a program, the snippet will echo only the first to the console.

    Quote
    Another simple question: how can my bat echo accented letters (è, ò, ù) properly? I didn't find a solution searching in google.

    Not to familiar with this, but I think you can use  the chcp command.

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

    -- Albert Einstein

    KiTiK

      Topic Starter


      Greenhorn

      Re: 2 question: for loop and accented letters
      « Reply #2 on: March 12, 2010, 11:36:05 AM »
      really nice! I thought I should use $Path, but I put it in the wrong place, after the "IN".
      Thanks, even if I'd like to ask you some explanation about the for loop, I use it in C programming, but it seems so different... I can not get it's logic, could you tell me something about it, please?

      About the second question I think I'll use this notation: e', o', u' :D

      Salmon Trout

      • Guest
      Re: 2 question: for loop and accented letters
      « Reply #3 on: March 12, 2010, 11:40:57 AM »

      $Path will only search until a match is found. If you have multiple copies of a program, the snippet will echo only the first to the console.

      Not to familiar with this, but I think you can use  the chcp command.

      Good luck.  8)

      To echo accented characters the command environment needs to be using a "codepage" which has them in its character set. For the characters which you find in French and Spanish I use code page 1252 which you can select by

      chcp 1252

      at the prompt.

      The code page you are currently in can be seen by typing chcp without a number.



      KiTiK

        Topic Starter


        Greenhorn

        Re: 2 question: for loop and accented letters
        « Reply #4 on: March 12, 2010, 02:13:36 PM »
        Thanks for the tip Salmon Trout, but I tried it and I still get this symbol: þ instead of è.
        Perhaps I have to specify something else in the echo command, but what?
        Anyway thank you very much

        Salmon Trout

        • Guest
        Re: 2 question: for loop and accented letters
        « Reply #5 on: March 12, 2010, 02:28:26 PM »
        Thanks for the tip Salmon Trout, but I tried it and I still get this symbol: þ instead of è.
        Perhaps I have to specify something else in the echo command, but what?
        Anyway thank you very much

        what do you see when you type chcp at the prompt?


        KiTiK

          Topic Starter


          Greenhorn

          Re: 2 question: for loop and accented letters
          « Reply #6 on: March 12, 2010, 02:30:00 PM »
          before i used chcp 1252 it was 850

          Helpmeh



            Guru

          • Roar.
          • Thanked: 123
            • Yes
            • Yes
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 8
          Re: 2 question: for loop and accented letters
          « Reply #7 on: March 12, 2010, 03:42:16 PM »
          There's a different solution to what sidewinder is getting at, without changing any settings.

          Open up MS-Word, put in your special characters, and click file > save. In the save menu, select Plain Text format (the one that says .txt). Then make sure the encoding is set to MS-DOS. If any letters are red, then they can't be used that way.
          Where's MagicSpeed?
          Quote from: 'matt'
          He's playing a game called IRL. Great graphics, *censored* gameplay.

          KiTiK

            Topic Starter


            Greenhorn

            Re: 2 question: for loop and accented letters
            « Reply #8 on: March 16, 2010, 04:57:29 AM »
            There's a different solution to what sidewinder is getting at, without changing any settings.

            Open up MS-Word, put in your special characters, and click file > save. In the save menu, select Plain Text format (the one that says .txt). Then make sure the encoding is set to MS-DOS. If any letters are red, then they can't be used that way.
            Thanks Helpmeh, I did it and I noticed that mu special characters changes after I saved in that way. So, I guess, this is the problem. I wonder how and why the same special characters are well echoed for example in the for /? command... Is there a way to print characters with their ascii code, perhaps? I don't know. If this is possible this could solve another my problem I didn't speak about yet :D
            Anyway, thanks for helping me

            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: 2 question: for loop and accented letters
            « Reply #9 on: March 16, 2010, 09:04:14 AM »
            I was able to paste è,ò, and ù into command prompt without changing anything...
            I was trying to dereference Null Pointers before it was cool.

            Salmon Trout

            • Guest
            Re: 2 question: for loop and accented letters
            « Reply #10 on: March 16, 2010, 12:28:08 PM »
            I was able to paste è,ò, and ù into command prompt without changing anything...

            Code: [Select]
            C:\Windows\system32>chcp
            Active code page: 850

            C:\Windows\system32>echo Nuages en début de journée
            Nuages en début de journée