'KD- Posted July 26, 2018 at 08:27 PM Report #611433 Posted July 26, 2018 at 08:27 PM Olá, estou querendo fazer um programa que deleta pastas, mais estou tento dificuldades nessa parte do código: If System.IO.Directory.Exists("C:\Users\USUÁRIO\AppData\Local\Temp") Then System.IO.Directory.Delete("C:\Users\USUÁRIO\AppData\Local\Temp", True) Else System.IO.Directory.CreateDirectory("C:\Users\USUÁRIO\AppData\Local\Temp") End If End Sub O que posso colocar na parte de "USUÁRIOS" para que ele possa "detectar" automaticamente o nome.
Tim§id€ Posted July 26, 2018 at 09:20 PM Report #611434 Posted July 26, 2018 at 09:20 PM Tens que usar algo deste género https://msdn.microsoft.com/en-us/library/system.io.path.getfullpath(v=vs.110).aspx - GetFulPath, GetPath etc. Porque feito assim hardcoded só funciona no teu computador. ...º(>_<)º...
Timóteo nkawa Posted July 28, 2018 at 08:09 AM Report #611452 Posted July 28, 2018 at 08:09 AM olá amigo! se queres pegar o nome do atual usuário do sistema tente fazer assim: Dim nome = Environment.UserName If System.IO.Directory.Exists("C:\Users\" & nome & "\AppData\Local\Temp") Then System.IO.Directory.Delete("C:\Users\" & nome & "\AppData\Local\Temp", True) Else System.IO.Directory.CreateDirectory("C:\Users\" & nome & "\AppData\Local\Temp") End If espero ter ajudado.
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