Jump to content
Sign in to follow this  
Jabberwock

Listing contents of a directory & cleaning up the name

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.

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  

×
×
  • Create New...