读取文件问题
2011-09-23 21:34
162 查看
tianwild在其日志中做过详细的记录,题为《读取文件夹下所有相同文件》,链接为
http://www.mysas.net/sns/index.php?app=blog&mod=Index&act=show&id=1834&mid=43
恰巧,mysas论坛上有一问,不同之处,题为:如何读取目录下的所有文件夹名。goole到了结果,想到日后或许用到特此记录:
1. filename pipe
%macro filenames(location); %*--End the
with a semi-colon--*;
filename dirname pipe "dir ""%unquote(&location)"" /b" lrecl=32767;
%*--Surround the macro variable resolution with doubled-up double quotes and
data filenames;
infile dirname truncover;
input filename $char1000.;
put filename=;
run;
filename dirname clear; %*--Release the file handle by clearing it--*;
%mend;
%filenames(d:\);
2.filename dopen dnum dread
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;
%get_filenames(C:\temp\);
还有更多的思路,详见:http://stackoverflow.com/questions/1409543/using-sas-macro-to-pipe-a-list-of-filenames-from-a-windows-directory
http://www.mysas.net/sns/index.php?app=blog&mod=Index&act=show&id=1834&mid=43
恰巧,mysas论坛上有一问,不同之处,题为:如何读取目录下的所有文件夹名。goole到了结果,想到日后或许用到特此记录:
1. filename pipe
%macro filenames(location); %*--End the
%macrostatement
with a semi-colon--*;
filename dirname pipe "dir ""%unquote(&location)"" /b" lrecl=32767;
%*--Surround the macro variable resolution with doubled-up double quotes and
%unquote--*;
data filenames;
infile dirname truncover;
input filename $char1000.;
put filename=;
run;
filename dirname clear; %*--Release the file handle by clearing it--*;
%mend;
%filenames(d:\);
%get_filenames(d:\your dir) %*--Don't single quote your input parameter. macro quote instead, if necessary--*;
2.filename dopen dnum dread
%macro get_filenames(location);
filename _dir_ "%bquote(&location.)";
data filenames(keep=memname);
handle=dopen( '_dir_' );
if handle > 0 then do;
count=dnum(handle);
do i=1 to count;
memname=dread(handle,i);
output filenames;
end;
end;
rc=dclose(handle);
run;
filename _dir_ clear;
%mend;
%get_filenames(C:\temp\);
还有更多的思路,详见:http://stackoverflow.com/questions/1409543/using-sas-macro-to-pipe-a-list-of-filenames-from-a-windows-directory
相关文章推荐
- 读取文件时出现中文乱码问题的解决
- 遇到一个在脚本中读取文件内容占用文件句柄的小问题
- 解决IIS7虚拟目录出现HTTP 错误 500.19(由于权限不足而无法读取配置文件)的问题
- 解决生成的saiku文件读取中文乱码的问题
- 关于用Getline读取文件只能读取首行的问题
- Java对象序列化文件追加对象的问题,以及Java的读取多个对象的问题解决方法。
- 解决IntelliJ IDEA无法读取配置文件的问题
- 记一次mapreduce读取不到输入文件的问题
- java读取文件时在最后的缓冲区内存在多余数据的问题
- PHP file函数读取文件遇到<***>时的奇怪问题
- verilog读取的二进制与十六进制文件的格式问题
- matlab读取csv文件存在字符串的问题(2014.5.8)
- Java读取文件byte转化String问题
- JavaWeb中读取文件资源的路径问题
- java web中读取properties文件时的路径问题
- java读取文件的路径问题
- 读取含有BOM头的文件遇到的问题
- java读取.properties文件时的乱码问题
- 分析Python读取文件时的路径问题
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题