1行のデータを含む、または空白のテキストファイルのグループがあります。 1つのファイルにダンプするには、それらのファイルをすべて必要とします。その部分は簡単ですが、新しいファイルに "Nodata"または同様の文字列を返すために空のファイルが必要です。バッチ:null値をチェックしてその場所に文字列を書き込む
setlocal enabledelayedexpansion
type nul >C:\somedirectory\DataAll.txt
REM Find all files in a direcotry; for those files
for %%G in (C:\somedirectory\txt??.txt) do (
REM Find all of the text within the found files
for /f "tokens=*" %%T in ('type "C:\somedirectory\%%~nG.txt"') do (
set DataIn=%%T
REM Check to see if the file is empty and write NoData the final variable to it if so
if "C:\somedirectory\%%~nG.txt" LSS 1('set "/a DataIn=Nodata"')
REM Check to see if file is not empty and write the data to the final variable
if "C:\somedirectory\%%~nG.txt" NEQ 0 ('set /a "DataIn=%%T"')
REM Write DataIn to final text file
>> "C:\somedirectory\DataAll.txt" echo !DataIn!
)
)
endlocal
これは、前のテキストファイルのデータを空白に複製します。たとえば、txt1にxxx、xxx、xxがある場合、 txt2は空白です。そしてtxt3は、x、xは、datallファイルが読み込まれます。X:
XXX、XXX、XX
XXX、XXX、xxを
X、X、X
方法DataInを別の文字列に設定しますか?
このコードではどうなっていると思いますか? 'if" C:\ somedirectory \ %%〜nG.txt "LSS 1"。これは間違いなくファイルのサイズをチェックしていません。 – Squashman
'SET'コマンドの'/A'オプションは、数学的演算に使用されます。なぜあなたはそれを使用していますか? – Squashman
ファイルのサイズをチェックしていないことを知っておくとよいでしょう。私は何か間違っている。私は/ aと/ pの両方で遊んだ。/aは私に何かエラーを与えていないものです。私はそれが数学的だと気づいていませんでした。 – gorillabut