View Full Version : how to search Computer for Specific File Types and add
ScottyDoesntKnow 04-09-2006, 01:37 PM Basically, I want to search in a certain defined directory all the files that are a certain file type. For example, if I wanted a button that will when pressed will go to a folder look for all the files that are .jpg and place them in a textScrollList.
|
|
Robert Bateman
04-09-2006, 02:24 PM
string $path = "C:/somePath/" ;
string $files[] = `getFileList -fld $path -fs "*.jpg"`;
for( $file in $files )
{
$fullPath = $path + $file;
print($fullPath + "\n"); // insert into GUI item instead...
}
ScottyDoesntKnow
04-09-2006, 02:52 PM
Thanks for the reply.
or if there are subdirectories, i've wrote a procedure several years ago to find all the files of a specific type:
proc string[] getDirs(string $cale, string $type){
string $allDirs[] = `getFileList -fld $cale`;
string $returnVal[];
for ($dir in $allDirs){
if (`filetest -d ($cale + $dir + "/")`) {
$returnVal[size($returnVal)] = $dir;
}
else {
string $buffer[];
tokenize $dir "." $buffer;
if ($buffer[size($buffer)-1] == $type)
$returnVal[size($returnVal)] = $dir;
}
}
return $returnVal;
}
proc getFiles2(string $cale, string $type, string $return[]){
string $dirs[] = getDirs($cale, $type);
for ($dir in $dirs){
if (`filetest -f ($cale + $dir)`) $return[size($return)] = ($cale + $dir);
else{
getFiles2(($cale + $dir + "/"), $type, $return);
}
}
}
global proc string[] getFiles(string $cale, string $extension){
string $returnVal[];
getFiles2($cale, $extension, $returnVal);
return $returnVal;
}
{
string $cale = "C:/";
$s = `timerX`;
string $files[] = getFiles($cale, "jpg");
$e = `timerX -st $s`;
print (size($files) + " fisiere in " + $e + " secunde");
}
CGTalk Moderation
04-09-2006, 03:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.