Jump to content
Sign in to follow this  
wolf9228

Get \ Find All Files type In Dir

Recommended Posts

[code]#include <GUIConstants.au3>
$Form = GUICreate("Form1", 419, 217, 155, 145)
$Tab1 = GUICtrlCreateTab(0, 0, 417, 217)
$TabSheet1 = GUICtrlCreateTabItem(" ")
$FOLDRIN = GUICtrlCreateButton("FOLDR IN", 8, 32, 105, 25)
$FOLDROUT = GUICtrlCreateButton("FOLDR OUT", 304, 32, 105, 25)
GUICtrlCreateLabel("File type IN FOLDR IN", 160, 64, 200, 20)
$IPUTYPE = GUICtrlCreateCombo ("Choose.", 160, 80, 97, 21)
$COPY = GUICtrlCreateButton("COPY", 8, 144, 105, 25)
$MOVE = GUICtrlCreateButton("MOVE", 304, 144, 105, 25)
GUICtrlCreateLabel("File in Name ", 24, 176, 74, 17)
GUICtrlCreateLabel("File Out Name", 312, 176, 86, 17)
$IN = GUICtrlCreateLabel("........................................................", 8, 192, 172, 17)
$OUTXY = GUICtrlCreateLabel("........................................................", 240, 192, 172, 17,$BS_RIGHT)
$CHNG = GUICtrlCreateCheckbox(" WHITE CHNG NAME ", 136, 144, 153, 17)
GUICtrlCreateTabItem("")
GUICtrlSetState($MOVE, $GUI_DISABLE)
GUICtrlSetState($COPY, $GUI_DISABLE)
GUICtrlSetState($IPUTYPE, $GUI_DISABLE)
$out =0
$FOLINOK = 0
$FOLOUTOK = 0
GuiSetState()


While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $FOLDRIN
$FOLIN = FileSelectFolder("Choose a folder.", "")
if $FOLIN > "" THEN
$FOLINOK = 1
FileChangeDir($FOLIN)
$pos = WinGetPos($Form)
SplashTextOn("Wait", "Wait Get All Files Type In Foldr In",419, 100, $pos[0], $pos[1] + 110, "", 24)
$out = GetAllFiletypeInDir($FOLINOK)
Sleep(1000)
SplashOff()
IF $FOLINOK = 1 AND $FOLOUTOK = 1 AND NOT ($out) = 0 THEN
GUICtrlSetState($MOVE, $GUI_ENABLE)
GUICtrlSetState($COPY, $GUI_ENABLE)
GUICtrlSetState($IPUTYPE, $GUI_ENABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
FileChangeDir(@ScriptDir)

ENDIF
ENDIF
Case $msg = $FOLDROUT
$FOLOUT = FileSelectFolder("", "")
if $FOLOUT > "" THEN
$FOLOUTOK = 1
IF $FOLINOK = 1 AND $FOLOUTOK = 1 AND NOT ($out) = 0 THEN
GUICtrlSetState($MOVE, $GUI_ENABLE)
GUICtrlSetState($COPY, $GUI_ENABLE)
GUICtrlSetState($IPUTYPE, $GUI_ENABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
FileChangeDir(@ScriptDir)
ENDIF
ENDIF

Case $msg = $COPY OR $msg = $MOVE
$log = ""
if GUICtrlRead($IPUTYPE) = "Choose." then
MsgBox(0,"","No Type Choose")
else
$pos = WinGetPos($Form)
SplashTextOn("Wait", "Wait Find All " & GUICtrlRead($IPUTYPE) & " Files In Foldr In",419, 100, $pos[0], $pos[1] + 110, "", 24)
$X = FINDFILESTypeInDir($FOLIN ,GUICtrlRead($IPUTYPE))
Sleep(1000)
SplashOff()
if NOT ($X) = 0 then
DirCreate ( ($FOLOUT) & "\FOLOUT" )
IF BitAND (GUICtrlRead($CHNG), $GUI_CHECKED) THEN

;WHITE CHNG NAME ............................
For $i = 1 to $X Step 1
EnvSet($i & "X" , "File" & $i & "." & GUICtrlRead($IPUTYPE))
next

For $i = 1 to $X Step 1
GuiCtrlSetData($IN, EnvGet($i))
if $msg = $COPY then FileCopy(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\" & EnvGet($i & "X") )
if $msg = $MOVE then FileMove(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\" & EnvGet($i & "X") )
GuiCtrlSetData($OUTXY, " " & EnvGet($i & "X"))
if $msg = $COPY then $log = $log & EnvGet($i) & " === Copy To ===> " & EnvGet($i & "X") & @CRLF
if $msg = $MOVE then $log = $log & EnvGet($i) & " === Move To ===> " & EnvGet($i & "X") & @CRLF
next
;.....................................
else

; WHITE out CHNG NAME......................

For $i = $X to 1 Step -1
GuiCtrlSetData($IN, EnvGet($i))
if $msg = $COPY then FileCopy(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\" & EnvGet($i) )
if $msg = $MOVE then FileMove(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\" & EnvGet($i) )
GuiCtrlSetData($OUTXY," " & EnvGet($i))
if $msg = $COPY then $log = $log & EnvGet($i) & " === Copy To ===> " & EnvGet($i) & @CRLF
if $msg = $MOVE then $log = $log & EnvGet($i) & " === Move To ===> " & EnvGet($i) & @CRLF
next
endif
;...........................................


GUICtrlSetState($MOVE, $GUI_DISABLE)
GUICtrlSetState($COPY, $GUI_DISABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
GUICtrlSetState($IPUTYPE, $GUI_DISABLE)
GUICtrlSetState($CHNG, $GUI_UNCHECKED)
$out =0
$FOLINOK = 0
$FOLOUTOK = 0
$i = 0
FileChangeDir(@ScriptDir)


$file = FileOpen("Report.ini", 2)
FileWriteLine($file, $log)
FileClose($file)
$comm = "Notepad.exe Report.ini"
Run($comm, "", @SW_MAXIMIZE)
else

endif
endif
EndSelect
WEnd






Func FINDFILESTypeInDir($DIR,$Type)
$search = FileFindFirstFile(($DIR) & "\*" & $Type)
If $search = -1 Then
MsgBox(0, "Error", "No files matched the search pattern")
FileClose($search)
Return 0
else
$i = 0
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$i = $i + 1
$file = StringUpper($file)
EnvSet($i , $file)
wend
endif
FileClose($search)
Return $i
EndFunc


Func GetAllFiletypeInDir($dir)
$chk = 0
$ix = 0
$outtypeX =""
$search = FileFindFirstFile("*.*")
If $search = -1 Then
MsgBox(0, "Error", "No files matched the search pattern")
FileClose($search)
Return 0
else
$i =0
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
$fileX =""
$file = StringUpper($file)
$i2 =1

While $i2 =1
if StringRight($file, 1) = '.' then
$file = $fileX
$i2 = 0
else
if StringLen($file) = 0 then $file = ""
if StringLen($file) = 0 then $i2 = 0
$fileX = StringRight($file, 1) & $fileX
$file = StringTrimRight( $file, 1 )
endif
wend
if $file <> "" then
$i = $i + 1
EnvSet($i, $file)
$chk = 1
endif
WEnd

if $i = 1 then FileClose($search)
if $i = 1 then Return EnvGet(1)

if $chk = 1 Then
For $i3 = $i to 1 Step -1
$var = EnvGet($i3)
For $i4 = $i to 1 Step -1
if $i4 = $i3 then $i4 = $i4 - 1
$var2 = EnvGet($i4)
if $var = $var2 then EnvSet($i3, "")
next
next

For $i5 = $i to 1 Step -1
if EnvGet($i5) <> "" then
$outtype = EnvGet($i5)
$outtypeX = $outtypeX & $outtype & "|"
endif
next
$outtypeX = StringTrimRight ( $outtypeX, 1 )
FileClose($search)
Return $outtypeX
Else
MsgBox(0, "Error", "No files matched the search pattern")
FileClose($search)
Return 0
endif
endif
EndFunc

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

note: THE MSGBOX Behind the SPLASHTEXTON

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The right Code

#include <GUIConstants.au3>
$Form = GUICreate("Form1", 419, 217, 155, 145)
$Tab1 = GUICtrlCreateTab(0, 0, 417, 217)
$TabSheet1 = GUICtrlCreateTabItem(" ")
$FOLDRIN = GUICtrlCreateButton("FOLDR IN", 8, 32, 105, 25)
$FOLDROUT = GUICtrlCreateButton("FOLDR OUT", 304, 32, 105, 25)
GUICtrlCreateLabel("File type IN FOLDR IN", 160, 64, 200, 20)
$IPUTYPE = GUICtrlCreateCombo ("Choose.", 160, 80, 97, 21)
$COPY = GUICtrlCreateButton("COPY", 8, 144, 105, 25)
$MOVE = GUICtrlCreateButton("MOVE", 304, 144, 105, 25)
GUICtrlCreateLabel("File in Name ", 24, 176, 74, 17)
GUICtrlCreateLabel("File Out Name", 312, 176, 86, 17)
$IN  = GUICtrlCreateLabel("........................................................", 8, 192, 172, 17)
$OUTXY = GUICtrlCreateLabel("........................................................", 240, 192, 172, 17,$BS_RIGHT)
$CHNG = GUICtrlCreateCheckbox(" WHITE CHNG NAME ", 136, 144, 153, 17)
GUICtrlCreateTabItem("")
GUICtrlSetState($MOVE, $GUI_DISABLE)
GUICtrlSetState($COPY, $GUI_DISABLE)
GUICtrlSetState($IPUTYPE, $GUI_DISABLE)
$out =0
$FOLINOK = 0
$FOLOUTOK = 0
GuiSetState()


While 1
$msg = GuiGetMsg()
Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $FOLDRIN
$FOLIN = FileSelectFolder("Choose a folder.", "")
if $FOLIN > "" THEN 
FileChangeDir(@ScriptDir)
$FOLINOK = 1
$out = GetAllFiletypeInDir($FOLIN)
IF $FOLINOK = 1 AND $FOLOUTOK = 1  AND NOT ($out) = 0 THEN 
GUICtrlSetState($MOVE, $GUI_ENABLE)
GUICtrlSetState($COPY, $GUI_ENABLE)
GUICtrlSetState($IPUTYPE, $GUI_ENABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
FileChangeDir(@ScriptDir)

ENDIF
ENDIF
        Case $msg = $FOLDROUT
$FOLOUT = FileSelectFolder("", "")
if $FOLOUT > "" THEN
$FOLOUTOK = 1
IF $FOLINOK = 1 AND $FOLOUTOK = 1  AND NOT ($out) = 0 THEN 
GUICtrlSetState($MOVE, $GUI_ENABLE)
GUICtrlSetState($COPY, $GUI_ENABLE)
GUICtrlSetState($IPUTYPE, $GUI_ENABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
FileChangeDir(@ScriptDir)
ENDIF
ENDIF

Case $msg = $COPY OR $msg = $MOVE
$log = ""
if GUICtrlRead($IPUTYPE) = "Choose." then 
MsgBox(0,"","No Type Choose")
else
$X = FINDFILESTypeInDir($FOLIN ,GUICtrlRead($IPUTYPE))
Sleep(1000)
SplashOff()
if NOT ($X) = 0 then 
DirCreate ( ($FOLOUT) & "\FOLOUT" )
IF BitAND (GUICtrlRead($CHNG), $GUI_CHECKED) THEN 

;WHITE CHNG NAME ............................
For $i = 1 to $X Step 1
EnvSet($i & "X" , "File" & $i & "." & GUICtrlRead($IPUTYPE))
next 

For $i = 1 to $X Step 1
GuiCtrlSetData($IN, EnvGet($i))
if $msg = $COPY then FileCopy(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\"  & EnvGet($i & "X") )
if $msg = $MOVE then FileMove(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\"  & EnvGet($i & "X") )
GuiCtrlSetData($OUTXY, "                          " & EnvGet($i & "X"))
if $msg = $COPY then $log = $log  & EnvGet($i) & " === Copy To ===> " &  EnvGet($i & "X") & @CRLF
if $msg = $MOVE then $log = $log  & EnvGet($i) & " === Move To ===> " &  EnvGet($i & "X") & @CRLF
next 
;.....................................
else

; WHITE out CHNG NAME......................
    
For $i = $X to 1 Step -1
GuiCtrlSetData($IN, EnvGet($i))
if $msg = $COPY then FileCopy(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\"  & EnvGet($i) )
if $msg = $MOVE then FileMove(($FOLIN)& "\" & EnvGet($i) , ($FOLOUT) & "\FOLOUT\"  & EnvGet($i) )
GuiCtrlSetData($OUTXY,"                       " & EnvGet($i))
if $msg = $COPY then $log = $log  & EnvGet($i) & " === Copy To ===> " &  EnvGet($i) & @CRLF
if $msg = $MOVE then $log = $log  & EnvGet($i) & " === Move To ===> " &  EnvGet($i) & @CRLF
next 
endif 
;...........................................


GUICtrlSetState($MOVE, $GUI_DISABLE)
GUICtrlSetState($COPY, $GUI_DISABLE)
GUICtrlSetData($IPUTYPE,"","")
GUICtrlSetData($IPUTYPE,$out & "|Choose." ,"Choose.")
GUICtrlSetState($IPUTYPE, $GUI_DISABLE)
GUICtrlSetState($CHNG, $GUI_UNCHECKED)
$out =0
$FOLINOK = 0
$FOLOUTOK = 0
$i = 0
FileChangeDir(@ScriptDir)


$file = FileOpen("Report.ini", 2)
FileWriteLine($file, $log)
FileClose($file)
$comm = "Notepad.exe Report.ini"
Run($comm, "", @SW_MAXIMIZE)
else 
    
endif 
endif 
EndSelect
WEnd






Func FINDFILESTypeInDir($DIR,$Type)
$pos = WinGetPos($Form)
$search = FileFindFirstFile(($DIR) & "\*" & $Type)
If $search = -1 Then
SplashTextOn("Msg", "No files matched " & GUICtrlRead($IPUTYPE) & "In Foldr In",419, 100, $pos[0], $pos[1] + 110, "", 24)
FileChangeDir(@ScriptDir)
FileClose($search)
Return 0
else 
$i = 0
While 1
$file = FileFindNextFile($search) 
If @error Then ExitLoop
$i = $i + 1
$file = StringUpper($file)
EnvSet($i , $file)
wend 
endif 
FileClose($search)
Return $i
EndFunc


Func GetAllFiletypeInDir($dir)
$pos = WinGetPos($Form)
FileChangeDir($dir)
SplashTextOn("Wait", "Wait Get All Files Type In Foldr In",419, 100, $pos[0], $pos[1] + 110, "", 24)
$chk = 0
$ix = 0
$outtypeX =""
$search = FileFindFirstFile("*.*")
If $search = -1 Then
SplashTextOn("Msg", "No files matched the search pattern",419, 100, $pos[0], $pos[1] + 110, "", 24)
Sleep(3000)
SplashOff()
FileClose($search)
FileChangeDir(@ScriptDir)
Return 0
else 
$i =0
While 1
$file = FileFindNextFile($search) 
If @error Then ExitLoop
$fileX =""
$file = StringUpper($file)
$i2 =1

While $i2 =1
if StringRight($file, 1) = '.' then 
$file = $fileX
$i2 = 0
else 
if StringLen($file) = 0 then $file = ""
if StringLen($file) = 0 then $i2 = 0
$fileX =  StringRight($file, 1) & $fileX 
$file = StringTrimRight( $file, 1 )
endif 
wend 
if $file <> "" then 
$i = $i + 1
EnvSet($i, $file)
$chk = 1
endif 
WEnd 

if $i = 1 then FileClose($search)
if $i = 1 then SplashOff()
if $i = 1 then FileChangeDir(@ScriptDir)
if $i = 1 then Return EnvGet(1) 
    
if $chk = 1 Then
For $i3 = $i to 1 Step -1
$var = EnvGet($i3)
For $i4 = $i to 1 Step -1
if $i4 = $i3 then $i4 = $i4 - 1
$var2 = EnvGet($i4)
if $var = $var2 then EnvSet($i3, "")
next 
next 

For $i5 = $i to 1 Step -1
if EnvGet($i5) <> "" then 
$outtype = EnvGet($i5)
$outtypeX = $outtypeX & $outtype & "|"
endif 
next 
$outtypeX = StringTrimRight ( $outtypeX, 1 )
SplashOff()
FileClose($search)
FileChangeDir(@ScriptDir)
Return $outtypeX
Else
SplashTextOn("Msg", "No files matched the search pattern",419, 100, $pos[0], $pos[1] + 110, "", 24)
Sleep(3000)
SplashOff()
FileClose($search)
FileChangeDir(@ScriptDir)
Return 0
endif 
endif 
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

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