Jump to content
'KD-

Excluir Diretório na pasta de usuários

Recommended Posts

'KD-

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.

Share this post


Link to post
Share on other sites
Tim§id€

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.

 


...º(>_<)º...

Share this post


Link to post
Share on other sites
Timóteo nkawa

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.