Jump to content

Listing contents of a directory & cleaning up the name


Recommended Posts

  • Moderators

does the trick for 2 folders, can't seem to add more, but with the 2nd directory it has to be specified in every file, for ex.

SetOutPath "$INSTDIR\common"

File "common\rawr.txt"

Blah, work on it some, see if you can get it... I'm going to go get something to eat, I'll have a look later.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Any progress?

Edit:

$Returned = _NSID_FileSetup(@DesktopDir & '\DummyFolder')
MsgBox(64, 'Info:', $Returned)
ClipPut($Returned)

Func _NSID_FileSetup($hLocation)
    Local $aList = _DirRecurse($hLocation)
    If @error Then SetError(1, 0, 0)
    $aList = StringSplit(StringTrimRight($aList, 1), @LF)
    Local $sHold = 'SetOutPath "$INSTDIR\"' & @CRLF
    Local $sMainDirectory = StringSplit($hLocation, '\')
    Local $aSplit, $iCount, $aDirectory[2] = ['', $sMainDirectory[0]], $iDCount = 1
    For $iCount = 1 To $aList[0]
        $aList[$iCount] = StringStripWS($aList[$iCount], 7)
        If StringInStr(FileGetAttrib($aList[$iCount]), 'd') Then
            $aSplit = StringSplit($aList[$iCount], '\')
            $iDCount += 1
            ReDim $aDirectory[$iDCount]
            $aDirectory[$iDCount - 1] = $aSplit[$aSplit[0]] 
        EndIf
    Next
    For $xCount = 1 To UBound($aDirectory) - 1
        $sHold &= 'SetOutPath "$INSTDIR\' & $aDirectory[$xCount] & '"' & @CRLF
        For $iCount = 1 To $aList[0]
            If Not StringInStr(FileGetAttrib($aList[$iCount]), 'd') Then
                $aSplit = StringSplit($aList[$iCount], '\')
                If StringStripWS($aSplit[$aSplit[0] - 1], 1) = StringStripWS($aDirectory[$xCount], 1) Then
                    $sHold &= 'File "' & StringTrimRight($aSplit[$aSplit[0] - 1] & _
                                        '\' & $aSplit[$aSplit[0]], 1) & '"' & @CRLF
                EndIf
            EndIf
        Next
    Next
    Return  StringTrimRight($sHold, 2)
EndFunc

Func _DirRecurse($hDirectory)
    RunWait(@Comspec & ' /c dir /b /s /a "' & $hDirectory & '" > "' & _
        @TempDir & '\RecursivOutput.txt"', @WorkingDir, @SW_HIDE)
    If Not FileExists(@TempDir & '\RecursivOutput.txt') Then SetError(1, 0, 0)
    Local $sFRead = FileRead(@TempDir & '\RecursivOutput.txt')
    FileDelete(@TempDir & '\RecursivOutput.txt')
    Return $sFRead
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You could try:

;NSIS Helper
;Steve Podhajecki [eltorro] gehossafats@netmdc.com

$InstallDir = "C:\Program Files\AutoIt3\Scite"
Search($InstallDir)
Exit

Func Search($sRoot)
    $FSO = ObjCreate("scripting.filesystemobject")
    $Folder = $FSO.GetFolder ($sRoot)
    $Files = $Folder.Files
    ClipPut("")
    ;  FileWriteLine(@DesktopCommonDir&"\AIS.lst",'SetOutPath "$INSTDIR\"')
    AddClip('SetOutPath "$INSTDIR\"')
    For $file In $Files
        ; FileWriteLine(@DesktopCommonDir&"\AIS.lst","file "&$file.Name)
        AddClip('file "' & $file.Name & '"')
    Next
    _RecursiveSearch($Folder, $sRoot)
    $FSO = 0
EndFunc   ;==>Search

Func _RecursiveSearch($oFolder, $sInstall)
    $subFolders = $oFolder.SubFolders
    For $oSubSubfolder In $subFolders
        $Files = $oSubSubfolder.Files
        $sPath = StringStripWS(StringReplace($oSubSubfolder.Path, $sInstall & "\", ""), 7)
        ;FileWriteLine(@DesktopCommonDir&"\AIS.lst",'SetOutPath "$INSTDIR\' &$sPath & '"')
        AddClip('SetOutPath "$INSTDIR\' & $sPath & '"')
        For $oFile In $Files
            ;FileWriteLine(@DesktopCommonDir&"\AIS.lst","file "&$oFile.Name)
            AddClip('file "' & $oFile.Name & '"')
        Next
        _RecursiveSearch($oSubSubfolder, $sInstall)
    Next
EndFunc   ;==>_RecursiveSearch

Func AddClip($sClipString)
    If Not ($sClipString = "") Then
        ClipPut(ClipGet() & $sClipString & @CRLF)
    EndIf
EndFunc   ;==>AddClip

The script is quick and dirty, hardly any error checking. However, is copies the list straight to clipboard.

Cheers

eltorro

Link to comment
Share on other sites

  • Moderators

Works great, but still has the same problem, NSIS needs the file path for sub directories, or the nsis compile can't find the file and will stop.

Mine works, I tested it on several directories.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

yours is cutting off the last character of the file extension as in. ".inc" it makes it ".in"

Then change it!!! wtf.

Replace:

$sHold &= 'File "' & StringTrimRight($aSplit[$aSplit[0] - 1] & _
                                        '\' & $aSplit[$aSplit[0]], 1) & '"' & @CRLFoÝ÷ Ùh­«­¢+ØÀÌØíÍ!½±µÀìôÌäí¥±ÅÕ½ÐìÌäìµÀìÀÌØíMÁ±¥ÑlÀÌØíMÁ±¥ÑlÁt´ÅtµÀì|(ÌäìÀäÈìÌäìµÀìÀÌØíMÁ±¥ÑlÀÌØíMÁ±¥ÑlÁutµÀìÌäìÅÕ½ÐìÌäìµÀì
I1
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ok Try this

;NSIS Helper
;Steve Podhajecki [eltorro] gehossafats@netmdc.com

$InstallDir = "C:\Program Files\AutoIt3\Scite"
$UseRelativePath =0
Search($InstallDir,$UseRelativePath)
Exit

Func Search($sRoot,$RelativePath= 0 )
    $FSO = ObjCreate("scripting.filesystemobject")
    $Folder = $FSO.GetFolder ($sRoot)
    $Files = $Folder.Files
    ClipPut("")
    ;  FileWriteLine(@DesktopCommonDir&"\AIS.lst",'SetOutPath "$INSTDIR\"')
    AddClip('SetOutPath "$INSTDIR\"')
    For $file In $Files
        ; FileWriteLine(@DesktopCommonDir&"\AIS.lst","file "&$file.Name)
        AddClip('file "' & $file.Name & '"')
    Next
    _RecursiveSearch($Folder, $sRoot,$RelativePath)
    $FSO = 0
EndFunc   ;==>Search

Func _RecursiveSearch($oFolder, $sInstall,$PathRelative=0)
    $subFolders = $oFolder.SubFolders
    For $oSubSubfolder In $subFolders
        $Files = $oSubSubfolder.Files
        $sPath = StringStripWS(StringReplace($oSubSubfolder.Path, $sInstall & "\", ""), 7)
        ;FileWriteLine(@DesktopCommonDir&"\AIS.lst",'SetOutPath "$INSTDIR\' &$sPath & '"')
        AddClip('SetOutPath "$INSTDIR\' & $sPath & '"')
        For $oFile In $Files
            ;FileWriteLine(@DesktopCommonDir&"\AIS.lst","file "&$oFile.Name)
            if $PathRelative Then
                Local $pos = StringInStr( $oFile.Path,":")
                 AddClip('file "..\..\..' & StringTrimLeft($oFile.Path & '"',$pos))
            else
            AddClip('file "' & $oFile.Path & '"')
        EndIf
        
        Next
        _RecursiveSearch($oSubSubfolder, $sInstall)
    Next
EndFunc   ;==>_RecursiveSearch

Func AddClip($sClipString)
    If Not ($sClipString = "") Then
        ClipPut(ClipGet() & $sClipString & @CRLF)
    EndIf
EndFunc   ;==>AddClip
Link to comment
Share on other sites

  • Moderators

Eltorro, what happens if there is 385++ sub folders with the _RecursiveSearch()?

Edit:

I should ask it like this, the way you keep recalling the function, is it possible that you would run into a recursive error?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...