I'm trying to convert audio files from AU to MP3 that are stored with dropbox. The audio file is downloaded to the dropbox client folder in windows, and then my application would be ran.
While trying to convert the file, I run into file in use issues. So I use this bit of code to determine if its free:
But that wasn't good enough. I would still get issues. So I though, well maybe the file is still downloading so I added a file size check, and I wait for the filesize to stop changing.
When that is detected, I still get file in use related errors. That chunk of code doesn't detect it. I've bashed my head into the wall over this for a long time.
It comes down to this. While the dropbox client program in windows is syncing this freshly downloaded file, I can't do an audio conversion on it because its being uploaded.
I need a better way of testing if a file is free, or I guess to expand on that, I need to know if it is dropbox that is locking the file. All I can do right now is have something pop up saying the file is still in use...do you want to wait for it to free up, or cancel. He clicks the try again button a few times...but due to flaky internet connections it still seems like its the program that isn't work, and that's when I get the phone call saying its still not working.
Here is the whole process :
I know that dropbox offers an API, but i see no reference to visual basic. I also think it is a bit out of the way to do a simple audio conversion.
To beat you to it, I have done some research. There is a program handle.exe, but I don't think I can release it with my software. I have also found many hits regarding a google search "what process is locking my file" but all the solutions are huge, bulky and still seem like I'm going out of my way to do something so simple.
I'm feel VERY defeated by these AU files and dropbox.
Any advice as to what I should do next is very welcome.
Thanks for taking the time to read this.
Nick
While trying to convert the file, I run into file in use issues. So I use this bit of code to determine if its free:
VB.NET:
Public Function FileInUse(ByVal sFile As String) As Boolean
Dim thisFileInUse As Boolean = False
If System.IO.File.Exists(sFile) Then
Try
Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
thisFileInUse = False
End Using
Catch
thisFileInUse = True
End Try
End If
Return thisFileInUse
End Function
But that wasn't good enough. I would still get issues. So I though, well maybe the file is still downloading so I added a file size check, and I wait for the filesize to stop changing.
When that is detected, I still get file in use related errors. That chunk of code doesn't detect it. I've bashed my head into the wall over this for a long time.
It comes down to this. While the dropbox client program in windows is syncing this freshly downloaded file, I can't do an audio conversion on it because its being uploaded.
I need a better way of testing if a file is free, or I guess to expand on that, I need to know if it is dropbox that is locking the file. All I can do right now is have something pop up saying the file is still in use...do you want to wait for it to free up, or cancel. He clicks the try again button a few times...but due to flaky internet connections it still seems like its the program that isn't work, and that's when I get the phone call saying its still not working.
Here is the whole process :
VB.NET:
Sub Convert_List()
For Each Path In ListBox1.Items
Dim cur_file_info = My.Computer.FileSystem.GetFileInfo(Path)
Dim new_file_name As String = cur_file_info.Directory.ToString & "\" & Strings.Left(cur_file_info.Name, cur_file_info.Name.Length - cur_file_info.Extension.Length) & ".mp3"
Dim counter As Integer = 0
Dim last_check_file_size As Integer = 0
Do While FileInUse(cur_file_info.FullName) = True
counter = counter + 1
If counter > 3000 Then
cur_file_info = My.Computer.FileSystem.GetFileInfo(Path)
If cur_file_info.Length > last_check_file_size Then
last_check_file_size = cur_file_info.Length
If frm_Still_DL.Visible = False Then
frm_Still_DL.Show()
frm_Still_DL.Refresh()
Else
frm_Still_DL.BringToFront()
frm_Still_DL.Refresh()
End If
counter = 0
Else
frm_Still_DL.Hide()
counter = 0
Dim ok As Integer = MsgBox("There was a problem, dropbox may still be using the audio file. Click ok to keep waiting (recommended) or click cancel to come back and try later!", MsgBoxStyle.OkCancel)
If ok <> 1 Then
Me.Close()
End If
End If
End If
Loop
frm_Still_DL.Hide()
If My.Computer.FileSystem.FileExists(new_file_name) = False Then
Shell(Application.StartupPath & "\sox.exe " & """" & Path & """" & " " & """" & new_file_name & """", AppWinStyle.MinimizedNoFocus, True)
End If
Do While FileInUse(cur_file_info.FullName) = True
Loop
My.Computer.FileSystem.DeleteFile(cur_file_info.FullName)
Next
MsgBox("All Files Converted!")
End Sub
I know that dropbox offers an API, but i see no reference to visual basic. I also think it is a bit out of the way to do a simple audio conversion.
To beat you to it, I have done some research. There is a program handle.exe, but I don't think I can release it with my software. I have also found many hits regarding a google search "what process is locking my file" but all the solutions are huge, bulky and still seem like I'm going out of my way to do something so simple.
I'm feel VERY defeated by these AU files and dropbox.
Any advice as to what I should do next is very welcome.
Thanks for taking the time to read this.
Nick