[Batch] number of lines in a file

Solved
yusukessj Posted messages 297 Status Member -  
yusukessj Posted messages 297 Status Member -
Hello,

I would like to get the number of lines in my file and check if it's greater than zero or not, but it's not working.
Thank you very much for your help

set /a compt=0 for /f "delims=" %%i in ('type fichier.txt') do set /a compt=1 if %compt% > 0 GOTO :oui :oui echo ouii > C:\wamp\www\batch\oui.txt :end


Configuration: Windows XP SP3
Intel Core 2 Quad q8200 2.33 Ghz
2 Go de RAM
ATI Radeon HD 4670 -- DDR3 -- 1Go

4 answers

  1. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    bonjour
    change this line
    if %compt% LEQ 0 GOTO :end
    0
  2. yusukessj Posted messages 297 Status Member 16
     
    Thank you very much for your help, Dubcek.
    You want to check if my variable is less than or equal to 0, and go to :end

    But if I want to go to the :yes function if that number is greater than or equal to 1
    should I use GEQ?
    0
  3. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    if %compt% GEQ 0 GOTO :oui goto :end :oui echo ouii > C:\wamp\www\batch\oui.txt :end
    0
  4. yusukessj Posted messages 297 Status Member 16
     
    Thank you very much, it works.
    I have a file that contains the absolute path of a file (chemin.txt).

    C:\truc\truc\truc\truc\truc\truc\Aaaa.html.htm

    I would like to extract just the name of my file and put it in a variable.
    I used an awk command that extracts this name and puts it into a file (fichier.txt)

    Here it is and it works:
    awk -F""\\"" "{print $8}" C:\wamp\www\batch\chemin.txt > C:\wamp\www\batch\fichier.txt


    Now when I want to retrieve the content of this file and put it in a variable, it doesn't work. Could you help me with that please?
    I did it like this:

    set /p file= <C:\wamp\www\batch\fichier.txt echo %file% > C:\wamp\www\batch\verifier.txt


    When I open verifier.txt, I find ECHO command is enabled.
    Thank you very much.
    0