[Scilab-users] find all files of specific type on hard drive
Claus Futtrup
cfuttrup at gmail.com
Mon Sep 27 17:52:36 CEST 2021
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. path
fpathname=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 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/228bd85c/attachment.htm>
More information about the users
mailing list