From: Ya Huang on
Hi there,

The following code shows how I create/delete hundreds of folders and files.
The problem is that it is not very reliable, sometimes
a few folders won't be created, which cause code followed it
stop running:

data _null_;
set dd;
file "%sysfunc(pathname(work))\md.bat";
if _n_=1 then put 'rd/q/s "H:\My Documents"\.';
put 'md "H:\My Documents"\D' n_;
run;

options noxwait xsync;
x """%sysfunc(pathname(work))\md.bat""";

code for creating files in corresponding folders....

Dataset dd has one variable n_, which is integer number, but not necessary
consecutive. Each time the program run, n_ may be different, which means
new set of folders has to be created. Before the new set of folders are
created, the old folders has to be deleted, along with all the files in
there. The numbers of files in each folder varies, from one to a few
thousands. First thing the above code do is to clean up all old
folders/files (with rd/q/s command). It may takes several minutes, then
create new folders.

It seems to me that some of the md command is executed before the rd is
run, therefore, the newly created folder is deleted right after it is
created.

Any better way to do this?

Thanks

Ya