Jump to content

Recommended Posts

Posted

Boa tarde,

Precisava de uma ajuda no meu programa, que serve para proteger pastas.

Queria substituir a FolderBrowserDialog1 pelo caminho final da pasta que pretendo proteger.

Aqui fica o código, para darem uma ajudinha:

//  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


	status = arr(0)


	If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then



		Dim d As DirectoryInfo = New DirectoryInfo(FolderBrowserDialog1.SelectedPath)

		Dim selectedpath As String = d.Parent.FullName + d.Name



		If FolderBrowserDialog1.SelectedPath.LastIndexOf(".{") = -1 Then



			If (Not d.Root.Equals(d.Parent.FullName)) Then

				d.MoveTo(d.Parent.FullName & "\" & d.Name & status)
				MsgBox("pasta Protegida")
			Else

				d.MoveTo(d.Parent.FullName + d.Name & status)
				MsgBox("des")

			End If

			TextBox1.Text = FolderBrowserDialog1.SelectedPath

		Else

			status = getstatus(status)



			d.MoveTo(FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf(".")))

			TextBox1.Text = FolderBrowserDialog1.SelectedPath.Substring(0, FolderBrowserDialog1.SelectedPath.LastIndexOf("."))

			MsgBox("pasta desProtegida")
		End If

	End If
End Sub	

Obrigado

Posted

E não é isso que já estás a fazer com o FolderBrowserDialog1.SelectedPath? Não estou a perceber a tua dúvida.

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"

Posted

Então... basta substituir todos os FolderBrowserDialog1.SelectedPath por a string literal que queres (por exemplo a "c:\pasta1"), e retirar o Show do Dialog.

Se bem que é má ideia, porque ou usas directórios especiais ou não podes garantir que o caminho exista nas máquinas alvo.

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"

Posted (edited)

Agora não estou a conseguir Desproteger a pasta.

Para Proteger funciona bem, para Desproteger coloquei num Button o seguinte código:

//	
	status = arr(0)

		 Dim d As DirectoryInfo = New DirectoryInfo(folder)

	Dim selectedpath As String = d.Parent.FullName + d.Name

	If (d.Root.Equals(d.Parent.FullName)) Then

				   d.MoveTo(d.Parent.FullName + d.Name & status)

		MsgBox("pasta Deprotegida")

	End If 

Não dá erro nenhum e não faz nada.

Acho que pode ter a ver com o nome da pasta, a origem e o destino.

Edited by a3deluxe
Posted

Mete um breakpoint e verifica como ficam os caminhos. É a melhor forma de perceberes o que se passa.

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"

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.