Skip to content

Commit 32c9bde

Browse files
committed
Add method to open the path in Windows File Explorer
1 parent 90ae39c commit 32c9bde

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<Target Name="ConfigurePolyfill" AfterTargets="ResolveLockFileAnalyzers" BeforeTargets="CoreCompile">
1010
<PropertyGroup>
11-
<MeziantouPolyfill_ExcludedPolyfills Condition="@(Analyzer->AnyHaveMetadataValue('NuGetPackageId', 'Microsoft.Windows.CsWin32'))">T:System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute</MeziantouPolyfill_ExcludedPolyfills>
11+
<MeziantouPolyfill_ExcludedPolyfills Condition="@(Analyzer->AnyHaveMetadataValue('NuGetPackageId', 'Microsoft.Windows.CsWin32'))">T:System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute|T:System.Diagnostics.CodeAnalysis.UnscopedRefAttribute</MeziantouPolyfill_ExcludedPolyfills>
1212
</PropertyGroup>
1313
</Target>
1414

src/Meziantou.Framework.FullPath/FullPath.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Meziantou.Framework;
1010

1111
[JsonConverter(typeof(FullPathJsonConverter))]
12-
public readonly struct FullPath : IEquatable<FullPath>, IComparable<FullPath>
12+
public readonly partial struct FullPath : IEquatable<FullPath>, IComparable<FullPath>
1313
{
1414
internal readonly string? _value;
1515

@@ -396,4 +396,24 @@ public bool TryGetSymbolicLinkTarget(SymbolicLinkResolutionMode resolutionMode,
396396
result = null;
397397
return false;
398398
}
399+
400+
[SupportedOSPlatform("windows5.1.2600")]
401+
public unsafe void OpenInExplorer()
402+
{
403+
if (IsEmpty)
404+
throw new InvalidOperationException("Path is empty");
405+
406+
var itemList = PInvoke.ILCreateFromPath(Value);
407+
if (itemList != null)
408+
{
409+
try
410+
{
411+
PInvoke.SHOpenFolderAndSelectItems(itemList, 0u, apidl: null, 0u).ThrowOnFailure();
412+
}
413+
finally
414+
{
415+
PInvoke.ILFree(itemList);
416+
}
417+
}
418+
}
399419
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
SHGetKnownFolderPath
1+
SHGetKnownFolderPath
2+
ILFree
3+
ILCreateFromPathW
4+
SHOpenFolderAndSelectItems

0 commit comments

Comments
 (0)