B4J Question Set windows directory attribute to hidden

T201016

Active Member
Licensed User
Longtime User
Hi,
How can I Set windows directory attribute to hidden ?

Dim jo As JavaObject
jo.InitializeStatic("java.lang.Runtime")
jo.RunMethodJO("getRuntime", Null).RunMethod("exec", Array("attrib +H <path_to_your_file>"))
 
Solution
You could try something like this:
B4X:
    Dim shl As Shell
    Private arguments() As String = Array As String("/C","attrib","+H","e:\_temp\mytest.txt")
    shl.Initialize("shl","C:\WINDOWS\system32\cmd.exe",arguments)
    shl.Run(-1)

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
    Else
        Log("Error: " & StdErr)
    End If
End Sub

OK! Thanks @PaulMeuris for the correct example.
Upvote 0
I understand ok
but my example doesn't work:

[CODE lang="b4x" title="'did not work" highlight="6-5,15-17,20"]Sub Button1_Click
' Dim AppTitle As String = "PhotoGallery"
Dim jo As JavaObject
jo.InitializeStatic("java.lang.Runtime")
' jo.RunMethodJO("getRuntime", Null).RunMethod("exec", Array("attrib +H <"&File.DirData(AppTitle)&"\hiden.txt>")) '----> did not work
jo.RunMethodJO("getRuntime", Null).RunMethod("exec", Array("attrib +H "&File.DirApp&"\hiden.txt")) '----> did not work
xui.MsgboxAsync("OK", "B4X")
End Sub

Sub Button2_Click
Private shl As Shell
Private params As List
params.Initialize
params.Add("attrib +H")
' params.Add("C:\Users\H\Downloads\JSHLL\Objects\hiden.txt") '----> did not work
' params.Add(File.DirApp&"\hiden.txt") '----> did not work
params.Add(File.Combine(File.DirApp,"\hiden.txt")) '----> did not work
shl.Initialize("shl","cmd.exe",params)
shl.WorkingDirectory = "C:\Windows\system32"
' shl.WorkingDirectory = File.DirApp '----> did not work

shl.Run(1000)

Wait For shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
xui.MsgboxAsync("OK", "B4X")
Else
xui.MsgboxAsync(StdErr, "Error:")
End If
End Sub[/CODE]
 
Last edited:
Upvote 0
You could try something like this:
B4X:
    Dim shl As Shell
    Private arguments() As String = Array As String("/C","attrib","+H","e:\_temp\mytest.txt")
    shl.Initialize("shl","C:\WINDOWS\system32\cmd.exe",arguments)
    shl.Run(-1)

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
    Else
        Log("Error: " & StdErr)
    End If
End Sub
 
Upvote 0
You could try something like this:
B4X:
    Dim shl As Shell
    Private arguments() As String = Array As String("/C","attrib","+H","e:\_temp\mytest.txt")
    shl.Initialize("shl","C:\WINDOWS\system32\cmd.exe",arguments)
    shl.Run(-1)

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
    Else
        Log("Error: " & StdErr)
    End If
End Sub

OK! Thanks @PaulMeuris for the correct example.
 
Upvote 0
Solution
Back
Top