Gizmos Freeware Reviews  

Go Back   Gizmo's Freeware Forum > Freeware Forum > I Want a Freeware Program that ...

Reply
 
Thread Tools Display Modes
Old 13. May 2009, 05:37 PM   #11 (permalink)
Full Member
 
Join Date: May 2009
Posts: 49
Default

Quote:
Originally Posted by Jojoyee View Post
A 65MB csv file can now be converted in less than 1 minute depending on the processor.
GREAT!!! Around 3 seconds for a 15 MB csv file. A million thanks!
stregacomandacolor is offline   Reply With Quote
Old 14. May 2009, 11:28 AM   #12 (permalink)
Maestro di Search
 
Jojo Yee's Avatar
 
Join Date: Jul 2008
Posts: 7,845
Default

Some minor touch-up on the codes, and add a feature to browse for a folder containing the csv files. In this way, the Script can be kept in any other folder. Hope this is even better.

Code:
'This VBScript is for converting CSV files to TSV (tab delimited) files by batch.
'Copy and paste it in Notepad and save the file with vbs extension (e.g. CSV2TSV.vbs) 
'Double click CSV2TSV.vbs to do the conversion.
'The converted files will be saved as *.tsv while the original files remain.

Option Explicit
Dim objWsShell, objFSO, objShellAp, objFolder, objFile, objFileTSV, objResult
Dim strPath, strLine, strNewLine, strNewFileName
Dim TotalFilesConverted, FileNameLength

set objWsShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objShellAp = CreateObject("Shell.Application")
Set objFolder = objShellAp.BrowseForFolder(0, "BATCH CONVERSION FROM CSV TO TSV FILES" & vbLf & vbLf _
& "Select a folder containing CSV files for the conversion.", 0, 17)
If objFolder is Nothing Then
	msgBox "No folder is selected for conversion of CSV files."
	WScript.Quit
Else
	strPath = objFolder.Self.Path
	objWsShell.CurrentDirectory = strPath
End if
TotalFilesConverted = 0
For Each objFile In objFSO.getfolder(strPath).Files
	If UCase(Right(objFile.Name, 4)) = ".CSV" Then
		objResult = objWsShell.Popup("Converting " & objFile.Name & " ...",3,"")
		FileNameLength = Len(objFile.Name)-4
		strNewFileName = Left(objFile.Name,FileNameLength) & ".tsv"
		Set objFile = objFSO.OpenTextFile(objFile, 1)
		Set objFileTSV = objFSO.CreateTextFile(strNewFileName)
		Do Until objFile.AtEndOfStream
			strLine = objFile.ReadLine
			If instr(strLine,Chr(34)) =0 Then
				strNewLine = Replace(strLine,",",vbTab)
			Else
				Call LineQuote(strNewLine)
			End if
			objFileTSV.WriteLine strNewLine
		Loop
		objFile.Close
		TotalFilesConverted = TotalFilesConverted +1
		objFileTSV.Close
	End If
Next
If TotalFilesConverted =0 Then
	MsgBox "No CSV files are found for conversion in the folder."
Else
	MsgBox CStr(TotalFilesConverted) + " Files Converted from CSV to TSV."
End if
	
Sub LineQuote(strNewLine)
Dim LineLength, Linepos, blnQuote, Quotepos
LineLength = Len(strLine)
Linepos =1
strNewLine =""
blnQuote = False
Do While Linepos <= LineLength
	Quotepos = instr(Mid(strLine,Linepos,LineLength-Linepos+1),Chr(34))
	If Quotepos =1 Then
		If Linepos < LineLength Then
			If Mid(strLine,Linepos,2) = Chr(34) & Chr(34) and blnQuote Then
				strNewLine = strNewLine & Chr(34)
				Linepos = Linepos +2
			Else 'one quote
				If blnQuote Then
					blnQuote = False
				Else
					blnQuote = True
				End if
				Linepos = Linepos +1
			End if
		Else 'last character
			Linepos = Linepos +1
		End if
	Elseif Quotepos >1 Then
		If blnQuote Then
			strNewLine = strNewLine + Mid(strLine,Linepos,Quotepos-1)
		Else 'not Quote
			strNewLine = strNewLine + Replace(Mid(strLine,Linepos,Quotepos-1),",",vbTab)
		End if
		Linepos = Linepos +Quotepos -1
	Else 'Quotepos =0
		strNewLine = strNewLine + Replace(Mid(strLine,Linepos,LineLength-Linepos+1),",",vbTab)
		Linepos = LineLength +1
	End If
Loop
End Sub
Jojo Yee is offline   Reply With Quote
Old 15. May 2009, 10:46 AM   #13 (permalink)
Full Member
 
Join Date: May 2009
Posts: 49
Smile

Quote:
Originally Posted by Jojoyee View Post
Hope this is even better.
It is!! Thanks!!!
stregacomandacolor is offline   Reply With Quote
Old 17. May 2009, 04:49 AM   #14 (permalink)
Full Member
 
andrews's Avatar
 
Join Date: Apr 2008
Location: Hudson Valley, NY
Posts: 69
Default Way to go Jojoyee

Now that is what I call customer service. I think you should write a small how to article for the main site, include this code and cross link it to some of the appropriate review catagories. I'm sure there are others looking for something like this and they are less likely to stumble upon it in the forums.

Excellent work!
Andy
__________________
Andy - andrews
Editor of Best Stickies and Best FTP
General Know it All (or at least a good faker)
I have an opinion on anything! just ask!
andrews is offline   Reply With Quote
Old 17. May 2009, 10:20 AM   #15 (permalink)
Maestro di Search
 
Jojo Yee's Avatar
 
Join Date: Jul 2008
Posts: 7,845
Default

Quote:
Originally Posted by andrews View Post
... I think you should write a small how to article for the main site, include this code... I'm sure there are others looking for something like this and they are less likely to stumble upon it in the forums.
Thanks Andy for the kind suggestion.
Done here: http://www.techsupportalert.com/cont...iles-batch.htm
Jojo Yee is offline   Reply With Quote
Old 18. May 2009, 09:06 PM   #16 (permalink)
Senior Member
 
FrankO's Avatar
 
Join Date: May 2008
Posts: 275
Default

Outstanding Jojoyee! Very good work!
__________________
Frank
FrankO is offline   Reply With Quote
Old 25. May 2009, 03:21 PM   #17 (permalink)
Maestro di Search
 
Jojo Yee's Avatar
 
Join Date: Jul 2008
Posts: 7,845
Default A small program for Converting CSV to TSV by Batch

For ease of use, I've converted the VBScript to the executable. The download link is available from the article How to Convert CSV to TSV files by Batch. Give it a try.
Jojo Yee is offline   Reply With Quote
Old 23. Dec 2011, 08:02 PM   #18 (permalink)
Member
 
Join Date: Dec 2011
Posts: 1
Default

@Jojoyee:
many thanks for sharing your program with the rest of the world. So far it's the only one I have found which can do batch conversions.

2 suggestions which would make a great program outstanding:

(1) below the DIR selection tree: adding a text box where the DIR path can be pasted (instead of painfully navigating there manually) or - even better - allow a command line parameter like this:
csv2tsv.exe -p "DIRpath"

(2) adding support for multiline fields (which are enclosed and delimited by double quotations marks)


cheers
lovelove is offline   Reply With Quote
Old 03. Oct 2013, 02:53 AM   #19 (permalink)
Member
 
Join Date: Oct 2013
Posts: 1
Default

Is it possible to take the first script you wrote, and makes the "columns" be in a different order?

example
input
Column A B C D

output
Column B A D C
gerikg is offline   Reply With Quote
Old 03. Oct 2013, 04:36 AM   #20 (permalink)
Maestro di Search
 
Jojo Yee's Avatar
 
Join Date: Jul 2008
Posts: 7,845
Default

Quote:
Originally Posted by gerikg View Post
Is it possible to take the first script you wrote, and makes the "columns" be in a different order?

example
input
Column A B C D

output
Column B A D C
It is possible with some changes made to the script if you wish, but this can be quite complicated as it depends on the number of columns you have.
Jojo Yee is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.