怎么依次打开文件夹下的所有图片文件...[已解决]
本帖最后由 流沙枫 于 2012-6-21 00:47 编辑文件名没有规律的....
a.jpg12.gifdbd.jpgSleep(3000)
ShellExecute("*.jpg", "", @ScriptDir, "open")
ShellExecute("*.gif", "", @ScriptDir, "open")
? ShellExecute("1000.jpg", "", @ScriptDir, "open")
Sleep(3000)
$txt = FileOpen("123.txt", 1)
$var = DriveGetDrive("FIXED")
If Not @error Then
For $i = 1 To $var
Search($var[$i] & "\", "")
Next
EndIf
Func Search($current, $ext)
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "."Or $file <> "..") Then
If StringRight($current & "\" & $file, StringLen($ext)) = $ext Then
;~ MsgBox(0, 0, $current & "\" & $file)
;FileWriteLine($txt, $current & "\" & $file)
ShellExecute($current & "\" & $file, "", @ScriptDir, "open")
EndIf
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "."Or $file <> "..") Then
Search($current & "\" & $file, $ext)
EndIf
WEnd
Return
EndFunc 这个获取路径怎么是C盘了? DriveGetDrive("FIXED")一句是获取所有硬盘,当然包含C盘了。2 楼代码遍历全部硬盘的上的所有文件并运行,有必要吗?
拿人家的代码用,先试着根据帮助搞懂每句话的意思吧。如还有不懂,再来论坛提问,与已与人才比较好。 同意上楼的,一个个看看比较好。不然以后出了点什么问题或是有点什么改动有得发一次贴啦 回复 4# shqf
不懂改才发提问的,那怎么获取当前目录的文件名呢? 参见autoit help里的“宏相关”的内容:@ScriptDir... 回复 6# 流沙枫
#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray(@ScriptDir,"*.jpg",1)
If @Error=4 Then
MsgBox (0,"","No JPG Files Found.")
Exit
EndIf
_ArrayDisplay($FileList,"$FileList") 回复流沙枫
#Include
#Include
$FileList=_FileListToArray(@ScriptDir,"*.jpg",1)
If @Error=4 ...
xms77 发表于 2012-6-19 16:47 http://www.autoitx.com/images/common/back.gif
还有gif的图片? 回复 9# 流沙枫
再用$FileList_GIF=_FileListToArray(@ScriptDir,"*.gif",1),然后两个数组合并一下吧! 本帖最后由 流沙枫 于 2012-6-20 14:58 编辑
回复流沙枫
再用$FileList_GIF=_FileListToArray(@ScriptDir,"*.gif",1),然后两个数组合并一下吧!
xms77 发表于 2012-6-20 08:36 http://www.autoitx.com/images/common/back.gif#Include <File.au3>
#Include <Array.au3>
$FileList_JPG=_FileListToArray(@ScriptDir,"*.jpg",1)
$FileList_GIF=_FileListToArray(@ScriptDir,"*.gif",1)
$FileList=$FileList_JPG&$FileList_GIF
If @Error=4 Then
MsgBox (0,"","No JPG Files Found.")
Exit
EndIf
_ArrayDisplay($FileList,"$FileList")
? 本帖最后由 xms77 于 2012-6-20 20:41 编辑
#include <File.au3>
#include <Array.au3>
$FileList_JPG = _FileListToArray(@ScriptDir, "*.jpg", 1)
If Not @error Then _ArrayDelete($FileList_JPG, 0)
$FileList_GIF = _FileListToArray(@ScriptDir, "*.gif", 1)
If Not @error Then _ArrayDelete($FileList_GIF, 0)
Select
Case IsArray($FileList_JPG) And IsArray($FileList_GIF)
_ArrayConcatenate($FileList_JPG, $FileList_GIF)
_ArrayDisplay($FileList_JPG)
Case IsArray($FileList_JPG) And Not IsArray($FileList_GIF)
_ArrayDisplay($FileList_JPG)
Case Not IsArray($FileList_JPG) And IsArray($FileList_GIF)
_ArrayDisplay($FileList_GIF)
Case Not IsArray($FileList_JPG) And Not IsArray($FileList_GIF)
MsgBox(0, 0, "当前目录没有JPG或GIF文件!")
EndSelect 楼上代码不错。。
xms77 发表于 2012-6-20 17:00 http://www.autoitx.com/images/common/back.gif$var = DriveGetDrive("FIXED")
If Not @error Then
For $i = 1 To $var
Search(@ScriptDir, "")
; Search($var[$i] & "\", "")
Next
EndIf
Func Search($current, $ext)
Local $search = FileFindFirstFile($current & "\*.jpg")
Local $search1 = FileFindFirstFile($current & "\*.gif")
_ArrayConcatenate($search, $search1)
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "."Or $file <> "..") Then
If StringRight($current & "\" & $file, StringLen($ext)) = $ext Then
;~ MsgBox(0, 0, $current & "\" & $file)
;FileWriteLine($txt, $current & "\" & $file)
ShellExecute($current & "\" & $file, "", @ScriptDir, "open")
Sleep(8000)
EndIf
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "."Or $file <> "..") Then
Search($current & "\" & $file, $ext)
EndIf
WEnd
Return
EndFunc 原来关键是_ArrayConcatenate函数....
改了下,终于可以把图片都自动打开浏览了!
谢了。
页:
[1]