xGETSx, если устроит WSH:
Код:
![Выделить весь код](images/misc/selectcode.png)
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim strSourceFile
Dim strTempFile
Dim strContent
If WScript.Arguments.Count = 1 Then
strSourceFile = WScript.Arguments.Item(0)
strTempFile = GetTemporaryName()
With WScript.CreateObject("Scripting.FileSystemObject")
If .FileExists(strSourceFile) Then
With .OpenTextFile(strSourceFile, ForReading)
strContent = .ReadAll
.Close
End With
With .OpenTextFile(strTempFile, ForWriting, True)
.Write Replace(strContent, vbCrLf, vbLf)
.Close
End With
.CopyFile strSourceFile, .BuildPath(.GetParentFolderName(strSourceFile), .GetBaseName(strSourceFile) & ".bak"), True
.CopyFile strTempFile, strSourceFile, True
.DeleteFile strTempFile
Else
WScript.Echo "File [" & strSourceFile & "] not found"
End If
End With
Else
WScript.Echo "Usage: " & WScript.ScriptName & " <Path to source file>"
End If
WScript.Quit 0
'=============================================================================
'=============================================================================
' Серый форум / vbscript: генерация пути для временного файла или папки
' (http://forum.script-coding.com/viewtopic.php?id=1221)
'=============================================================================
Function GetTemporaryName()
Const TemporaryFolder = 2
Dim strTempName
With WScript.CreateObject("Scripting.FileSystemObject")
Do
strTempName = .BuildPath(.GetSpecialFolder(TemporaryFolder), .GetTempName)
Loop While .FileExists(strTempName) Or .FolderExists(strTempName)
End With
GetTemporaryName = strTempName
End Function
'=============================================================================
P.S. Файл читается в память целиком, посему для
гигабайтных текстовых файлов не очень годится.