'KD- 0 Posted July 26, 2018 Report Share Posted July 26, 2018 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. Link to post Share on other sites
Tim§id€ 5 Posted July 26, 2018 Report Share Posted July 26, 2018 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. ...º(>_<)º... Link to post Share on other sites
Timóteo nkawa 4 Posted July 28, 2018 Report Share Posted July 28, 2018 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. Link to post Share on other sites
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