Results 1 to 9 of 9

Thread: Similar Query over Deleting files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Similar Query over Deleting files

    Hi again,

    I have a directory that contains files and I wish to allow the user to delete them but would it be possible to display a message while the files are bieng deleted because otherwise it looks as if my program has locked up.

    this is the code I'm using for deleting files. Also when the button is clicked to browse to the folder it doesnt always select the correct on. i.e if I have been in another folder it goes straight to that one. any suggestions.

    Thanks
    R

    VB Code:
    1. Private Sub Command5_Click()
    2.  
    3. Dim strFile() As String, strPath As String
    4.     Dim n As Long, nCount As Long
    5.     On Error Resume Next
    6.     With CommonDialog1
    7.    
    8.         .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
    9.         .MaxFileSize = 32767
    10.         .CancelError = True
    11.         .InitDir = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s"
    12.         .DialogTitle = "Select File To Delete"
    13.                                                              
    14.        .ShowOpen
    15.         If Err.Number <> cdlCancel Then
    16.             strFile = Split(.FileName, vbNullChar)
    17.             nCount = UBound(strFile)
    18.             If nCount = 0 Then
    19.                 'Only one file is selected so split up the path and the filename
    20.                 ReDim strFile(1)
    21.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    22.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    23.                 nCount = 1
    24.             End If
    25.             strPath = strFile(0)
    26.             If Right$(strPath, 1) <> "\" Then
    27.                 strPath = strPath & "\"
    28.             End If
    29.             For n = 1 To nCount
    30.                     Kill strPath & strFile(n)
    31.            
    32.             Next
    33.         End If
    34.     End With
    35. End Sub

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Similar Query over Deleting files

    You can use the same code as you did with your play list. Update a ProgressBar in the loop, or just change the Caption of a Label showing the file name of the file that is being deleted.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: Similar Query over Deleting files

    After adding many files and the button to write the xml file is clicked it seems to lock up the other command buttons. Do I need something in this code to Kill it or something?.

    VB Code:
    1. Private Sub Command2_Click()
    2. Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
    3.     Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
    4. Dim mysong As String
    5.  
    6.     Dim mytag As Boolean
    7.    mp3path = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s\"
    8.    xmlpath = "C:\Program Files\mgamerz\XML PLAYER\"
    9.  
    10.  
    11.      
    12.      SongName = Dir(mp3path & "\*.mp3")
    13.      fname = mp3path & SongName
    14.      
    15.             With Form4
    16.    
    17.     While Not Len(SongName) = 0
    18.        
    19. '        Artist = GetMP3Tag(fname)
    20.                 If Not i = 0 Then
    21.                     Load .Label1(i): Load .Text1(i)
    22.                     .Label1(i).Top = .Label1(i - 1).Top + 350
    23.                     .Text1(i).Top = .Text1(i - 1).Top + 350
    24.                     .Label1(i).Visible = True: .Text1(i).Visible = True
    25.                    
    26.                 End If
    27.                
    28.                 .Label1(i) = SongName
    29.                 mytag = GetMP3Tag(fname)
    30.                 .Text1(i) = RTrim(MP3Info.sArtist)
    31.                      
    32.  
    33.         SongName = Dir
    34.              fname = mp3path & SongName
    35.  
    36.         i = i + 1
    37.    
    38.     Wend
    39.                 .Height = .Text1(.Text1.Count - 1).Top + 1600
    40.                 .TAG = mp3path
    41.                 MDIForm1.Caption = "Close This Form to Update XML Playlist"
    42.                 .Show
    43. '                .WindowState = 2
    44.             End With
    45.     TAG = "wait"
    46.     While TAG = "wait"
    47.     DoEvents
    48.     Wend
    49.    
    50.      
    51.    i = 1
    52.      f2 = FreeFile
    53.     Open mp3path & "mp3.txt" For Output As #f2
    54.      f1 = FreeFile
    55.      
    56.     Open xmlpath & "audiolist.xml" For Output As #f1
    57.    
    58.    
    59.     Print #f1, "<?xml version=""1.0""?>"
    60.     Print #f1, "<songs>"
    61.     SongName = Dir(mp3path & "\*.mp3")
    62.     i = 1
    63.     While Not Len(SongName) = 0
    64.        
    65.         ' if you can return the name of the artist you put the code in here
    66.  
    67.                mytag = GetMP3Tag(mp3path & SongName)
    68.              'pos = InStr(mytag, "\")
    69.              mytag = Replace(mytag, "\", "/")
    70. Do While InStr(mytag, " ")
    71.   mytag = Replace(mytag, " ", "")
    72. Loop
    73.  
    74.              Artist = RTrim(MP3Info.sArtist)
    75.              If Len(Artist) = 0 Then Artist = "UNKOWN"
    76.                  
    77.                  
    78.               MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath))) & " " & SongName
    79.        
    80.              MyPath = Replace(MyPath, "\", "/")
    81.              
    82.  
    83.            MyPath = Replace(MyPath, " ", "", 1, 1)
    84.            
    85.            mysong = Left$(SongName, Len(SongName) - 4)
    86.  
    87.            
    88.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & mysong & """/> "
    89.  
    90.        
    91.         Print #f1, songpath
    92.         Print #f2, SongName
    93.         Sleep 100
    94.         SongName = Dir
    95.    
    96.     Wend
    97.  
    98.     Print #f1, "</songs>"
    99. Close
    100.  
    101. End Sub

    Thanks
    R

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Similar Query over Deleting files

    While code is executed VB can't handle events unless you put in a DoEvent somewhere in the loop.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: Similar Query over Deleting files

    will that need to go int the code to write XML or would it be easier to display a message while it is doing until it has finished processing

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Similar Query over Deleting files

    For your origional post in this thread you can use the following approach if you like. Download the attached Form and add it to your project and use code simular to this:
    VB Code:
    1. Private Sub Command5_Click()
    2.  
    3.     Dim strFile() As String, strPath As String
    4.     Dim n As Long, nCount As Long
    5.     Dim dlg As frmProgress
    6.  
    7.     On Error Resume Next
    8.     With CommonDialog1
    9.    
    10.         .Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNLongNames
    11.         .MaxFileSize = 32767
    12.         .CancelError = True
    13.         .InitDir = "C:\Program Files\mgamerz\XML PLAYER\my_mp3s"
    14.         .DialogTitle = "Select File To Delete"
    15.                                                              
    16.        .ShowOpen
    17.         If Err.Number <> cdlCancel Then
    18.             Set dlg = New frmProgress
    19.             dlg.Show vbModeless, Me
    20.             DoEvents
    21.             strFile = Split(.FileName, vbNullChar)
    22.             nCount = UBound(strFile)
    23.             If nCount = 0 Then
    24.                 'Only one file is selected so split up the path and the filename
    25.                 ReDim strFile(1)
    26.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    27.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    28.                 nCount = 1
    29.             End If
    30.             strPath = strFile(0)
    31.             If Right$(strPath, 1) <> "\" Then
    32.                 strPath = strPath & "\"
    33.             End If
    34.             For n = 1 To nCount
    35.                 Call dlg.Progress(strPath & strFile(n)
    36.                 Kill strPath & strFile(n)
    37.             Next
    38.             Unload dlg
    39.             Set dlg = Nothing
    40.         End If
    41.     End With
    42. End Sub
    Attached Files Attached Files

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: Similar Query over Deleting files

    for some reason Im getting a syntax error with this line:

    Call dlg.Progress(strPath & strFile(n)

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Similar Query over Deleting files

    Quote Originally Posted by robvr6
    for some reason Im getting a syntax error with this line:

    Call dlg.Progress(strPath & strFile(n)
    Sorry it's missing a paranthesis.
    Call dlg.Progress(strPath & strFile(n))

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: Similar Query over Deleting files

    that wo9rks great but as soon as I click the update xml button it locks everything up - is there anyway I could display something like the egg timer until it is finished - because when its finished processing it should then stop and the other buttons should work shouldn't they or am I totally wrong as usual?

    Thaks
    R

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width