Je viens vers vous car je sèche un petit peu sur du code.
J'ai sur un disque réseau "h:\" beaucoup de dossiers et sous-rep qui correspondent à des livrables à déployer sur un parc serveurs.
Je cherche à faire un script qui va m'ouvrir une "inputbox" et demander à l'user le nom du lot qu'il recherche. ex : A9, B10, ex... qui corresponds à un sous-rep situé sur ce disque.
Je veux qu'il scan donc tout le disque pour trouver par ex le sous-rep A9-XXXXX et qu'il me le liste.
Alors deux options :
-- La première, c'est qu'il génère une page html sortant la liste et il n'y a plus qu'à aller chercher l'archive et la télécharger.
-- La seconde, que mon user choisisse le nom du lot et que ça le place directement dedans dans une fenêtre explorateur.
Voici le code :
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
MsgBox($MB_SYSTEMMODAL, '', 'Export contenu du dossier selectionné en HTML5')
Example()
Func Example()
Local Const $sSaveFilePath = @ScriptDir
Local $sHTML = '', $sTab = @TAB
_HTML_Add($sHTML, '<!DOCTYPE html>')
_HTML_Add($sHTML, '<html lang="fr">')
_HTML_Add($sHTML, '<head>')
_HTML_Add($sHTML, '<meta charset="utf-8">', $sTab)
_HTML_Add($sHTML, '<title># Listage du Repertoire</title>', $sTab)
_HTML_Add($sHTML, '<style type="text/css">', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '@import url(http://weloveiconfonts.com/api/?family=fontawesome);.dirtohtml a{background:#2C4770;color:#08c;position:relative;text-decoration:none;-webkit-transition:all .3s ease-out;transition:all .3s ease-out}.dirtohtml a:hover{color:#0af}.dirtohtml input[type=checkbox],.dirtohtml input[type=checkbox]+ul{display:none}.dirtohtml input[type=checkbox]:checked+ul{display:block}.dirtohtml label{cursor:pointer}.dirtohtml ul li{list-style:none}[class*="fontawesome-"]:before{font-family:"FontAwesome",sans-serif;margin-right:5px}', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</style>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</head>')
_HTML_Add($sHTML, '<body>')
_Tab_Add($sTab)
Local Const $sDirectorySelection = FileSelectFolder('Choix du "repertoire" a générer HTML5', '')
Local $aFileList = _FileListToArrayRec($sDirectorySelection, '*', 0, 1, 2, 2)
If @error Then
_HTML_Add($sHTML, '<p>Pas de fichiers sous le <rep></p>', $sTab)
Else
_HTML_Add($sHTML, '<div class="dirtohtml">', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '<ul>', $sTab)
_Tab_Add($sTab)
Local $bIsRelative = False, _
$iCheckboxCount = 1, $iCurrentLevel = 0, $iNestedDepth = 0, $iNextIndex = 0, $iNextLevel = 0, _
$sFileName = '', $sRelativeFilePath = ''
For $i = 1 To $aFileList[0]
$aFileList[$i] = StringRegExpReplace($aFileList[$i], '(?:\\|/)', '\\')
$iCurrentLevel = @extended
If $i < $aFileList[0] Then
$iNextIndex = $i + 1
$aFileList[$iNextIndex] = StringRegExpReplace($aFileList[$iNextIndex], '(?:\\|/)', '\\')
$iNextLevel = @extended
EndIf
$sFileName = StringRegExpReplace($aFileList[$i], '^.+\\', '')
If _WinAPI_PathIsDirectory($aFileList[$i]) = $FILE_ATTRIBUTE_DIRECTORY Then
If $iNextLevel > $iCurrentLevel Or $iNextLevel = $iCurrentLevel Then
_HTML_Add($sHTML, '<li>', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '<label for="dirtohtml_' & $iCheckboxCount & '"><i class="fontawesome-folder-close-alt"></i>' & $sFileName & '</label>', $sTab)
_HTML_Add($sHTML, '<input id="dirtohtml_' & $iCheckboxCount & '" type="checkbox">', $sTab)
_HTML_Add($sHTML, '<ul>', $sTab)
$iCheckboxCount += 1
$iNestedDepth += 1
ElseIf $iNextLevel < $iCurrentLevel Then
_HTML_Add($sHTML, '<li>' & $sFileName, $sTab)
EndIf
_Tab_Add($sTab)
Else
$sRelativeFilePath = _PathGetRelative($sSaveFilePath, $aFileList[$i])
$bIsRelative = Not @error
_HTML_Add($sHTML, '<li><i class="fontawesome-file"></i><a href="' & ($bIsRelative ? '' : 'file://') & StringReplace($sRelativeFilePath, '\', '/') & '">' & $sFileName & '</a></li>', $sTab)
If $iNextLevel < $iCurrentLevel Then
For $j = 1 To ($iCurrentLevel - $iNextLevel)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</li>', $sTab)
$iNestedDepth -= 1
Next
EndIf
EndIf
Next
If $iNestedDepth Then
For $j = 1 To $iNestedDepth
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</li>', $sTab)
Next
EndIf
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</div>', $sTab)
EndIf
_HTML_Add($sHTML, '</body>')
_HTML_Add($sHTML, '</html>')
Local Const $sHTMLFilePath = _WinAPI_PathRemoveBackslash($sSaveFilePath) & '\cdapp.html'
Local Const $hFileOpen = FileOpen($sHTMLFilePath, BitOR($FO_OVERWRITE, $FO_UTF8))
If $hFileOpen > -1 Then
FileWrite($hFileOpen, $sHTML)
FileClose($hFileOpen)
MsgBox($MB_SYSTEMMODAL, '', 'Export en HTML5 <réussi>.' & @CRLF & $sHTMLFilePath)
Else
MsgBox($MB_SYSTEMMODAL, '', '[ERR.] Rejoue encore !')
EndIf
ConsoleWrite($sHTML & @CRLF)
Return True
EndFunc
Func _HTML_Add(ByRef $sHTML, $sData, $sTab = Default)
$sHTML &= (($sTab = Default) ? '' : $sTab) & $sData & @CRLF
EndFunc
Func _Tab_Add(ByRef $sTab)
$sTab &= @TAB
EndFunc
Func _Tab_Remove(ByRef $sTab)
Local Static $TAB_LENGTH = StringLen(@TAB)
$sTab = StringTrimRight($sTab, $TAB_LENGTH)
EndFunc
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
MsgBox($MB_SYSTEMMODAL, '', 'Export contenu du dossier selectionné en HTML5')
Example()
Func Example()
Local Const $sSaveFilePath = @ScriptDir
Local $sHTML = '', $sTab = @TAB
_HTML_Add($sHTML, '<!DOCTYPE html>')
_HTML_Add($sHTML, '<html lang="fr">')
_HTML_Add($sHTML, '<head>')
_HTML_Add($sHTML, '<meta charset="utf-8">', $sTab)
_HTML_Add($sHTML, '<title># Listage du Repertoire</title>', $sTab)
_HTML_Add($sHTML, '<style type="text/css">', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '@import url(http://weloveiconfonts.com/api/?family=fontawesome);.dirtohtml a{background:#2C4770;color:#08c;position:relative;text-decoration:none;-webkit-transition:all .3s ease-out;transition:all .3s ease-out}.dirtohtml a:hover{color:#0af}.dirtohtml input[type=checkbox],.dirtohtml input[type=checkbox]+ul{display:none}.dirtohtml input[type=checkbox]:checked+ul{display:block}.dirtohtml label{cursor:pointer}.dirtohtml ul li{list-style:none}[class*="fontawesome-"]:before{font-family:"FontAwesome",sans-serif;margin-right:5px}', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</style>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</head>')
_HTML_Add($sHTML, '<body>')
_Tab_Add($sTab)
Local Const $sDirectorySelection = FileSelectFolder('Choix du "repertoire" a générer HTML5', '')
Local $aFileList = _FileListToArrayRec($sDirectorySelection, '*', 0, 1, 2, 2)
If @error Then
_HTML_Add($sHTML, '<p>Pas de fichiers sous le <rep></p>', $sTab)
Else
_HTML_Add($sHTML, '<div class="dirtohtml">', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '<ul>', $sTab)
_Tab_Add($sTab)
Local $bIsRelative = False, _
$iCheckboxCount = 1, $iCurrentLevel = 0, $iNestedDepth = 0, $iNextIndex = 0, $iNextLevel = 0, _
$sFileName = '', $sRelativeFilePath = ''
For $i = 1 To $aFileList[0]
$aFileList[$i] = StringRegExpReplace($aFileList[$i], '(?:\\|/)', '\\')
$iCurrentLevel = @extended
If $i < $aFileList[0] Then
$iNextIndex = $i + 1
$aFileList[$iNextIndex] = StringRegExpReplace($aFileList[$iNextIndex], '(?:\\|/)', '\\')
$iNextLevel = @extended
EndIf
$sFileName = StringRegExpReplace($aFileList[$i], '^.+\\', '')
If _WinAPI_PathIsDirectory($aFileList[$i]) = $FILE_ATTRIBUTE_DIRECTORY Then
If $iNextLevel > $iCurrentLevel Or $iNextLevel = $iCurrentLevel Then
_HTML_Add($sHTML, '<li>', $sTab)
_Tab_Add($sTab)
_HTML_Add($sHTML, '<label for="dirtohtml_' & $iCheckboxCount & '"><i class="fontawesome-folder-close-alt"></i>' & $sFileName & '</label>', $sTab)
_HTML_Add($sHTML, '<input id="dirtohtml_' & $iCheckboxCount & '" type="checkbox">', $sTab)
_HTML_Add($sHTML, '<ul>', $sTab)
$iCheckboxCount += 1
$iNestedDepth += 1
ElseIf $iNextLevel < $iCurrentLevel Then
_HTML_Add($sHTML, '<li>' & $sFileName, $sTab)
EndIf
_Tab_Add($sTab)
Else
$sRelativeFilePath = _PathGetRelative($sSaveFilePath, $aFileList[$i])
$bIsRelative = Not @error
_HTML_Add($sHTML, '<li><i class="fontawesome-file"></i><a href="' & ($bIsRelative ? '' : 'file://') & StringReplace($sRelativeFilePath, '\', '/') & '">' & $sFileName & '</a></li>', $sTab)
If $iNextLevel < $iCurrentLevel Then
For $j = 1 To ($iCurrentLevel - $iNextLevel)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</li>', $sTab)
$iNestedDepth -= 1
Next
EndIf
EndIf
Next
If $iNestedDepth Then
For $j = 1 To $iNestedDepth
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</li>', $sTab)
Next
EndIf
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</ul>', $sTab)
_Tab_Remove($sTab)
_HTML_Add($sHTML, '</div>', $sTab)
EndIf
_HTML_Add($sHTML, '</body>')
_HTML_Add($sHTML, '</html>')
Local Const $sHTMLFilePath = _WinAPI_PathRemoveBackslash($sSaveFilePath) & '\cdapp.html'
Local Const $hFileOpen = FileOpen($sHTMLFilePath, BitOR($FO_OVERWRITE, $FO_UTF8))
If $hFileOpen > -1 Then
FileWrite($hFileOpen, $sHTML)
FileClose($hFileOpen)
MsgBox($MB_SYSTEMMODAL, '', 'Export en HTML5 <réussi>.' & @CRLF & $sHTMLFilePath)
Else
MsgBox($MB_SYSTEMMODAL, '', '[ERR.] Rejoue encore !')
EndIf
ConsoleWrite($sHTML & @CRLF)
Return True
EndFunc
Func _HTML_Add(ByRef $sHTML, $sData, $sTab = Default)
$sHTML &= (($sTab = Default) ? '' : $sTab) & $sData & @CRLF
EndFunc
Func _Tab_Add(ByRef $sTab)
$sTab &= @TAB
EndFunc
Func _Tab_Remove(ByRef $sTab)
Local Static $TAB_LENGTH = StringLen(@TAB)
$sTab = StringTrimRight($sTab, $TAB_LENGTH)
EndFunc