I wrote a Visual Basic program to run through the list one at a time. I am not a programmer, so don't judge me on this code. It's probably more complicated than it needs to be, but I have a lot of files to convert, so I set it up to create a log file as well as show a little status update for each one. Feel free to use it if you like. Just a note, this is not VBScript, it's Visual Basic. If you want to run it as a VBS you will probably need to make some modifications.
Code: Select all
Option Strict On
Imports System.IO
Module Module1
Sub Main()
Dim fileListPath As String = "c:\DCX_files\filelist.txt" ' List of files to be converted
Dim fileList() As String = IO.File.ReadAllLines(fileListPath) ' Read in file list
Dim fileCount As Integer = fileList.Length ' Count # of files for progress reporting
Dim filesProcessed As Integer = 1 ' File counter
Dim file As String ' Current file selected from the list
Dim fileInfo As System.IO.FileInfo ' To extract filename and pathname
Dim fileName, filePath, outputName, shellCommand As String
Dim procID As Integer ' Just used to capture output of Shell command
Dim logFile As String = "c:\DCX_files\DCX_log.txt" ' Log file pathname
' Write header for log file
My.Computer.FileSystem.WriteAllText(logFile, "Rundate: " & vbDate & vbCrLf, False)
My.Computer.FileSystem.WriteAllText(logFile, "Files to process: " & CStr(fileCount) & vbCrLf, False)
My.Computer.FileSystem.WriteAllText(logFile, "--------------------------------------------" & vbCrLf, False)
' Convert files
For Each file In fileList
' Show current progress
Console.Clear()
Console.Write("Processing file " & CStr(filesProcessed) & "/" & CStr(fileCount) & vbCrLf & vbCrLf)
' Get name and path of current file
fileInfo = My.Computer.FileSystem.GetFileInfo(file)
fileName = fileInfo.Name
filePath = fileInfo.DirectoryName
outputName = filePath & "\" & Left$(fileName, Len(fileName) - 4) & ".pdf"
Console.Write("Converting: " & file & vbCrLf)
Console.Write("Output file: " & outputName)
Console.WriteLine()
' Run NConvert in command shell, wait to finish before processing next file
shellCommand = "c:\nconvert -quiet -xall -multi -out pdf -c 1 -keepfiledate -o """ _
& outputName & """ """ & file & """"
procID = Shell(shellCommand, AppWinStyle.Hide, True, -1)
' Write to log file
My.Computer.FileSystem.WriteAllText(logFile, "Processed: " & file & vbCrLf, True)
filesProcessed += 1
Next
' Write final log entry
My.Computer.FileSystem.WriteAllText(logFile, "--------------------------------------------" & vbCrLf, False)
My.Computer.FileSystem.WriteAllText(logFile, "Processed " & CStr(filesProcessed - 1) & "/" & CStr(fileCount) & " files." & vbCrLf, True)
Console.WriteLine()
Console.Write("Processing complete. Press any key to end.")
Console.ReadKey()
End Sub
End Module