[英]Check if directory exists in my connected phone C#
插入iPhone時,可以訪問名為DCIM的文件夾。
文件路徑為“此PC \\ Will-iPhone \\ Internal Storage \\ DCIM”。
我的問題是如何檢查該文件夾是否存在? 我需要知道檢查的方法,但是不能在手機上檢查,因為它的文件路徑開頭沒有C \\或H \\或其他內容。
顯然,我無法上傳圖像,但它只是在設備和驅動程序下列為“ Will-iPhone”。
if (System.IO.Directory.Exists(@"\\Will-iPhone\Internal Storage\DCIM\"))
{
MessageBox.Show("Yes");
}
我也嘗試過使用不同數量的反斜杠,但起初使用“ This PC”,但到目前為止似乎沒有任何效果
任何幫助表示贊賞。 最好是C#btw
檢查DCIM
文件夾的屬性應該有完整路徑。
iPhone(和其他相機)是所謂的PTP設備,無法使用UNC路徑進行訪問。 相反,您需要自己實現PTP或找到合適的庫(根據Google的快速搜索,可能很難做到)。
除此之外,還有PTPdrive (無從屬關系)據稱將PTP設備映射到驅動器號。
附錄 :畢竟,可以使用WIA來訪問iPhone,所以我記下了這一點(向要使用的Microsoft Windows Image Acquisition Library v2.0添加COM引用):
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()));
}
}
請注意,如果找不到使用WIA復制影像的方法,則此方法僅適用於影像和視頻(盡管它們也以IMG開頭)。 對於初學者,以上內容就足夠了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.