I have created this function to help my colleague for a problem. The goal
is to search and find a folder and finally create a folder inside. Simple but very useful
You can also modify to achieve your own goal.
It was tested on Windows 8.x , but must work on Windows 7 , Vista and XP, (Windows Server too)
is to search and find a folder and finally create a folder inside. Simple but very useful
You can also modify to achieve your own goal.
It was tested on Windows 8.x , but must work on Windows 7 , Vista and XP, (Windows Server too)
' ' Script Created by Lucky Chris ATTOH-TOURE - System & Virtualization Engineer ' Search and find a folder | Create Folder also ' 2014 - August 26 Public HiddenState 'Function check folder attributes Public Function CheckAttribute(ValueF) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") NewValue = Replace(ValueF,"\","\\") Set colFolders = objWMIService. _ ExecQuery("Select * from Win32_Directory where name = '" + NewValue + "' ") For Each objFolder in colFolders HiddenState = objFolder.Hidden if (HiddenState = 0) then HiddenState = "False" Else HiddenState = "True" Next End Function ' Public Function ShowSubfolders(Folder) 'Folder you want to find strFlag = "Documents" For Each Subfolder in Folder.SubFolders on error resume next Set fFolder = fso.GetFolder(Subfolder.Path) CheckAttribute(Subfolder.Path) if (((StrComp(Subfolder.Name, strFlag, vbTextCompare)) = 0) AND (HiddenState = "False"))then wscript.echo Subfolder.Path wscript.echo HiddenState If (fso.FolderExists(Subfolder.Path + "\\TESTFOLDER")) Then 'wscript.echo "Le repertoire existe" wscript.quit else set r = fso.CreateFolder( Subfolder.Path + "\\TESTFOLDER") end if wscript.quit end if if err.number <> 0 then wscript.echo err.description ShowSubfolders Subfolder Next End Function set fso = CreateObject("Scripting.FileSystemObject") Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") strComputer = "." Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") For Each os in oss OSv = os.Version Next Set wshShell = CreateObject( "WScript.Shell" ) USERNAME = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) OSv = Split(OSv,".") 'Windows Vista ,8 + : OSv => OS Version If (OSv(0) >= 6) then If (fso.FolderExists("C:\\Users\\" + USERNAME + "\\Documents")) Then 'Put the initial folder or drive (C: or D:) ShowSubfolders fso.GetFolder("D:\") else set r = fso.CreateFolder( "C:\\Users\\" + USERNAME + "\\Documents") ShowSubfolders fso.GetFolder("D:\") end if end if