输出到.CSV?
问题描述:
我有一个批处理文件,检查一个项目,并检查出来,它工作正常,但是有可能做一个VBS,将我的.txt文件转换为.csv,因此它更容易阅读或使批处理文件直接输出到.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
答
%的时间%,%DATE%>> logs.CSV将它添加到.csv文件将在EXECEL
答
格式化时间&日期是区域性依赖如此调整并相应地输出到一个文件。
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
答
@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%
打开,所以你有时间/日期格式的问题吗? – npocmaka
1. CSV看起来像'DDMMYYYY,HHMMSS'; 2.'%DATE%'&'%TIME%'返回依赖于区域的日期/时间格式,所以你需要'wmic OS GET LocalDateTime' ... – aschipfl
check [this](http://stackoverflow.com/ a/19799236/388389),了解日期/时间格式与区域设置无关的几种方法。 – npocmaka