Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查我连接的电话C中是否存在目录#_C#_Iphone_Directory - Fatal编程技术网

C# 检查我连接的电话C中是否存在目录#

C# 检查我连接的电话C中是否存在目录#,c#,iphone,directory,C#,Iphone,Directory,当我插入iphone时,我可以访问一个名为DCIM的文件夹 文件路径为“This PC\Will iPhone\Internal Storage\DCIM” 我的问题是如何检查该文件夹是否存在?我需要知道如何检查,但不要在手机上,因为它的文件路径开头没有C\或H\或其他内容 显然,我无法上传图像,但它只是在设备和驱动程序下被列为“Will iPhone” 我也尝试过使用不同数量的反斜杠,开始时使用“ThisPC”,但到目前为止似乎没有任何效果 感谢您的帮助。最好是C#btw检查DCIM文件夹的属

当我插入iphone时,我可以访问一个名为DCIM的文件夹

文件路径为“This PC\Will iPhone\Internal Storage\DCIM”

我的问题是如何检查该文件夹是否存在?我需要知道如何检查,但不要在手机上,因为它的文件路径开头没有C\或H\或其他内容

显然,我无法上传图像,但它只是在设备和驱动程序下被列为“Will iPhone”

我也尝试过使用不同数量的反斜杠,开始时使用“ThisPC”,但到目前为止似乎没有任何效果


感谢您的帮助。最好是C#btw

检查
DCIM
文件夹的属性,应该有完整的路径。

iPhone(和其他摄像头)是所谓的设备,不能使用UNC路径访问。相反,您需要自己实现PTP或找到一个合适的库(根据快速谷歌搜索,这可能很难)

除此之外,还有(无附属机构)据称将PTP设备映射到驱动器号

附录:毕竟,可以使用WIA访问iPhone,所以我记下了这一点(添加对Microsoft Windows Image Acquisition Library v2.0的COM引用以供使用):


请注意,如果找不到使用WIA复制图像的方法,则此方法仅适用于图像和视频(尽管这些视频也是从IMG开始的)。首先,上面的内容应该足够了。

我这么做了,上面写着“这台电脑\Will iPhone\Internal Storage”谢谢,我想那对我来说就到此为止了。我不能使用PTPdrive,因为我希望它能适用于所有iPhone。我不太擅长编程,你说的第一种方式听起来比它的价值要难得多,只是意识到你不想复制文件。。。你还觉得这个答案有用吗?你能解释一下我如何使用WIA吗?我想测试一下代码是否适合我,但我不能添加“使用WIA”;我也不知道像你说的那样添加COM什么。我没有那么丰富的编码经验,而且我也使用NETFramework3.5,所以它可以在WindowsXP上运行。感谢您的帮助您应该能够在VisualStudio中右键单击项目,
Add->Reference…->COM->Type Libraries
然后搜索
图像
(对我来说,这会返回3次点击)。添加Microsoft Windows Image Acquisition Library v2.0已获取,非常感谢您迄今为止的帮助。我输入了代码,有两个错误。我不能上传图片,但他们在这里。。。item.Transfer().SaveFile(Path.Combine(Path,targetName));-“savefile”用红色下划线,表示对象不包含savefile的定义,下一个定义是。。。Path.Combine(savePath,iPhone.Properties[“Name”].get_Value());-只是说它有无效的论点。请原谅我的无知,我不是最擅长编程的
if (System.IO.Directory.Exists(@"\\Will-iPhone\Internal Storage\DCIM\"))
        {
            MessageBox.Show("Yes");
        }
using System.Collections.Generic;
using System.IO;
using System.Linq;
using WIA;

public static class WiaCopy
{
    public static IEnumerable<IDeviceInfo> GetAppleDevices()
    {
        return new DeviceManager().DeviceInfos.Cast<IDeviceInfo>().Where(di =>
            di.Type == WiaDeviceType.CameraDeviceType
            && di.Properties["Manufacturer"].get_Value() == "Apple Inc."
            && di.Properties["Description"].get_Value() == "Apple iPhone");
    }

    public static IEnumerable<Item> GetImgItems(IDeviceInfo deviceInfo)
    {
        var device = deviceInfo.Connect();
        return device.Items.Cast<Item>().Where(i => i.Properties["Item Name"].get_Value().ToString().StartsWith("IMG"));
    }

    public static void TransferItem(Item item, string path)
    {
        // TODO: should use .mov for videos here
        var targetName = item.Properties["Item Name"].get_Value() + ".jpg";
        Directory.CreateDirectory(path);
        item.Transfer().SaveFile(Path.Combine(path, targetName));
    }
}
var savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Auto Import");

foreach (var iPhone in WiaCopy.GetAppleDevices())
{
    foreach (var imgItem in WiaCopy.GetImgItems(iPhone))
    {
        WiaCopy.TransferItem(imgItem, Path.Combine(savePath, iPhone.Properties["Name"].get_Value()));
    }
}