Windows Batch script * (star) read as text?

后端 未结 1 1542
日久生厌
日久生厌 2021-01-26 08:20

I\'m writing a batch script to convert a fixed-width text file to .csv format. Here\'s what I\'ve written so far:

@echo off
setlocal enabledelayedexpansion


            


        
相关标签:
1条回答
  • 2021-01-26 09:01

    for /f expects a single file name and is not capable of using wildcards. Use another plain for around:

    for %%X in (HRV*.txt) do (
      for /F "tokens=*" %%A in (%%X) do (
        ... etc. etc.
      )
    )
    

    by the way: your way of redirecting is very slow. The destination file is opened, one line is written and the file is closed again. Opening and closing a file is very time consuming. You can avoid it by opening and closing it just one time. Instead of:

    for /l %%a in (1,1,10000) do (
      echo something>>file.txt
    )
    

    which needs about 27 seconds, do:

    (
      for /l %%a in (1,1,10000) do (
        echo something
      )
    )>file.txt
    

    which needs about 170 ms. (Ymmv - times depends on your computer system)

    0 讨论(0)
提交回复
热议问题