在Windows中复制DOORS结构

时间:2016-07-22 13:32:39

标签: ibm-doors

我正在尝试创建一个脚本,该脚本将复制Windows文件结构中的DOORS结构。我们的想法是运行脚本,并将当前位置的文件夹结构向下复制到用户的Windows文件夹结构中。选择。我是DXL的新手,但我找到了mkdir()函数。使用它时,我给它一个完整的文件路径似乎有问题,即C:\ output \ folder1 \。在这种情况下,除非C:\ output已经存在,否则它不会正确创建结构。

我的问题是,有没有办法让它可以同时创建多个文件夹级别,还是有更好的方法可以解决它?

2 个答案:

答案 0 :(得分:1)

您希望首先创建基本级别文件夹(在脚本中或外部),然后在循环访问DOORS中的每个项目/文件夹时,为该项目创建一个文件夹。例如:

mkdir("C:/output")
string p_name = ""
Item i
Project p
for p_name in database do {
  mkdir("C:/output/" p_name)
  p = project(p_name)
  for i in p do {
    if((type(i) "" == "Folder") || (type(i) "" == "Project")) {
      mkdir("C:/output/" fullName(i))
    }
  }
}

这应该让你开始,我没有时间测试它,但你可以根据自己的需要进行修改。

答案 1 :(得分:0)

史蒂夫的答案是正确的,虽然在我的情况下使用递归更有意义,因为我还必须做一些其他事情。

此代码是从我在IBM Developer Works论坛上找到的版本修改的,但我找不到源代码,如果再找到它我会链接它

public static class WindowsNetworking
{
    public static bool TryConnectToRemote(string remoteUnc, string username, string password, bool promptUser = false)
    {
        bool isUnc = remoteUnc != null && remoteUnc.Length >= 2 && remoteUnc[0] == '\\' && remoteUnc[1] == '\\';
        if (!isUnc)
        {
            return false;
        }
        ConnectToRemote(remoteUnc, username, password, promptUser);
        return true;
    }

    public static IDisposable CreateRemoteContext(string remoteUnc, string username, string password, bool promptUser = false)
    {
        return new RemoteFileSystemContext(remoteUnc, username, password, promptUser);
    }

    public static void DisconnectRemote(string remoteUNC)
    {
        var ret = (NetworkError) WNetCancelConnection2(remoteUNC, CONNECT_UPDATE_PROFILE, false);
        if (ret != NetworkError.NO_ERROR)
        {
            throw new Win32Exception((int) ret, ret.ToString());
        }
    }

    [DllImport("Mpr.dll")]
    private static extern int WNetUseConnection(
        IntPtr hwndOwner,
        NETRESOURCE lpNetResource,
        string lpPassword,
        string lpUserID,
        int dwFlags,
        string lpAccessName,
        string lpBufferSize,
        string lpResult
        );

    [DllImport("Mpr.dll")]
    private static extern int WNetCancelConnection2(
        string lpName,
        int dwFlags,
        bool fForce
        );

    [StructLayout(LayoutKind.Sequential)]
    private class NETRESOURCE
    {
        public int dwScope = 0;
        public int dwType = 0;
        public int dwDisplayType = 0;
        public int dwUsage = 0;
        public string lpLocalName = "";
        public string lpRemoteName = "";
        public string lpComment = "";
        public string lpProvider = "";
    }

    private static void ConnectToRemote(string remoteUNC, string username, string password, bool promptUser)
    {
        NETRESOURCE nr = new NETRESOURCE
        {
            dwType = RESOURCETYPE_DISK,
            lpRemoteName = remoteUNC
        };

        NetworkError ret;
        if (promptUser)
            ret = (NetworkError) WNetUseConnection(IntPtr.Zero, nr, "", "", CONNECT_INTERACTIVE | CONNECT_PROMPT, null, null, null);
        else
            ret = (NetworkError) WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);

        if (ret != NetworkError.NO_ERROR)
        {
            throw new Win32Exception((int) ret, ret.ToString());
        }
    }
}