使用SAS和mkdir在Windows中创建目录结构 [英] Using SAS and mkdir to create a directory structure in windows

查看:797
本文介绍了使用SAS和mkdir在Windows中创建目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在SAS中从Windows创建目录结构。最好使用允许我指定UNC命名约定的方法,例如:

I want to create a directory structure in Windows from within SAS. Preferably using a method that will allow me to specify a UNC naming convention such as:

\\computername\downloads\x\y\z

我在网络上看到了许多使用DOS的例子通过%sysexec() x 调用 mkdir 命令。 mkdir命令的好处是,如果它们不存在,它将创建任何中间文件夹。我成功地测试了以下命令从提示符,它的行为正如预期(引用似乎并不重要,因为我没有空格在我的路径名称):

I have seen many examples for SAS on the web using the DOS mkdir command called via %sysexec() or the xcommand. The nice thing about the mkdir command is that it will create any intermediate folders if they also don't exist. I successfully tested the below commands from the prompt and it behaved as expected (quoting does not seem to matter as I have no spaces in my path names):

mkdir \\computername\downloads\x\y\z
mkdir d:\y
mkdir d:\y\y
mkdir "d:\z"
mkdir "d:\z\z"
mkdir \\computername\downloads\z\z\z
mkdir "\\computername\downloads\z\z\z"

从SAS运行罚款:

x mkdir d:\x;
x 'mkdir d:\y';
x 'mkdir "d:\z"';
x mkdir \\computername\downloads\x;
x 'mkdir \\computername\downloads\y';

但是从SAS运行时,这些不工作,例如:

But these do not work when run from SAS,eg:

x mkdir d:\x\x;
x 'mkdir d:\y\y';
x 'mkdir "d:\z\z"';
x mkdir \\computername\downloads\x\y\z ;
x 'mkdir "\\computername\downloads\z"';

** OR **;

%sysexec mkdir "\\computername\downloads\x\y\z ";

** OR **;

filename mkdir pipe "mkdir \\computername\downloads\x\y\z";
data _null_;
  input mkdir;
  put infile;
run;

它不工作。不仅这个,但窗口立即关闭,即使我有选项xwait 指定,因此没有机会看到任何错误消息。我已经尝试所有的方法与UNC路径和驱动器号路径,即。 D:\downloads\x\y\z

It does not work. Not only this but the window closes immediately even though I have options xwait specified so there is no opportunity to see any ERROR messages. I have tried all methods with both the UNC path and a drive letter path, ie. D:\downloads\x\y\z.

如果我看错误讯息由操作系统返回:

If I look at the error messages being returned by the OS:

%put %sysfunc(sysrc()) %sysfunc(sysmsg());

我得到以下结果:

-20006 WARNING: Physical file does not exist, d:\downloads\x\x\x.

查看 mkdir 命令的文档看起来它只支持在启用命令扩展时创建中间文件夹。这可以通过将 / E:ON 添加到 cmd.exe 来实现。我已尝试更改我的代码以使用:

Looking at the documentation for the mkdir command it appears that it only supports creating intermediate folders when 'command extensions' are enabled. This can be achieved with adding the /E:ON to cmd.exe. I've tried changing my code to use:

cmd.exe /c /E:ON mkdir "\\computername\downloads\x\y\z"

还是没有运气!

任何人都可以告诉我为什么互联网上的其他人似乎都可以从SAS内部工作,除了我?再次,它从一个DOS提示符,只是不是从SAS内工作正常。

Can anyone tell me why everyone else on the internet seems to be able to get this working from within SAS except for me? Again, it works fine from a DOS prompt - just not from within SAS.

我更喜欢一个专门解决这个问题的答案(我知道有其他解决方案使用多个步骤或 dcreate())。

I'd prefer an answer that specifically address this issue (I know there are other solutions that use multiple steps or dcreate()).

我正在运行WinXP 32Bit,SAS 9.3 TS1M2。感谢。

I'm running WinXP 32Bit, SAS 9.3 TS1M2. Thanks.

推荐答案

您需要使用mkdir选项-p创建所有子文件夹

You need to use the mkdir option -p which will create all the sub folders

ie

x mkdir -pc:\\\
ewdirectory\level 1\level 2;

x mkdir -p "c:\newdirectory\level 1\level 2";

这篇关于使用SAS和mkdir在Windows中创建目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆