Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2018-03-02 14:14:36 +0300
committerHieu Hoang <hieuhoang@gmail.com>2018-03-02 14:14:36 +0300
commit3f66a2fbb216762806a38ab2ef2727ad8b701935 (patch)
tree884796878a14f0b2aefd84541523f7fdc85a79d6
parent91dbe92e2db56f4f3996f8fbc51de4778cad2a0b (diff)
word doc mangling at IMO
-rwxr-xr-xscripts/generic/checkDocx.vbs100
-rwxr-xr-xscripts/generic/docx2doc.vbs102
2 files changed, 202 insertions, 0 deletions
diff --git a/scripts/generic/checkDocx.vbs b/scripts/generic/checkDocx.vbs
new file mode 100755
index 000000000..a64edd902
--- /dev/null
+++ b/scripts/generic/checkDocx.vbs
@@ -0,0 +1,100 @@
+
+Option Explicit
+
+
+Dim wordApp
+Dim fso
+Dim rootPath 'As String
+Dim myFile 'As String
+Dim folder 'As Scripting.folder
+Dim args
+
+Set args = Wscript.Arguments
+rootPath = args(0)
+
+
+Set wordApp = CreateObject("Word.Application")
+Set fso = CreateObject("Scripting.FileSystemObject")
+wordApp.Visible = True
+
+Set folder = fso.GetFolder(rootPath)
+
+ProcessFolder folder
+
+wordApp.Quit
+Wscript.Echo "done"
+
+
+
+Sub ProcessFolder(folder)
+ Dim suffix 'As String
+ Dim prefix 'As String
+
+ 'files
+ Dim files 'As Scripting.files
+ Dim file 'As Scripting.file
+
+ Set files = folder.files
+ For Each file In files
+ 'Wscript.Echo file.Name
+
+ If (StrComp(Left(file.Name, 1), "~") <> 0) And Len(file.Name) > 5 Then
+ suffix = Right(file.Name, 5)
+
+ If StrComp(suffix, ".docx", vbTextCompare) = 0 Then
+ prefix = Left(file.Name, Len(file.Name) - 5)
+
+ Dim oldFilePath 'As String
+ Dim newFilePath 'As String
+
+ oldFilePath = folder.Path + "\" + file.Name
+ newFilePath = folder.Path + "\" + prefix + ".doc"
+ 'Wscript.Echo oldFilePath
+ 'Wscript.Echo newFilePath
+
+ If fso.FileExists(newFilePath) Then
+ Wscript.Echo "Duplicate: " + oldFilePath
+ Else
+ Dim doc 'As Word.Document
+
+ On Error Resume Next
+ Set doc = wordApp.documents.Open(oldFilePath)
+
+ If Err.Number <> 0 Then
+ On Error GoTo 0
+ Wscript.Echo "Error: " + oldFilePath
+ fso.MoveFile oldFilePath, newFilePath
+ Else
+ On Error Goto 0
+ doc.Close 0 'wdDoNotSaveChanges
+ End If
+ End If
+ End If
+
+ End If
+
+ Next
+
+ 'folders
+ Dim subFolder 'As Scripting.folder
+ For Each subFolder In folder.SubFolders
+ 'Wscript.Echo subFolder.Path
+ ProcessFolder subFolder
+
+ If Len(subFolder.Name) > 2 Then
+ suffix = Right(subFolder.Name, 2)
+ If StrComp(suffix, " A") = 0 Or _
+ StrComp(suffix, " C") = 0 Or _
+ StrComp(suffix, " E") = 0 Or _
+ StrComp(suffix, " F") = 0 Or _
+ StrComp(suffix, " R") = 0 Or _
+ StrComp(suffix, " S") = 0 Then
+
+ 'prefix = Left(subFolder.Name, Len(subFolder.Name) - 2)
+ 'subFolder.Name = prefix
+ End If
+ End If
+ Next
+
+End Sub
+
diff --git a/scripts/generic/docx2doc.vbs b/scripts/generic/docx2doc.vbs
new file mode 100755
index 000000000..a91ef5ac2
--- /dev/null
+++ b/scripts/generic/docx2doc.vbs
@@ -0,0 +1,102 @@
+
+Option Explicit
+
+
+Dim wordApp
+Dim fso
+Dim rootPath 'As String
+Dim myFile 'As String
+Dim folder 'As Scripting.folder
+Dim args
+
+Set args = Wscript.Arguments
+rootPath = args(0)
+
+
+Set wordApp = CreateObject("Word.Application")
+Set fso = CreateObject("Scripting.FileSystemObject")
+wordApp.Visible = True
+
+Set folder = fso.GetFolder(rootPath)
+
+ProcessFolder folder
+
+wordApp.Quit
+Wscript.Echo "done"
+
+
+
+Sub ProcessFolder(folder)
+ Dim suffix 'As String
+ Dim prefix 'As String
+
+ 'files
+ Dim files 'As Scripting.files
+ Dim file 'As Scripting.file
+
+ Set files = folder.files
+ For Each file In files
+ 'Wscript.Echo file.Name
+
+ If (StrComp(Left(file.Name, 1), "~") <> 0) And Len(file.Name) > 5 Then
+ suffix = Right(file.Name, 5)
+
+ If StrComp(suffix, ".docx", vbTextCompare) = 0 Then
+ prefix = Left(file.Name, Len(file.Name) - 5)
+
+ Dim oldFilePath 'As String
+ Dim newFilePath 'As String
+
+ oldFilePath = folder.Path + "\" + file.Name
+ newFilePath = folder.Path + "\" + prefix + ".doc"
+ Wscript.Echo oldFilePath
+ 'Wscript.Echo newFilePath
+
+ Dim doc 'As Word.Document
+
+ On Error Resume Next
+ Set doc = wordApp.documents.Open(oldFilePath)
+
+ If Err.Number <> 0 Then
+ On Error GoTo 0
+ Wscript.Echo "Error: " + oldFilePath
+ Else
+ doc.SaveAs2 newFilePath, 0 ' wdFormatDocument
+ On Error Goto 0
+
+ doc.Close 0 'wdDoNotSaveChanges
+
+ On Error Resume Next
+ file.Delete True
+ On Error GoTo 0
+ End If
+
+ End If
+
+ End If
+
+ Next
+
+ 'folders
+ Dim subFolder 'As Scripting.folder
+ For Each subFolder In folder.SubFolders
+ Wscript.Echo subFolder.Path
+ ProcessFolder subFolder
+
+ If Len(subFolder.Name) > 2 Then
+ suffix = Right(subFolder.Name, 2)
+ If StrComp(suffix, " A") = 0 Or _
+ StrComp(suffix, " C") = 0 Or _
+ StrComp(suffix, " E") = 0 Or _
+ StrComp(suffix, " F") = 0 Or _
+ StrComp(suffix, " R") = 0 Or _
+ StrComp(suffix, " S") = 0 Then
+
+ prefix = Left(subFolder.Name, Len(subFolder.Name) - 2)
+ subFolder.Name = prefix
+ End If
+ End If
+ Next
+
+End Sub
+