Creación de directorios durante una copia utilizando IFileOperation
Usando el contenedor IFileOperation de Stephen Toub para C # (enlazar), que ha estado funcionando bien hasta ahora. Ahora estoy tratando de hacer una copia para recopilar archivos de ubicaciones de red, cada ubicación de red en su propio subdirectorio.
\\FOO\data
dentroC:\gather\Foo_data
\\BAR\manage\current
dentroC:\gather\bar\manage
Y así. El problema esta enFileOperation.CopyItem
. Debe ser porque el directorio de destino aún no existe:IFileOperation
Lo creará durante la copia, ¿verdad? Utilicé la técnica deotra pregunta y cambiado de ToubFileOperation.CreateShellItem
a esto:
private static ComReleaser<IShellItem> CreateShellItem( string path )
{
try
{
return new ComReleaser<IShellItem>( (IShellItem)SHCreateItemFromParsingName( path, null, ref _shellItemGuid ) );
}
catch ( FileNotFoundException )
{
IntPtr pidl = SHSimpleIDListFromPath( path );
IShellItem isi = (IShellItem)SHCreateItemFromIDList( pidl, ref _shellItemGuid );
Marshal.FreeCoTaskMem( pidl );
System.Diagnostics.Debug.WriteLine( "Shell item: " + isi.GetDisplayName( SIGDN.DesktopAbsoluteParsing ) );
return new ComReleaser<IShellItem>( isi );
}
}
Me pegué elDebug.WriteLine
allí para comprobar que está funcionando, y parece estar funcionando bien; Escribe el camino de vuelta.
PeroIFileOperation.CopyItem
arroja unArgumentException
, y no puedo entender por qué. ¿No estoy haciendo el "IShellItem
para un archivo inexistente "correctamente? Sospecho que necesito obtenerSFGAO_FOLDER
allí, ya que estoy tratando de crear unIShellItem
para un inexistentedirectorio, no archivo, pero ¿cómo?