Announcement

Collapse
No announcement yet.

Deleting all files in a subdirectory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deleting all files in a subdirectory

    I am trying to delete all .jpg files in a subdirectory.
    The subdirectory path is stored in imagepath

    I have got this in my script

    Dim delimage as String
    delimage = imagepath & "*.jpg"
    System.IO.File.Delete(delimage)

    I am getting this error:

    Error 1 Running script C:\Program Files (x86)\HomeSeer HS3\scripts\MK_SnapshotFrontDoorVisitor.vb :Exception has been thrown by the target of an invocation.Illegal characters in path.

    I guess its not liking the place holder in *.jpg

  • #2
    I think for my application it would be better to just delete the subdirectory. I have tried to run this as a subroutine, calling it from Sub or function window in the event run script

    I have simplifies the script and replaced a lot of code with 'other code' as it is not relevant for this

    Code:
    Imports System.Net.Mail
    Imports System.IO
     Const INI_FILE As String = "MK_Snapshot.ini"
    Const ScriptName As String = "MK_Snapshot"
     Public imagePath As String = ""
    Public imagePath2 As String = ""
    Public isLinux As Boolean
    Public FilesList As New ArrayList
    Public SmtpHost As String = ""
    Public SmtpUserName As String = ""
    Public SmtpPassword As String = ""
    Public SmtpPort As Integer
     
    Sub Main(Optional ByVal Parms As String = "")
         
       other code
        
     End Sub
     Function FixPath(ByVal fpath As String) As String
         
         other code
     End Function
     Function GetSnapshots(ByVal Camera As String, Qty As Integer, DelayMs As Integer) As Boolean
        
     End Function
     Function SendEmail(ByVal MailFrom As String, ByVal MailTo As String, ByVal Subject As String, ByVal Body As String) As Boolean
         other code
     
    End Function
     Sub DelDir(ByVal Parms as Object)
         Dim hsPath As String = hs.GetAppPath
         imagePath = FixPath(hsPath & hs.GetINISetting("Settings", "ImagePath", "", INI_FILE))
         If Len(imagePath) > 0 Then
            imagePath2 = imagePath.Remove(0, 1)
             
         Else
            hs.WriteLog(ScriptName, "Error! Missing ImagePath value in ini file.")
            Exit Sub
        End If
     System.IO.Directory.Delete(imagepath,true)
    hs.WriteLog(ScriptName,  "Directory deleted")
     
    End Sub
    This is sometimes saying Directory deleted in the log, other times I get an error like this:


    Running script C:\Program Files (x86)\HomeSeer HS3\scripts\MK_SnapshotFrontDoorVisitor.vb :Exception has been thrown by the target of an invocation.->Does entry point DelDir exist in script? at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Obj ect obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3f a75582d7a()

    Comment

    Working...
    X