c# - 如何将文件从 windows 复制到单声道的 mac?

标签 c# macos xamarin mono

正如标题所说,我想以单声道将文件从 Windows 复制到 Mac。这是我的 C# 代码:

using System;
using System.IO;
namespace CopyFiles
{
    public class EmptyClass
    {
        public static void Main()
        {
            string windowsPath = "\\\\another-machine-name\\Share\\Tem";
            string macPath = "..";
            CopyFiles (windowsPath, macPath);
        }

        public static bool CopyFiles(string oldPath, string newPath)
        {

            Directory.CreateDirectory (newPath); 
            if (!Directory.Exists (oldPath)) { 
                return false;
            }

            string[] directories = Directory.GetDirectories (oldPath);
            if (directories.Length > 0) { 
                foreach (string   d   in   directories) { 
                    CopyFiles (d, newPath + d.Substring (d.LastIndexOf ("\\")));
                } 
            } 

            string[] files = Directory.GetFiles (oldPath);
            if (files.Length > 0) { 
                foreach (string   s   in   files) { 
                    File.Copy (s, newPath + s.Substring (s.LastIndexOf ("\\"))); 
                } 
            } 
            return true;
        }
    }
}

winowsPath 是共享路径。我不知道怎么写mac路径。 有没有人可以帮助我?

最佳答案

我假设代码将在 OS X 端运行。

OS X 的文件系统 / 有一个根节点。其他所有内容都在该根节点下。例如,您的主文件夹中的 document.doc 将被引用为 /Users/Long/document.doc

如果您不确定文件的位置,则可以按照以下步骤查找:

  • 在 Finder 中找到容器文件夹
  • 打开一个新的终端窗口
    • 输入cd{空格}
  • 将文件夹从 Finder 拖到终端
  • {return}
  • 输入pwd{return}

这会将当前工作目录更改为您放入 finder 的目录,然后 pwd 会将工作目录打印出来(在屏幕上),以便您可以看到路径应该是什么样子。

关于c# - 如何将文件从 windows 复制到单声道的 mac?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31552760/

相关文章:

android - Xamarin Forms - ListView 绑定(bind)更新行 UI

c# - 如何将列表从 C# 传递到 F#?

c# - 需要正则表达式的帮助来解析表达式

c# - 线程和C#中的新Task库

c++ - dyld : Library not loaded:/usr/local/opt/jpeg/lib/libjpeg. 9.dylib OpenCV C++ MacOS

c# - Xamarin 中的 SignalR 客户端

c# - 如何使用 AutoMapper 将 IEnumerable 映射到列表

events - 获取 CGEvent Tap 中按下的修改键

html - 替换或修改滚动条,使其在 MacOS 上始终可见

c# - 如何使用 Xamarin 在 iPad 上实现 UIDocumentInteractionController