Computer Hope

Microsoft => Microsoft DOS => Topic started by: pamomil605 on March 01, 2020, 02:01:27 AM

Title: Batch expert needed file cannot be for looped because of first symbol
Post by: pamomil605 on March 01, 2020, 02:01:27 AM
I'm having a bit of an issue in the link there is a text file and you will notice that first character is unknown symbol and after batch tries to for loop it only copies that first character and stops there.

Is there a way to tell batch to continue or to warn him before that there is unknown symbol? or even delete it and proceed with the rest of file?

Link to text file:
https://easyupload.io/eknrri

Script:

Code: [Select]
    :: Turn echo off
    @echo off
   
    :: Enable extensions
    SETLOCAL EnableExtensions
    SETLOCAL EnableDelayedExpansion
   
    :: Set input file
    set "InputFile=index.txt"
   
    :: Set output file
    set "OutputFile=output.txt"
 
    :: Check if output file exits if it does delete it
    If Exist "%OutputFile%" Del "%OutputFile%"
   
    :: Loop through input file
    for /F "tokens=* delims=" %%A in ('Type "%InputFile%"') do (
        :: Set line equal to file text
        set line=%%A
   
        echo !line!
    )>>"%OutputFile%"