找回密码
 加入
搜索
查看: 15826|回复: 18

[系统综合] 【已解决】_FileListToArray 咋样用数组方式来实现

 火.. [复制链接]
发表于 2014-7-3 11:29:15 | 显示全部楼层 |阅读模式
本帖最后由 xz00311 于 2014-7-7 18:50 编辑

正确答案在http://www.autoitx.com/forum.php ... amp;fromuid=7636455 这里
;C:\Users\chtyfox\Desktop\板端\11\222\333\4444\55555\666666
  #Include <File.au3>
  #Include <Array.au3>
  Local $var ,$pathfile,$pa,$FILE2
  $_Path = "C:\Users\chtyfox\Desktop\板端"
  _FileReadDir($_Path)
  $FILE2 = StringRight($pathfile, StringLen($pathfile) - StringInStr($pathfile, "", 1, -1))
  MsgBox(0,"1",$FILE2)
  $1 = StringLen($FILE2)+1
  $2 = StringLen($pathfile) -$1
  $3 = StringLeft($pathfile,$2)
  $FILE3 = StringRight($3, StringLen($3) - StringInStr($3, "", 1, -1) )
  MsgBox(0,"2",$FILE3)
  $4 = StringLen($FILE3)+1
  $5 = StringLen($3) -$4
  $6 = StringLeft($3,$5)
  $FILE4 = StringRight($6, StringLen($6) - StringInStr($6, "", 1, -1) )
  MsgBox(0,"3",$FILE4)
  $7 = StringLen($FILE4)+1
  $8 = StringLen($6) -$7
  $9 = StringLeft($6,$8)
  $FILE5 = StringRight($9, StringLen($9) - StringInStr($9, "", 1, -1) )
  MsgBox(0,"4",$FILE5)
  $10 = StringLen($FILE5)+1
  $11 = StringLen($9) -$10
  $12= StringLeft($9,$11)
  $FILE6 = StringRight($12, StringLen($12) - StringInStr($12, "", 1, -1) )
  MsgBox(0,"5",$FILE6)
  $13 = StringLen($FILE6)+1
  $14= StringLen($12) -$13
  $15= StringLeft($12,$14)
  $FILE7 = StringRight($15, StringLen($15) - StringInStr($15, "", 1, -1) )
  MsgBox(0,"6",$FILE7)
Func _FileReadDir($_Path)
        $Folder = _FileListToArray($_Path, "*", 2)
        If Not IsArray($Folder) Then Return 0
        For $i = 1 To $Folder[0]
                                $pathfile =$_Path & "" & $Folder[$i]
               _FileReadDir($_Path & "" & $Folder[$i]) 
                        Next
EndFunc                        
发表于 2014-7-4 09:56:13 | 显示全部楼层
帮顶学习。。。。。。。。。。。。。。。。。
发表于 2014-7-4 11:04:38 | 显示全部楼层
_FileListToArray  即可
发表于 2014-7-4 15:24:20 | 显示全部楼层
回复 1# xz00311

   _FileListToArray 咋样用数组方式来实现??

   _FileListToArray 本身的結果是數組  哪還要怎麼用數組實現??

你的 程式裡面  

Func _FileReadDir($_Path)

        $Folder = _FileListToArray($_Path, "*", 2)

        If Not IsArray($Folder) Then Return 0

        For $i = 1 To $Folder[0]

                                $pathfile =$_Path & "\" & $Folder[$i]

               _FileReadDir($_Path & "\" & $Folder[$i])

                        Next

EndFunc                     

這一段是幹嘛用的你知道嗎  ??
$Folder = _FileListToArray($_Path, "*", 2)
$Folder  這個不就是 一個數組了嗎??

===========================
滅火器  使用下去後 怎麼樣 可以滅火呀????

這個問題如果 你可以回答  那你的問題就有解了
发表于 2014-7-4 15:57:55 | 显示全部楼层
我与楼上有同样的感觉呵。不过看楼主已是高级会员了啊,一时难以理解,胡乱猜测一下:楼主想要实现的功能 比_FileListToArray()强一点,即想把所有子目录下的文件也输出在数组中?
 楼主| 发表于 2014-7-7 10:24:02 | 显示全部楼层
我对数组方面的东西很差的有些东西不能理解,学C的时候数组也是最差的不知道咋样用,我只要文件夹的名字然后在其他目录在创建11\222\333\4444\55555\666666这样的方式的文件夹
 楼主| 发表于 2014-7-7 10:26:20 | 显示全部楼层
其实我想到 $FILE3- $FILE7咋写了就是$FILE2这个还没想通
发表于 2014-7-7 10:26:34 | 显示全部楼层
回复学习。。。。。。。。。。。。。。。。。。。
发表于 2014-7-7 11:27:14 | 显示全部楼层
我对数组方面的东西很差的有些东西不能理解,学C的时候数组也是最差的不知道咋样用,我只要文件夹的名字然后 ...
xz00311 发表于 2014-7-7 10:24



    是不是想多了… 遍历目录后直接在其后面加上 \11\222\333\4444\55555\666666,用 DirCreate() 创建不就行了
发表于 2014-7-7 11:28:05 | 显示全部楼层
Local $sPath = 'C:\Users\chtyfox\Desktop\板端'
$aLine = _FileFindMain($sPath)
If @Error Then Exit
;_ArrayDisplay($aLine, $aLine)
For $i = 0 To UBound($aLine) - 1
        MsgBox(0, '', $aLine[$i] & '\11\222\333\4444\55555\666666')
        ;DirCreate($aLine[$i] & '\11\222\333\4444\55555\666666')
Next

Func _FileFindMain($_Path)
        Local $sFiles
        __FileFinda($sPath, $sFiles)
        Local $aLine = StringRegExp($sFiles, '\V+', 3)
        If @Error Then Return SetError(1)
        Return $aLine
EndFunc   ;==>_FileFindMain

Func __FileFinda($sDir, ByRef $sOut)
        Local $hSearch = FileFindFirstFile($sDir & '\*')
        If $hSearch = -1 Then Return
        While 1
                Local $sFile = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If Not @extended Then ContinueLoop
                __FileFinda($sDir & '\' & $sFile, $sOut)
                $sOut &= $sDir & '\' & $sFile & @CRLF
        WEnd
        FileClose($hSearch)
EndFunc   ;==>__FileFinda
 楼主| 发表于 2014-7-7 16:57:20 | 显示全部楼层
我是在做批量安装FileInstall_Aid这个的新加的功能,代码我是反编译别人的所以不能把源码放出来,我加的功能是先获取里面的文件夹里面所有文件夹,然后在释放的时候在其他目录创建同样的层次的文件夹
 楼主| 发表于 2014-7-7 17:04:35 | 显示全部楼层
;C:\Users\chtyfox\Desktop\板端\11\222\333\4444\55555\666666  这里面的文字不是固定啊,是一直变化的
 楼主| 发表于 2014-7-7 17:16:08 | 显示全部楼层
谢谢AFAN的代码给到我思路的不知道创建文件夹还可以这样写的谢谢
发表于 2014-7-7 17:24:14 | 显示全部楼层
你是想获取目录及子目录的结构,然后在指定的文件夹中创建同样的目录结构?
Local $sPath = 'C:\Users\chtyfox\Desktop\板端'
Local $sPathNew = 'X:\Xa\Xb'

$aLine = _FileFinDir($sPath)
If @error Then Exit

For $i = 0 To UBound($aLine) - 1
        MsgBox(0, '', $sPathNew & '\' & $aLine[$i])
        ;DirCreate($sPathNew & '\' & $aLine[$i])
Next

Func _FileFinDir($_Path)
        $_Path = StringRegExpReplace($_Path, '^\s+|\\+$|\s+$', '')
        Local $sFiles
        __FileFinda($_Path, $sFiles)
        Local $iLen = StringLen($_Path) + 1
        $sFiles = StringRegExpReplace($sFiles, '(?m)^.{' & $iLen & '}', '')
        Local $aLine = StringRegExp($sFiles, '\V+', 3)
        If @error Then Return SetError(1)
        Return $aLine
EndFunc   ;==>_FileFinDir

Func __FileFinda($sDir, ByRef $sOut)
        Local $hSearch = FileFindFirstFile($sDir & '\*')
        If $hSearch = -1 Then Return
        While 1
                Local $sFile = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If Not @extended Then ContinueLoop
                __FileFinda($sDir & '\' & $sFile, $sOut)
                $sOut &= $sDir & '\' & $sFile & @CRLF
        WEnd
        FileClose($hSearch)
EndFunc   ;==>__FileFinda
 楼主| 发表于 2014-7-7 18:23:33 | 显示全部楼层
是的,文件夹里面的所有文件夹和子文件夹
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-13 11:08 , Processed in 0.099078 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表