View Single Post
Old 12-25-2009, 04:37 AM   #153
tricos
Junior Member
tricos began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Dec 2009
Device: kindle 2
Vb.Net to make this batch

Hi, I just got a kindle and spent the whole day researching on best way to get my journal articles on this thing... Kinda disappointed with the options, but sopdf is about the best way to get screwed since you're going to be any way you go...

I don't even think he did anything else with it after first creating it... You can't download the exe or see his code on his google site...

Anyways, I just spent a couple hours at 2 am writing something to get all my journal articles from my folders converted so I could copy and paste them on the kindle so I figured I'd drop the code here so someone more motivated than me can maybe run with it, and make it worth a dang other than just a one time thing for myself late at night...


Imports System.IO
Imports System.Text

Public Class Form1

Private Prefix As String = "G:\KindleOut\"

Private Sub btnFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFolder.Click

Try

Dim objFolderDialog As New FolderBrowserDialog()
objFolderDialog.ShowDialog()

Me.txtFolder.Text = objFolderDialog.SelectedPath

Catch ex As Exception

End Try

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click

Try

Me.btnExit.Enabled = False
Dim Path As String = Me.txtFolder.Text

If Not String.IsNullOrEmpty(Path) Then

If Not Directory.Exists(Path.Replace("G:\", "G:\KindleOutput\")) Then
Directory.CreateDirectory(Path.Replace("G:\", "G:\KindleOutput\"))
End If

Dim objDirectory As New DirectoryInfo(Path)
Dim objDirectories As DirectoryInfo() = objDirectory.GetDirectories
If objDirectories.Count > 0 Then
For Each objDir As DirectoryInfo In objDirectories
ProcessDirectory(objDir)
Next
End If

ProcessFiles(objDirectory)

End If

Catch ex As Exception

Finally

Me.btnExit.Enabled = True

End Try

End Sub

Private Sub ProcessDirectory(ByVal objDir As DirectoryInfo)

If Not Directory.Exists(objDir.FullName.Replace("G:\", "G:\KindleOutput\")) Then
Directory.CreateDirectory(objDir.FullName.Replace( "G:\", "G:\KindleOutput\"))
End If

Dim objDirectories As DirectoryInfo() = objDir.GetDirectories()

If objDirectories.Count > 0 Then
For Each objDirectory As DirectoryInfo In objDirectories
ProcessDirectory(objDirectory)
Next
End If

ProcessFiles(objDir)

End Sub

Private Sub ProcessFiles(ByVal objDir As DirectoryInfo)

Dim objFiles As FileInfo() = objDir.GetFiles("*.pdf")

For Each objFile As FileInfo In objFiles

Dim objBoo As New StringBuilder()

With objBoo
.Append(" -i ")
.Append(Chr(34) & objFile.FullName & Chr(34))
.Append(" -o ")
.Append(Chr(34) & objFile.FullName.Replace("G:\", "G:\KindleOutput\") & Chr(34))
End With

If Not File.Exists(objFile.FullName.Replace("G:\", "G:\KindleOutput\")) Then
Process.Start("c:\sopdf.exe", objBoo.ToString())
System.Threading.Thread.Sleep(2000)
' if you don't have something in there to keep it from opening up
' 50 files at once to convert them, then it is going to take 100 times longer
' than if you just have it wait 2 seconds after each one...
End If

Next

End Sub

End Class
tricos is offline   Reply With Quote