?
Solved

Why dosent the file extension change ?

Posted on 2012-09-20
9
Medium Priority
?
420 Views
Last Modified: 2012-09-20
Hi!

Have this vbscript that ADD <CR> of the end of the lines
in a linux file. And save the new file as csv-file

But it dosent change the file extension to csv ?

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "2crlf.vbs"
'*
'* Declare Variables
'*
Dim boo_CR
Dim boo_LF
Dim boo_OK
Dim intARG
Dim strARG
Dim strMSG
strMSG = "Converted files:" & vbCrLf
Dim strOTF
'*
'* Declare Objects
'*
Dim objARG
Set objARG = WScript.Arguments
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOTF
'*
'* Convert Each Drag-and-Drop File
'*
For intARG = 0 to objARG.Count - 1
strARG = objARG(intARG)
strMSG = strMSG & vbCrLf & strARG
If objFSO.FileExists(strARG) Then
'*
'* Read File
'*
Set objOTF = objFSO.OpenTextFile(strARG,1)
strOTF = objOTF.ReadAll()
Set objOTF = Nothing
'*
'* Convert File (if applicable)
'*
boo_CR = False
boo_LF = False
If InStr(strOTF,vbCr) > 0 Then boo_CR = True
If InStr(strOTF,vbLf) > 0 Then boo_LF = True
If boo_CR And boo_LF Then
boo_OK = False
strMSG = strMSG & vbCrLf & vbTab & "(Not Converted)"
ElseIf boo_CR Then
strOTF = Replace(strOTF,vbCr,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted CR)"
ElseIf boo_LF Then
strOTF = Replace(strOTF,vbLf,vbCrLf)
boo_OK = True
strMSG = strMSG & vbCrLf & vbTab & "(Converted LF)"
End If
'*
'* Write File
'*
If boo_OK Then
Set objOTF = objFSO.OpenTextFile(strARG & ".csv",2,True)
objOTF.Write(strOTF)
Set objOTF = Nothing
End If
Else
strMSG = strMSG & vbCrLf & vbTab & "(File Not Found)"
End If
Next
'*
'* Destroy Objects
'*
Set objARG = Nothing
Set objFSO = Nothing
'*
'* Done
'*
MsgBox strMSG,vbInformation,cVBS

Open in new window

0
Comment
Question by:team2005
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:tlayton
ID: 38416976
Looks, to me, like you need to strip the previous extension from your strARG variable before appending the ".csv" extension...

Something like:
Set objOTF = objFSO.OpenTextFile(Substring(strARG, 1, Len(strARG) - 4) & ".csv",2,True)

Open in new window

0
 
LVL 2

Author Comment

by:team2005
ID: 38417101
Hi!

Sorry, dosent help ?
0
 
LVL 2

Author Comment

by:team2005
ID: 38417119
Hi!

The origfile have no extension (linux file)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:tlayton
ID: 38417130
Try closing the file before setting it to nothing?

Like:

objOTF.Write(strOTF)
objOTF.Close
Set objOTF = Nothing

Open in new window

0
 
LVL 2

Author Comment

by:team2005
ID: 38417195
Hi!

I tryed to change line back to _:
Set objOTF = objFSO.OpenTextFile(strARG & ".csv",2,True)
objOTF.Write(strOTF)

Have onother script, that call this... And it have a space before the path:

No its make 2 files, one with no extension and one with csv extension
?????
0
 
LVL 5

Expert Comment

by:tlayton
ID: 38417208
Is that not correct? Isn't the one with no extension your original file and the one with .csv is the new file? Looks that way in your code...
0
 
LVL 5

Accepted Solution

by:
tlayton earned 2000 total points
ID: 38417215
If you want to purely change the extension and remove the original file you can use the following line:

Warning: Make sure the file is saving correctly in .csv before deleting

objFSO.DeleteFile(strArg)

Open in new window

0
 
LVL 2

Author Closing Comment

by:team2005
ID: 38417252
Thanks
0
 
LVL 5

Expert Comment

by:tlayton
ID: 38417287
You're welcome, good luck!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question