Jump to content
Sign in to follow this  
john123

Search subfolder name exactly!

Recommended Posts

john123

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.

Share this post


Link to post
Share on other sites
funkey

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 to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
john123

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 by john123

Share this post


Link to post
Share on other sites
99ojo

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 by 99ojo

Share this post


Link to post
Share on other sites
john123

Thanks funke

Have a nice day!

Hapy Chrismas to forum!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

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.