mschol Posted August 25, 2007 Share Posted August 25, 2007 (edited) i'm trying to convert a php script to a autoit script: php: function getFiles($path, $fileFilter) { $dirStack = array($path); $files = array(); while (null !== ($dir = array_pop($dirStack))) { $dh = opendir($dir) or die('Error: Could not open directory: '.$dir); while (false !== ($file = readdir($dh))) { $skipDirs = array('.', '..', 'System Volume Information', 'Temporary Internet Files', 'Temp', 'WINDOWS'); if (!in_array($file,$skipDirs)) { $fullFile = $dir . $file; if (is_file($fullFile)) { if (preg_match($fileFilter, $file)) { $splitFullFile = $dir ."|". $file; $files[] = $splitFullFile; } } else if (is_dir($fullFile)) { $dirStack[] = $fullFile . '/'; } } } closedir($dh); } sort($files); return $files; } so far i have thought of the following code: Func getFiles($path) dim $dirStack,$dir,$dh,$skipDirs,$file,$fullFile,$splitFullFile,$files $dirStack = _ArrayCreate($path); while $dir = _ArrayPop($dirStack) $dh = FileFindFirstFile($dir & "*.*") while FileFindNextFile($dh); $skipDirs = _ArrayCreate('System Volume Information', 'Temporary Internet Files', 'Temp', 'WINDOWS'); if Not _ArrayBinarySearch($skipDirs,$file) Then $fullFile = $dir & $file; if Not _isfolder($fullFile) Then if StringRegExp($file,"\.(?-iavi|mpg|ogm|mkv)$",0) Then $splitFullFile = $dir ."|". $file; if IsArray($files) Then $files[] = $files = _Arrayadd($files,$splitFullFile); Else $files = _ArrayCreate($splitFullFile) EndIf EndIf else $dirStack[] = $fullFile & '/'; EndIf EndIf WEnd FileClose($dh); WEnd Return $files EndFunc but i dont get any output from the function anyone who can help me convert the php script to autoit (and i know about the _filelistToArrayEx() function, its just that i want a native autoit script that doesnt depend on a commandline in order to get file/folder lists) Edited August 25, 2007 by mschol Link to comment Share on other sites More sharing options...
therks Posted August 25, 2007 Share Posted August 25, 2007 (edited) *Edit: I also see a major problem. How many times do you read/compare the variable $file? Okay, now how many times do you SET it? Check the help file on using FileFindNextFile. It has a very good example of how to use the function, cus you can't really use it in a while loop the way you are. PHP has a very handy feature in that you can set a variable, while at the same time checking it, but AutoIt cannot do this. Also, what exactly do you want this function to do? Just list files into an array and return it? I think you're needlessly over complicating it by trying to force a PHP script into AutoIt. Besides some similar syntax, the two languages are totally different. What is your $path variable supposed to be? Cus I'm just seeing a problem with the line $dirStack = _ArrayCreate($path). The _ArrayCreate function works with multiple variable input, ie: _ArrayCreate('one', 'two', 'three', 'four', 'etc') Which gives you: Array ( [0] = 'one' [1] = 'two' [2] = 'three' [3] = 'four' [4] = 'etc' ) So this: $dirStack = _ArrayCreate($path) Gives you this: Array ( [0] = $path ) Edited August 25, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
weaponx Posted August 25, 2007 Share Posted August 25, 2007 Use Smoke_N's _FileListToArrayEx http://www.autoitscript.com/forum/index.ph...c=33930&hl=Don't reinvent the wheel Link to comment Share on other sites More sharing options...
mschol Posted August 25, 2007 Author Share Posted August 25, 2007 Use Smoke_N's _FileListToArrayEx http://www.autoitscript.com/forum/index.ph...c=33930&hl=Don't reinvent the wheelas i said, i'd like to have a native autoit way to do this...i assume that *should* be possible because if you , for example, cant run cmd.exe due to restrictions, you should be able to still run the script..i dont like to be dependent on OS features Link to comment Share on other sites More sharing options...
therks Posted August 26, 2007 Share Posted August 26, 2007 I reiterate: What exactly do you want this function to do? I'm sure it can't be that hard to figure out, but your existing code confuses me. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
mschol Posted August 26, 2007 Author Share Posted August 26, 2007 I reiterate: What exactly do you want this function to do? I'm sure it can't be that hard to figure out, but your existing code confuses me.list al files in a given directory, also give back all the files in the subdirectory'sit has a couple of additional things:1) look for certain extensions.2) exclude certain directory's (for example , the recycle bin and windows folder)and give back an array with only the file list (i do not need the amount of items in the array)i have the php script, which works perfect but i want a more portable way to do this (and i thought autoit would be the solution)but for now i will use the _FilelisttoArrayEx() function, with a couple of own additional checks in order to achieve what i want...and i still think there is a way to do all of this function (_filelisttoArray()) in a native autoit way.. (so that you dont have to rely on cmd)because when grouppolicy deny running cmd, the entire script will hang. Link to comment Share on other sites More sharing options...
therks Posted September 1, 2007 Share Posted September 1, 2007 and i still think there is a way to do all of this function (_filelisttoArray()) in a native autoit wayOh there definitely is (sorry I've taken so long to reply), I wrote up a function myself to do it for a program I made. What do you want the results to look like? You just want file names? [0] = file.txt [1] = fun.bat [2] = hello.wld etc Or full path+file? [0] = c:\file.txt [1] = c:\windows\fun.bat etc Considering you want to check subdirs I'm guessing fullpath+filename. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
therks Posted September 1, 2007 Share Posted September 1, 2007 Okay, give this a try. expandcollapse popupFunc _FileList($sFilePath, $sFileFilter = '', $sFolderExclude = '') Local $iFileCounter, $aFileList[10] Local $iFolderCounter, $aFolderList[10] Local $aSubfolderList[1] Local $hFind, $sFindFile If StringRight($sFilePath, 1) <> '\' Then $sFilePath &= '\' ConsoleWrite('Indexing ' & $sFilePath & @CRLF) $hFind = FileFindFirstFile($sFilePath & '*') While 1 Local $sFindFile = FileFindNextFile($hFind) If @error Then ExitLoop If StringInStr(FileGetAttrib($sFilePath & $sFindFile), 'd') Then If StringRegExp($sFilePath & $sFindFile & '\', $sFolderExclude) Then ContinueLoop EndIf $aFolderList[$iFolderCounter] = $sFilePath & $sFindFile & '\' $iFolderCounter += 1 If $iFolderCounter >= UBound($aFolderList) Then ReDim $aFolderList[$iFolderCounter + 10] EndIf Else If StringRegExp($sFindFile, $sFileFilter) Then $aFileList[$iFileCounter] = $sFilePath & $sFindFile $iFileCounter += 1 If $iFileCounter >= UBound($aFileList) Then ReDim $aFileList[$iFileCounter + 10] EndIf EndIf EndIf WEnd FileClose($hFind) For $iFolder = 0 To $iFolderCounter - 1 $aSubfolderList = _FileList($aFolderList[$iFolder], $sFileFilter, $sFolderExclude) If IsArray($aSubfolderList) Then For $iSubfolderFile = 0 To UBound($aSubfolderList) - 1 $aFileList[$iFileCounter] = $aSubfolderList[$iSubfolderFile] $iFileCounter += 1 If $iFileCounter >= UBound($aFileList) Then ReDim $aFileList[$iFileCounter + 10] Next EndIf Next If Not $iFileCounter Then Return 0 Else ReDim $aFileList[$iFileCounter] Return $aFileList EndIf EndFuncoÝ÷ ÙKí7éªëk Does that do what you need it to do? My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 2, 2007 Moderators Share Posted September 2, 2007 You could just look in randallc's signature and try out his FileListToArrayNew ... I believe he stayed away from the cmd option. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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