Jump to content

Search subfolder name exactly!


john123
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...