Help us understand the problem. What is going on with this article?

tsv形式とcsv形式のファイルを相互変換

はじめに

tsvファイル、またはcsvファイルを変換スクリプトファイルにドラッグ&ドロップで相互変換するプログラム

何番煎じかっていう&ゆくゆくは死に言語であるvbsのため、完全に自分用メモ

使い方

1.以下のスクリプトを保存し、拡張子をvbsにする
2.変換したいファイルをドラッグ&ドロップ(複数ファイルの一括ドロップ可)
3.同一ディレクトリに変換後のファイルが出力される

Option Explicit
'*******************************************************************************
'CSV TSV_converter.vbs
'  tsv(タブ区切り)形式とcsv(カンマ区切り)形式を相互変換
'  INPUT : 変換元ファイル(複数可)
'  OUTPUT: 変換元ファイル名.tsv、または変換元ファイル名.csv
'*******************************************************************************

Dim objFSO                        'As Object
Dim objArg                        'As Object
Dim objInput                      'As Object
Dim objOutput                     'As Object
Dim strLine                       'As String
Dim i                             'As int
Dim pathName, fileName, fileExt   'As String
Dim cnvExt, chrBefore, chrAfter   'As String

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objArg = Wscript.Arguments

For i = 0 To objArg.Count - 1
  Set objInput = objFSO.OpenTextFile(objArg(i), 1)                                 'ForReading
  pathName = objFSO.GetFile(objArg(i)).ParentFolder
  fileName = objFSO.GetBaseName(objArg(i))
  fileExt = objFSO.GetExtensionName(objArg(i))

  '拡張子を判定し、区切り文字を指定
  If fileExt = "csv" Then
    cnvExt =".tsv"
    chrBefore = Chr(44)
    chrAfter = Chr(9)
  ElseIf fileExt = "tsv" Then
    cnvExt =".csv"
    chrBefore = Chr(9)
    chrAfter = Chr(44)
  End If

  Set objOutput = objFSO.OpenTextFile(pathName & "\" & fileName & cnvExt, 2, True) 'ForWriting
  Do Until objInput.AtEndOfStream
    strLine = Replace(objInput.ReadLine, chrBefore, chrAfter)
    objOutput.WriteLine (strLine)
  Loop
  objInput.Close
  objOutput.Close
Next 'i

Set objFSO = Nothing
Set objArg = Nothing

Wscript.Quit (0)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away