Pakku Posted July 19, 2007 Share Posted July 19, 2007 (edited) Hi all,I had a dir with several dirs in it and in there several files. I wanted to 'extract' all of these files in just one dir. So I came up with the following:Func _ExtractDir($dir,$dest) $search = FileFindFirstFile($dir & "*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop EndIf If StringInStr(StringRight($file,4),".") = 1 Then $destfile = $dest & StringReplace($dir & $file,"\","-") FileCopy($dir & "\" & $file,$destfile) Else _ExtractDir($dir & $file & "\",$dest) EndIf WEnd FileClose($search) EndIf EndFuncTo ensure that no filename is the same, the files will be copied to the destination with the pathe where it was in but the backslahses are replaced by a "-" sign. This also makes it easy to 'group' them and to keep the overview Note:If you want to 'extract' the dir where it is in: also know as the @ScriptDir, the first parameter has to be blanck: "" All parameters have to end with a backslash: "\", but the above rule is overruling this oneI havn't test to extract TO the same dir as you want to 'extract', but I don't think it's a good idea.As you may see, this script splits the files from the folders by checking if the dot (".") is on the 4th place counted from the end. So it 'thinks' that files always have a 3 char extension!Feedback, bug reports and stuff is more than welcome Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
NELyon Posted July 20, 2007 Share Posted July 20, 2007 Can't this throw a recursion error? Link to comment Share on other sites More sharing options...
Pakku Posted July 20, 2007 Author Share Posted July 20, 2007 (edited) Can't this throw a recursion error?Not that I know of, I used it myself and it didn't.Why? Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
WolfWorld Posted July 20, 2007 Share Posted July 20, 2007 (edited) I fix it a bit Func _ExtractDir($dir,$dest ) $search = FileFindFirstFile($dir & "*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file,".") = 1 Then;Remember File ext can be more than or less than 3- $dest = $dest & StringReplace($dir & $file,"\","-") FileCopy($file,$dest) Else _ExtractDir($dir & $file & "\", $dest) EndIf WEnd FileClose($search) EndIf EndFunc Edited July 20, 2007 by athiwatc Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets! Link to comment Share on other sites More sharing options...
Pakku Posted July 20, 2007 Author Share Posted July 20, 2007 (edited) I fix it a bit Func _ExtractDir($dir,$dest ) $search = FileFindFirstFile($dir & "*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file,".") = 1 Then;Remember File ext can be more than or less than 3- $dest = $dest & StringReplace($dir & $file,"\","-") FileCopy($file,$dest) Else _ExtractDir($dir & $file & "\", $dest) EndIf WEnd FileClose($search) EndIf EndFuncoÝ÷ Ûú®¢×¶+)¢Èëhr·µæ¢W^¯§h¶)â·}ÚºÚ"µÍYÝ[Ò[ÝÝ[ÔYÚ ÌÍÙ[K JK ][ÝË][ÝÊHH HÜ This might work, it your extension is 3 or 4 char long Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Pakku Posted July 20, 2007 Author Share Posted July 20, 2007 (edited) Updated script, check out the first post! Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
mrrlg Posted August 1, 2007 Share Posted August 1, 2007 When I define the source and destination and attempt to run your script, nothing happens. What am I doing wrong?$dir="C:\salesreports\"$dest="C:\archive\sales\"Func _ExtractDir($dir,$dest) $search = FileFindFirstFile($dir & "*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop EndIf If StringInStr(StringRight($file,4),".") = 1 Then $destfile = $dest & StringReplace($dir & $file,"\","-") FileCopy($dir & "\" & $file,$destfile) Else _ExtractDir($dir & $file & "\",$dest) EndIf WEnd FileClose($search) EndIfEndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now