는 먼저 자신이 더 복잡 될 것입니다 카메라를 확인 DriveInfo
// Find removable disks
var drives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable && x.IsReady);
List<FileInfo[]> pictureHandles = new List<FileInfo[]>();
// Find all files of a certain type on each drive
foreach(var drive in drives)
{
pictureHandles.Add(
new DirectoryInfo(drive.Name)
.GetFiles("*.jpg",SearchOption.AllDirectories)
.ToArray());
}
// Do stuff with pictureHandles and identify
// which drive is which camera using System.Management
를 사용하여 이동식 디스크를 찾는 상대적으로 쉽다. 오직 당신 만이 그들을 식별하는 방법을 정확히 알게 될 것이지만 WMI
을 통해 System.Management
을 사용하여 제안 할 것입니다. Here의 등 특정 속성을 통해 USB에 디지털 카메라를 찾을 수 ManagementObjectSearcher
클래스를 보여주는 기사와 같은 GUID
, Name
, 내가 정확히 기억한다면, 당신이 그렇게처럼 초기화 것이다 :
var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_USB");
을
그리고 다음을 통해 반복,
foreach(var device in searcher.Get())
를 체크 속성 :
if(device["Name"].ToString().Equals("My Digital Camera"))
마지막으로 파일에 대한 작업을 모두 마쳤 으면 다음과 같이 삭제할 수 있습니다.
foreach(FileInfo[] files in pictureHandles)
{
for (int i = 0; i < files.Length; i++)
{
try
{
File.Delete(files[i].FullName);
}
catch(Exception ex)
{
// Failed to delete
}
}
}
1. 전체 드라이브를 복사하지 않는 이유는 무엇입니까? 2. ['DriveInfo'] (http://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives.aspx)와 스위치를 사용할 수 있습니다. 3. 디렉터리 구조 등을 구문 분석하십시오. 4. [this] (http://stackoverflow.com/questions/9038697/get-serial-number-of-boot-drive-and-other- info)를 사용하여 일련 번호를 가져옵니다. – UIlrvnd
1. 복사 할 수 있지만 카메라를 식별해야합니다. 2. 나는 아직 사용하지 않았습니다. 질문이었습니다. 무엇을해야합니까? 3. 나는 정말로 이해하지 못하지만, const 문자열에 대해 생각하지 않기를 바랍니다. 4. 나는 그것을 검사 할 것이다 – user1693057