[Scilab-users] find all files of specific type on hard drive

P M p.muehlmann at gmail.com
Mon Sep 27 20:56:53 CEST 2021


@  Denis:
My fault: unix_g seem to be promising.

            f = unix_g('dir /A: *.txt /S')

looks promising.
thank you for the hint.
BR
Philipp



Am Mo., 27. Sept. 2021 um 20:37 Uhr schrieb P M <p.muehlmann at gmail.com>:

> @ Denis:
> - I forgot to mention: The files are under windows.
>
> @ Claus:
> - [...] I create a list of all files in that directory and read all of
> them [....]
>
> Yes , this is what I see when using "listfiles"
> What I am searching for would be:
> - choose a directory
> - choose a file extension
>
> --> create a list of all files with that extension in :
> -> the directory
> -> in all sub-directories
>
> I do doubt that there is a ready-to-use-function for that, so my question
> is: How to do it the most elegant way?
>
> I do not have a full aproach for this, yet.
> However I feel, that the first thing to do is, to get absolut pathnames to
> all folders,
> Afterwards I would scan each folder for the specifi file type.
>
>
> Mh...still thinking.
> Philipp
>
>
>
>
>
>
> Am Mo., 27. Sept. 2021 um 17:52 Uhr schrieb Claus Futtrup <
> cfuttrup at gmail.com>:
>
>> Hi Philipp
>>
>> This piece of code used to work (haven't checked with Scilab 6.1.1).
>> First I ask the user to select one file in the directory, then I create a
>> list of all files in that directory and read all of them:
>>
>> [units,typs,nams]=file(); // nams(1) = script file name incl. pathfpathname=strsplit(nams(1), [filesep()]);scriptpath = get_absolute_file_path(fpathname($));
>> printf("Please select a .txt measurement file\n");[filetoread pathtofile] = uigetfile("*.txt",scriptpath,"Choose measurement file");
>>     // For a start, assume script file is in the same directory as the data,
>>     // but don't be sure, read pathtofile and use it instead.readfile = pathtofile + "\" + filetoread;if length(filetoread)>4 then // one char + .txt expected, i.e. length>4
>>     // If user doesn't select any file, the above check prevents a crash
>>     chdir(pathtofile);
>>     if verbose then printf(" MSG: File found, thanks!\n"); end
>>
>> ...
>>
>> // Analyze - find all files in the path, who's filename is an// integer, which means - we expect it to be an angle.filelist=listfiles(pathtofile + "\*.txt");
>>
>>
>> ...
>>
>> imax=max(size(filelist));
>>
>> ...
>>
>> printf("Loop %i times: ",imax);for i=1:imax do
>>     printf("%i ",i) // Show progress
>>     [path fname extension] = fileparts(filelist(i));
>>     if isnum(fname) then    // check if fname (a string) contains
>>         d=evstr(fname);      // a number, and convert to number
>>
>>
>> I hope this is inspiring.
>>
>> Cheers,
>> Claus
>>
>> On 27-09-2021 16:50, P M wrote:
>>
>> Dear All,
>>
>> I need to find and list all files of a specific type on my hard
>> drive....How to do that in the most elegant way?
>>
>> E.g.:
>>
>> - find all *.txt files in "D:\"
>> - also find all '*.txt' files in each sub - directory, sub-sub-directory,
>> ..etc
>> - create a list that stores the absolute path names to the *.txt files.
>>
>> I am aware of
>> - dir
>> - findfiles
>> - listfiles
>> - ls
>>
>> But they only seem to list the files in a dedicated folder.
>>
>> Is there a function, that also searches all sub-folders automatically?
>>
>> Thank you,
>> Philipp
>>
>>
>>
>>
>> _______________________________________________
>> users mailing listusers at lists.scilab.orghttp://lists.scilab.org/mailman/listinfo/users
>>
>>
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210927/eb53e1e3/attachment.htm>


More information about the users mailing list