我要删除一个文件夹,其中一个子文件夹的名称为“con”,这是一个保留的设备名称,因此C#会引发异常。
在CMD中,我可以删除rmdir \\.\c:\con
这样的文件夹,但是在C#中我尝试了很多变种,并且总是得到路径格式不受支持。例如,以下内容不起作用:Directory.Delete("\\\\" + Environment.UserDomainName + "\\c:\\test")
。
请注意,我不想依赖外部命令,例如CMD的del
命令等。
答案 0 :(得分:3)
您必须绕过.net框架并使用FREQ
表示法删除文件,并使用p / invoke进行* make some survey data with unformatted responses;
data have;
do respondent_id = 1 to 10000;
array responses KCI_1-KCI_80;
do _n_ = 1 to dim(responses);
responses(_n_) = ceil(4*ranuni(123));
end;
output;
end;
run;
* make some format data for each question;
data responseMeanings;
length questionID 8 responseValue 8 responseMeaning $50;
do questionID = 1 to 80;
fmtname = cats('Q',questionID,'_fmt');
peg = ranuni (1234); drop peg;
do responseValue = 1 to 4;
select;
when (peg < 0.4) responseMeaning = scan('Never,Seldom,Often,Always', responseValue);
when (peg < 0.8) responseMeaning = scan('Yes,No,Don''t Ask,Don''t Tell', responseValue);
otherwise responseMeaning = scan('Nasty,Sour,Sweet,Tasty', responseValue);
end;
output;
end;
end;
run;
* create a custom format for the responses of each question;
proc format cntlin=responseMeanings(rename=(responseValue=start responseMeaning=label));
run;
* macro to associate variables with the corresponding custom format;
%macro format_each_response;
%local i;
format
%do i = 1 %to 80;
KCI_&i Q&i._fmt.
%end;
;
%mend;
* compute frequency counts;
proc freq data=have;
table KCI_1-KCI_80;
%format_each_response;
run;
调用
\\?\c:\con