【问题标题】:Is there a way to Alias a dead network path to a local directory in Windows 7?有没有办法将死网络路径别名到 Windows 7 中的本地目录?
【发布时间】:2018-09-25 17:31:55
【问题描述】:

我有一堆旧的批处理脚本,我可能需要恢复这些脚本,其中有数百个对死的特定网络路径的引用。有没有办法将 \\myNetWorkPath.com\SomeFolder\SomeFolder2 别名为特定的本地 Windows 7 目录?

例如,\\myNetWorkPath.com\SomeFolder\SomeFolder2 是 C:\SomeFolder2 的别名。 同样,\\myNetWorkPath.com\SomeFolder\SomeFolder2 是一个死的(不再工作)网络路径。

如果这没有任何意义,请告诉我。 谢谢!

【问题讨论】:

  • 记事本-“编辑”-“替换”...“全部替换”?
  • 对不起,我应该添加更多细节。大约有 50 个文件,以及一些实际构建这些悲伤网络目录的函数。如果别名是一个选项,那将非常有帮助。
  • 选择一种语言并编写一个快速而肮脏的应用程序,这将改变您的代码库。
  • 获取tour、阅读How to Ask和minimal reproducible example。这更像是SuperUser 类型的问题,而不是 SO。您可以尝试编辑主机文件,将机器名称映射到共享名称为“SomeFolder”的机器。

标签: windows batch-file alias


【解决方案1】:

继续我的“选择一种语言并编写一个快速而肮脏的应用程序来改变你的代码库”。评论...这里有一点 c# 可以帮助你。

    static void Main(string[] args)
    {
        //foreach file you drop onto the compiled EXE
        foreach (string item in args)
        {
            if (System.IO.File.Exists(item))//if the file path actually exists
            {
                ChangeThePath(item);
            }
        }
    }

    private static void ChangeThePath(string incomingFilePath)
    {
        string backupCopy = incomingFilePath + ".bck";
        System.IO.File.Copy(incomingFilePath, backupCopy);//make a backup
        string newPath = "c:\\This\\New\\Path\\Is\\Much\\Better";
        string oldPath = "c:\\Than\\This\\Deprecated\\One";
        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(incomingFilePath))
        {
            using (System.IO.StreamReader sr = new System.IO.StreamReader(backupCopy))
            {
                string currentLine = string.Empty;
                while ((currentLine = sr.ReadLine()) != null)
                {
                    sw.WriteLine(currentLine.Replace(oldPath, newPath));
                }
            }
        }
    }

【讨论】:

  • 一个有趣的解决方案,但这在技术上并不能回答 OP 的问题。
猜你喜欢
  • 1970-01-01
  • 2015-06-05
  • 2016-09-12
  • 1970-01-01
  • 2020-06-20
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 2019-05-05
相关资源
最近更新 更多