すべてのサブフォルダを含む選択したフォルダの属性を変更または削除する方法&ファイル。VB.Net - フォルダの属性を変更する方法サブフォルダとファイルを含む
私は、次のコードを使用:
System.IO.SetAttribute(FolderBrowserDialog1.SelectedPath,IO.FileAttribute.Hidden)
をしかし、それだけで、選択したフォルダは、あなたが再帰的にサブフォルダをループすることができますサブフォルダ&ファイル
すべてのサブフォルダを含む選択したフォルダの属性を変更または削除する方法&ファイル。VB.Net - フォルダの属性を変更する方法サブフォルダとファイルを含む
私は、次のコードを使用:
System.IO.SetAttribute(FolderBrowserDialog1.SelectedPath,IO.FileAttribute.Hidden)
をしかし、それだけで、選択したフォルダは、あなたが再帰的にサブフォルダをループすることができますサブフォルダ&ファイル
はない属性を変更します。私はOSが再帰的にそれをすると思う!
Private Function getAllFolders(ByVal directory As String) As List(of String)
'Create object
Dim fi As New IO.DirectoryInfo(directory)
'Change main folder attribute
System.IO.SetAttribute(directory,IO.FileAttribute.Hidden)
'List to store paths
Dim Folders As New List(Of String)
'Loop through subfolders
For Each subfolder As IO.DirectoryInfo In fi.GetDirectories()
'Add this folders name
Folders.Add(subfolder.FullName)
'Recall function with each subdirectory
For Each s As String In getAllFolders(subfolder.FullName)
Folders.Add(s)
'Change subfolders attribute
System.IO.SetAttribute(s,IO.FileAttribute.Hidden)
Next
Next
Return Folders
End Function
すべてのサブフォルダとファイルは次のように列挙することができます。
If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
Dim di = New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
di.Attributes = di.Attributes Or FileAttributes.Hidden
For Each i In di.EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
i.Attributes = i.Attributes Or FileAttributes.Hidden
Next
End If
別の方法attrib.exeとなります
Dim cmd = "attrib +H """ & FolderBrowserDialog1.SelectedPath.TrimEnd("\"c)
Shell("cmd /c " & cmd & """ & " & cmd & "\*"" /S /D", AppWinStyle.Hide)
私はそれがすべて列挙よりも高速であることを期待ファイルエントリを取得し、それぞれの属性を取得して個別に設定することもできますが、このメソの別の利点デフォルトでは、シェル関数はコマンドが完了するのを待たず、プログラムは待機せずに続行できます。
ユーザーが選んだディレクトリからすべてのサブディレクトリをループする必要があります。再帰的な機能...今すぐ、選択したディレクトリに対してただちに変更します。属性を設定する前に、各ディレクトリとそのファイルを取得し、その属性を設定するループを作成します。 – Codexer