How to create folder in MTP device by c# windows application?
I referred to the portable device code written in C++.
Three keys are required to create a folder.
WPD_OBJECT_CONTENT_TYPE = WPD_CONTENT_TYPE_FOLDER
WPD_OBJECT_PARENT_ID
WPD_OBJECT_NAME
public void createFolder(string folderName, string parentObjectId)
{
IPortableDeviceContent content;
this._device.Content(out content);
string objectID = null;
IPortableDeviceValues values = GetRequiredPropertiesForFolderType(folderName, parentObjectId);
content.CreateObjectWithPropertiesOnly(values, objectID);
}
private IPortableDeviceValues GetRequiredPropertiesForFolderType(string folderName, string parentObjectId)
{
IPortableDeviceValues values = new PortableDeviceTypesLib.PortableDeviceValues() as IPortableDeviceValues;
//type
var WPD_OBJECT_CONTENT_TYPE = new _tagpropertykey();
WPD_OBJECT_CONTENT_TYPE.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
WPD_OBJECT_CONTENT_TYPE.pid = 7;
var WPD_CONTENT_TYPE_FOLDER = new _tagpropertykey();
WPD_CONTENT_TYPE_FOLDER.fmtid = new Guid(0x27E2E392, 0xA111, 0x48E0, 0xAB, 0x0C, 0xE1, 0x77, 0x05, 0xA0, 0x5F, 0x85);
values.SetGuidValue(ref WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FOLDER.fmtid);
var WPD_OBJECT_PARENT_ID = new _tagpropertykey();
WPD_OBJECT_PARENT_ID.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
WPD_OBJECT_PARENT_ID.pid = 3;
values.SetStringValue(ref WPD_OBJECT_PARENT_ID, parentObjectId);
//name
var WPD_OBJECT_NAME = new _tagpropertykey();
WPD_OBJECT_NAME.fmtid = new Guid(0xEF6B490D, 0x5CD8, 0x437A, 0xAF, 0xFC, 0xDA, 0x8B, 0x60, 0xEE, 0x4A, 0x3C);
WPD_OBJECT_NAME.pid = 4;
values.SetStringValue(WPD_OBJECT_NAME, folderName);
return values;
}
How to access an MTP USB device with python
One way to do this would be to install ADB (android debugging bridge, part of the SDK) and launch it as a child process from python. ADB can be used to, among other things, read from or write to, an android device.
Windows Portable Device - Notify when a new file is created / copied / deleted
WPD_EVENT_OBJECT_ADDED corresponds to MTP event ObjectAdded.
https://msdn.microsoft.com/en-us/microsoft-r/dn932706
I think that what events are really sent depends on concrete implementation of MTP protocol on concrete portable device.
I beleave that WPD API main purpose is to manage portable devices like a phones and music players, access and methods to work with usb flash drives are only exported as some layer of compatibility, and may not contain all functions.
If you want to receive such notifications not from portable devices implements MTP, but only from USB flash drives, you should take a look for example on filesystem minifilters
https://msdn.microsoft.com/en-us/windows/hardware/drivers/ifs/file-system-minifilter-drivers
They could give you needed callbacks.
Related Topics
How to Determine the Standard Deviation (Stddev) of a Set of Values
Firefox Browser Does Not Reload the Update CSS/Js Files
How to Convert JavaScript Datetime to C# Datetime
What Is the "Volatile" Keyword Used For
Using Image Control in Wpf to Display System.Drawing.Bitmap
How to Extract a File from an Embedded Resource and Save It to Disk
For VS. Linq - Performance VS. Future
Handling a Click for All Controls on a Form
What Does Synchronizationcontext Do
Better Naming in Tuple Classes Than "Item1", "Item2"
Send Push to Android by C# Using Fcm (Firebase Cloud Messaging)
Printing to a Client Printer from a Web App
How Does Creating a Instance of Class Inside of the Class Itself Works