Last active
May 21, 2018 02:25
-
-
Save KenjiOhtsuka/7147806 to your computer and use it in GitHub Desktop.
Script to split text file by some amount of lines. It works on Windows, using JScript. テキストファイルを行単位で分割するスクリプト。Windows で動きます。JScript です。いくつか使われない変数が宣言されてるっぽいですが・・・。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*========================================================== | |
Declaration | |
==========================================================*/ | |
// constants | |
var ForReading = 1; // 読み込み | |
var ForWriting = 2; // 書きこみ(上書きモード) | |
var ForAppending = 8; // 書きこみ(追記モード) | |
var fileName = "File Name"; | |
/*========================================================== | |
実行部 | |
==========================================================*/ | |
splitFile(); | |
ForReading = null; | |
ForWriting = null; | |
ForAppending = null; | |
/*========================================================== | |
Function Declaration | |
==========================================================*/ | |
function splitFile() { | |
var strFolderPath; | |
var objFileSys; | |
var objInFile; | |
var objOutFile; | |
var strScriptPath; | |
var strRecord; | |
var index = 0; | |
objFileSys = new ActiveXObject("Scripting.FileSystemObject"); | |
strScriptPath = String(WScript.ScriptFullName).replace(WScript.ScriptName,""); | |
objInFile = objFileSys.OpenTextFile(strScriptPath + fileName, ForReading); | |
try { | |
var i, writingSize; | |
do { | |
index++; | |
objOutFile = objFileSys.CreateTextFile(strScriptPath + "out" + index.toString() + ".txt", true); | |
for (i = 0; i < 1000000; i++) { | |
strRecord = objInFile.ReadLine(); | |
objOutFile.WriteLine(strRecord); | |
if (objInFile.AtEndOfStream == true) break; | |
} | |
objOutFile.Close(); | |
} while (objInFile.AtEndOfStream==false); | |
} catch(e) { | |
WScript.echo("Error!"); | |
WScript.echo(strScriptPath + "out" + index.toString() + ".txt"); | |
} finally { | |
objInFile.Close(); | |
objOutFile.Close(); | |
} | |
// discard objects | |
objFileSys = null; | |
objInFile = null; | |
objOutFile = null; | |
strScriptPath = null; | |
strRecord = null; | |
strFolderPath = null; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
初めまして。
上記のスクリプトで、ヘッダーを1行必ず付けて分割するにはどうしたらいいでしょうか?