john123 Posted December 23, 2009 Share Posted December 23, 2009 Hi everyone! I hava folder Drv as below: C:\Drv\D\S\R1\*.* C:\Drv\D\W\T1\*.* .... How to search subfolder name that the result return as : C:\Drv\D\S\R1 C:\Drv\D\W\T1 not: C:\Drv\D C:\Drv\D\S C:\Drv\D\S\R1 C:\Drv\D\W C:\Drv\D\W\T1 (remove C:\Drv\D, C:\Drv\D\S, C:\Drv\D\W from result) I want search folder and add path driver folder to DevicePath in registry. Thanks so much. Link to comment Share on other sites More sharing options...
funkey Posted December 23, 2009 Share Posted December 23, 2009 This could help: #include <Array.au3> $a = _GetFolders("R1") _ArrayDisplay($a) $b = _GetFolders("T1") _ArrayDisplay($b) Func _GetFolders($SearchPath, $sStartPath = @HomeDrive) ;funkey 23.12.2009 Local $line, $aFolder Local $cmd = 'dir /ad /b /s "' & $SearchPath & '"' Local $Pid = Run(@ComSpec & " /c " & $cmd, $sStartPath & "\", @SW_HIDE, 2) While 1 $line &= StdoutRead($Pid, 0, 0) If @error Then ExitLoop WEnd $aFolder = StringSplit($line, @CRLF, 3) If $aFolder[0] = "" Then Return SetError(1, 0, "") ReDim $aFolder[UBound($aFolder) - 1] For $i = 0 To UBound($aFolder) - 1 $aFolder[$i] = _OEMToAnsi($aFolder[$i]) Next Return $aFolder EndFunc ;==>_GetAllFolders Func _OEMToAnsi($sOEM) Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '') If @error = 0 Then $sAnsi = $a_AnsiFName[2] Return $sAnsi EndFunc ;==>_OEMToAnsi Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
john123 Posted December 23, 2009 Author Share Posted December 23, 2009 (edited) This could help: #include <Array.au3> $a = _GetFolders("R1") _ArrayDisplay($a) $b = _GetFolders("T1") _ArrayDisplay($b) Func _GetFolders($SearchPath, $sStartPath = @HomeDrive) ;funkey 23.12.2009 Local $line, $aFolder Local $cmd = 'dir /ad /b /s "' & $SearchPath & '"' Local $Pid = Run(@ComSpec & " /c " & $cmd, $sStartPath & "\", @SW_HIDE, 2) While 1 $line &= StdoutRead($Pid, 0, 0) If @error Then ExitLoop WEnd $aFolder = StringSplit($line, @CRLF, 3) If $aFolder[0] = "" Then Return SetError(1, 0, "") ReDim $aFolder[UBound($aFolder) - 1] For $i = 0 To UBound($aFolder) - 1 $aFolder[$i] = _OEMToAnsi($aFolder[$i]) Next Return $aFolder EndFunc ;==>_GetAllFolders Func _OEMToAnsi($sOEM) Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '') If @error = 0 Then $sAnsi = $a_AnsiFName[2] Return $sAnsi EndFunc ;==>_OEMToAnsi Thank you so much. But I want search R1, T1 from "C:\Drv". Like this: #include <Array.au3> Func _SearchDir($start_dir) Local $dir = $start_dir & '\*.*' Local $search = FileFindFirstFile($dir) While 1 $next = FileFindNextFile($search) If @error Then ExitLoop If StringInStr(FileGetAttrib($next & "\" & $search), "D") Then _SearchDir($next & "\" & $search) Else $next = $next & '\' $search EndIf WEnd EndFunc Can you improve this code? Can get C:\Drv\D\S\R1, C:\Drv\D\W\T1, ... from C:\Drv (remove C:\Drv\D\S, C:\Drv\D, C:\Drv\D\W, C:\Drv\D from the result)? With _FileListToArray("C:\Drv", "*", 2), it don't remove C:\Drv\D\S, C:\Drv\D, C:\Drv\D\W, C:\Drv\D. Edited December 23, 2009 by john123 Link to comment Share on other sites More sharing options...
99ojo Posted December 23, 2009 Share Posted December 23, 2009 (edited) Hi, just change the following lines in funkey's code: $a = _GetFolders("R1") $b = _GetFolders("T1") to $a = _GetFolders("R1", "C:\drv") $b = _GetFolders("T1", "C:\drv") ;-)) Stefan Edited December 23, 2009 by 99ojo Link to comment Share on other sites More sharing options...
john123 Posted December 23, 2009 Author Share Posted December 23, 2009 Thanks funkeHave a nice day!Hapy Chrismas to forum! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now