输出到.CSV?

时间:2015-10-20 20:28:11

标签: csv batch-file output

我有一个批处理文件检查项目并检查它,它工作正常但是是否可以制作一个VBS,将我的.txt文件转换为.csv,以便更容易阅读或制作批处理文件直接将其输出到.csv文件?

我的问题是我需要将.txt / .log转换为.csv。

批处理文件

@echo off
title Checkin
color 0a

SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)


cls
:home
cls
call :ColorText 0b "---------------------------------------"
echo.
call :ColorText 74 "-               Welcome               -"
echo.
call :ColorText 0b "---------------------------------------"
echo.
call :ColorText 0a "        Ready, Awaiting Scan...        "
echo.
set /p scan=
cls
call :ColorText 0a "-            Please Wait...           -"
echo.
echo %time% %date% >>%scan%.log
echo %scan% %date% %time% >>master.xml
ping localhost -n 3 >nul
echo.
call :ColorText 0a "-               Success!              -"
echo.
ping localhost -n 2 >nul
goto :home


:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1

输出:

 9:27:14.94 Tue 10/20/2015 
 9:27:22.65 Tue 10/20/2015 
 9:28:37.00 Tue 10/20/2015 

我需要电子表格看起来像:

    Date  |  Time
 DDMMYYYY | HHMMSS

3 个答案:

答案 0 :(得分:1)

@echo off

for /f "delims=." %%a in ('wmic os get LocalDateTime^| findstr [0-9]') do set "$all=%%a"

>>scan.csv echo %$all:~0,8%;%$all:~8%

答案 1 :(得分:0)

格式化时间&amp;日期是区域相关的,因此相应地调整并输出到文件。

FOR /F "tokens=1-3 delims=:" %%G IN ("%TIME: =0%") DO set oTime=%%G%%H%%I

FOR /F "tokens=2-4 delims= /" %%G IN ("%DATE%") DO set oDate=%%G%%H%%I

echo %oDate%,%oTime% >>scan.csv

答案 2 :(得分:-1)

%time%,%date%&gt;&gt; logs.CSV会将其添加到将在execel中打开的.csv文件