Imports System.IO Module modFileFunctions Dim m_TempPath As String = String.Concat(Path.GetTempPath, "PDFUtils\") Public Function TempFilename(ByVal Filename As String) As String Dim di As New DirectoryInfo(m_TempPath) If Not di.Exists Then di.create() Return String.Concat(m_TempPath, Date.Now.Ticks, "\", Filename) End Function Public Sub TempFileCleanup() Dim dirTemp As New DirectoryInfo(m_TempPath) If Not dirTemp.Exists Then Exit Sub ' Clean up previous files For Each fi As FileInfo In dirTemp.GetFiles("*.*", SearchOption.AllDirectories) Try fi.Delete() Catch ex As System.Exception ' Errors might mean a file is locked so just ignore it End Try Next ' Clean up previous directories For Each di As DirectoryInfo In dirTemp.GetDirectories Try di.Delete(True) Catch ex As Exception ' Errors might mean a file is locked in a directory so just ignore it End Try Next End Sub End Module