【问题标题】:How to copy files from windows to mac in mono?如何以单声道将文件从Windows复制到Mac?
【发布时间】:2015-07-22 02:15:53
【问题描述】:

正如标题所说,我想以单声道将文件从 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路径。 有没有人可以帮帮我?

【问题讨论】:

    标签: c# macos xamarin mono


    【解决方案1】:

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

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

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

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

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

    【讨论】:

    • 感谢您的回复。如您所说,我将共享文件夹拖入终端,获取路径/Volumes/Share/Tem
    • 感谢您的回复。如您所说,将共享文件夹拖入终端后,我得到了路径/Volumes/Share/Tem。然后我将windowsPath 更改为/Volumes/Share/Tem,并将macPath 更改为/Users/Long/Desktop/TestFolder。有用。 Tem 文件夹是从 Windows 复制到 Mac...但我不知道“/volumes”是什么意思。
    • /Volumes 是文件系统中各种 hdd、sdd 和 smb(等)驱动器的挂载位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 2015-04-17
    • 2021-07-15
    • 2017-06-11
    相关资源
    最近更新 更多