sopching 发表于 2010-10-19 13:46
3# pobel
高手 能解释下程序?思路是:
1. 用pathname函数找出library的路径;
2. 第一个data步找出该路径下所有的文件夹,并保存完整的路径;
3. 第二个data步利用pipe执行系统命令,删除该路径下的文件夹。
这里主要是利用pipe的机制,本人对pipe也不是很熟悉,只是参照了某个读过的例子。
希望熟悉pipe的高手能解释一下。
下面是一组查找文件夹内容的DATA步,希望对你有点用:
*** What can you do---Get the whole list of options and description;
filename help pipe 'dir /?';
data _null_;
infile help;
input;
list;
run;
filename help clear;
/*
1 Displays a list of files and subdirectories in a directory.
2
3 DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
4 [/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
5
6 [drive:][path][filename]
7 Specifies drive, directory, and/or files to list.
8
9 /A Displays files with specified attributes.
10 attributes D Directories R Read-only files
11 H Hidden files A Files ready for archiving
12 S System files I Not content indexed files
13 L Reparse Points - Prefix meaning not
14 /B Uses bare format (no heading information or summary).
15 /C Display the thousand separator in file sizes. This is the
16 default. Use /-C to disable display of separator.
17 /D Same as wide but files are list sorted by column.
18 /L Uses lowercase.
19 /N New long list format where filenames are on the far right.
20 /O List by files in sorted order.
21 sortorder N By name (alphabetic) S By size (smallest first)
22 E By extension (alphabetic) D By date/time (oldest first)
23 G Group directories first - Prefix to reverse order
24 /P Pauses after each screenful of information.
25 /Q Display the owner of the file.
26 /R Display alternate data streams of the file.
27 /S Displays files in specified directory and all subdirectories.
28 /T Controls which time field displayed or used for sorting
29 timefield C Creation
30 A Last Access
31 W Last Written
32 /W Uses wide list format.
33 /X This displays the short names generated for non-8dot3 file
34 names. The format is that of /N with the short name inserted
35 before the long name. If no short name is present, blanks are
36 displayed in its place.
37 /4 Displays four-digit years
38
39 Switches may be preset in the DIRCMD environment variable. Override
40 preset switches by prefixing any switch with - (hyphen)--for example, /-W.
*/
*** The contents of a folder;
FileName MyDir Pipe 'dir "c:\files" /B';
data content;
infile MyDir lrecl=300 truncover;
input @1 content $100. ;
format content $100.;
run;
filename mydir clear;
*** Only the folders in a directory;
FileName MyDir Pipe 'dir "c:\files\sas\papers" /ad /b ';
data content;
infile MyDir lrecl=300 truncover;
input @1 content $100. ;
format content $100.;
run;
filename mydir clear;
FileName MyDir Pipe 'dir "c:\files"';
data folder;
infile MyDir lrecl=300 truncover;
input @1 folder $100. ;
if index(folder,"
folder=strip(substr(folder,index(folder,"
if folder ne "." and folder ne "..";
put _infile_;
format folder $100.;
run;
filename mydir clear;
*** Get every file(include folders) under a direcotory, down to the root;
FileName MyDir Pipe 'dir "c:\files\sas\papers" /s';
data content;
infile MyDir lrecl=300 truncover;
input @1 content $100. ;
format content $100.;
run;
filename mydir clear;
*** Get every file under the directory, down to the root, and store the full path;
FileName MyDir Pipe 'dir "c:\files\sas\papers" /b /s';
data content;
infile MyDir lrecl=300 truncover;
input @1 content $300. ;
format content $300.;
run;
filename mydir clear;
*** Get all folders under the directory, down to the root;
FileName MyDir Pipe 'dir "c:\files\sas\papers" /ad /b /s';
data content;
infile MyDir lrecl=300 truncover;
input @1 content $300. ;
format content $300.;
run;
filename mydir clear;