a3deluxe Posted January 23, 2016 at 12:36 AM Report Share #592377 Posted January 23, 2016 at 12:36 AM Boa noite, Precisava de uma ajudinha com o meu código, o programa consiste no seguinte: Inicio o programa, ele verifica se um ficheiro "File1.txt" existe na PenDrive, se existir, copia outro ficheiro de outra directoria para esta PenDrive. // Dim encontrou As Boolean = False For Each drive As DriveInfo In DriveInfo.GetDrives() If File.Exists(String.Format("{0}File1.txt", drive.Name)) Then Thread.Sleep(100) [b] File.Copy("D:\FileB.dbf", "{0}", drive.Name) ---> erro[/b] encontrou = True End If Next If Not encontrou Then MsgBox("Ficheiro não encontrado.. ", MsgBoxStyle.Critical, "Error") End If Dá-me o seguinte erro: " A conversão da cadeia "E:\" para o tipo Boolean não é válida." Obrigado Link to comment Share on other sites More sharing options...
Solution ribeiro55 Posted January 23, 2016 at 01:36 AM Solution Report Share #592379 Posted January 23, 2016 at 01:36 AM Verifica a assinatura do método Copy. Tem 2 overloads: System.IO.File.Copy(String,String) System.IO.File.Copy(String,String,Boolean) '<---- É este overload que está a fazer match 'esclarecendo: System.IO.File.Copy("caminho origem","caminho destino") System.IO.File.Copy("caminho origem","caminho destino","Se existir, escrever por cima?") No teu caso, estás a passar uma String numa assinatura que esperava um Boolean no terceiro parametro, daí indicar que não é possível inferir um boolean de "E:\", e com razão. Altera para: File.Copy("D:\FileB.dbf", String.Format("{0}File1.txt", drive.Name), True) Confirma sempre a assinatura. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
He B TeMy Posted January 23, 2016 at 02:16 AM Report Share #592381 Posted January 23, 2016 at 02:16 AM Posso perguntar para que tens o thread.sleep aí? Link to comment Share on other sites More sharing options...
a3deluxe Posted January 23, 2016 at 09:51 AM Author Report Share #592391 Posted January 23, 2016 at 09:51 AM He B TeMy, foi engano, não preciso dele. Obrigado ribeiro55. funcionou sem problemas. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now