SAS 識別資料夾下指定檔案型別及名稱

2022-08-26 11:00:15 字數 1683 閱讀 1147

/*step1:獲取指定資料夾的指定型別的所有檔案*/

%macro find_sas(dirname,type);/*引數有兩個:路徑,檔案型別字尾*/

libname sasjob "&sasjob_path";

%put %str(----------->dirname=&dirname);

%put %str(----------->type=&type);

data sasjob.dirfiles;

rc=filename("dir","&dirname");/*把&dirname值傳給檔案引用符「dir"*/

openfile=dopen("dir");/*得到路徑標示符openfile,dopen是開啟directory的sas內建函式*/

if openfile>0 then do;/*如果openfile>0表示正確開啟路徑*/

nummem=dnum(openfile);/*得到路徑標示符openfile中member的個數nummem*/

do ii=1 to nummem;

name=dread(openfile,ii);/*用dread依次讀取每個檔案的名字到name*/

filepath="&dirname"||name;

fnum=compress(name,".xml","");

fnum=compress(fnum,"user_case","");

output;/*依次輸出*/

end;

end;

keep name filepath fnum;/*只保留filepath、fnum列*/

run;

proc sort data=sasjob.dirfiles;/*按照name排序*/

by descending name;

%if &type^=all %then %do;/*是否過濾特定的檔案型別&type*/

where index(upcase(name),upcase(".&type"));/*y,則通過檢索name是否包含&type*/

%end;

run;

proc print data=sasjob.dirfiles;

run;

%mend find_sas;

%macro dir(sasjob_path,type,dataset_num);

libname sasjob "&sasjob_path";

%let sasjob_path=&sasjob_path.;

%find_sas(&sasjob_path,&type);

data temp(keep=name_sas name_log);

set sasjob.dirfiles;

name_sas=compress(name);

name_log=compress(tranwrd(name,'.sas','.log'),);

if name_sas ^='dirfiles.sas7bdat' and name_sas ^='dirfiles.sas7bdat.lck';

run;

proc sort data=temp out=sasjob.dirfiles;

by name_sas;

run;

%mend dir;

%dir(./02@compute_03_1_8,sas,0);

matlab讀取資料夾下指定型別的檔案

遍歷資料夾中的指定型別檔案 mm dir jpg 遍歷當前目錄下的jpg格式檔案,如果不是當前目錄下的,可以寫在 中 mm為num 1大小的struct結構,提取第i個檔案的檔名時使用mm i name即可 這個結構體中包含的屬性有name,date,bytes等 另外比較常用的就是allnames...

遍歷讀取指定資料夾下指定型別的所有檔案

經常碰到朋友,尤其是初學者對指定資料夾下指定型別檔案的讀取很困惑,這裡,我把自己經常用的程式貼出來,供初學者學些 include stdafx.h include windows.h include include include iostream using namespace std typed...

查詢指定資料夾下的檔案

include include using namespace std finddata t結構體 struct finddata t void main attrib為檔案屬性,由以下字元代表 fa rdonly 唯讀檔案 fa label 卷標號 fa hidden 隱藏檔案 fa direc ...