現在のフォルダ内にあるファイル名をソートして取得
- このスクリプトを起動させるショートカット(.lnk)をSendToフォルダに入れて使用
Set-StrictMode -Version Latest
$gci = @(Get-ChildItem -Force -File -Name)
$srcCSharp = @'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace MyNamespace {
public class MyClass {
[DllImport(
"Shlwapi.dll",
EntryPoint = "StrCmpLogicalW",
CharSet = CharSet.Unicode
)]
public static extern int StrCmpLogicalW(
[MarshalAs(UnmanagedType.LPWStr)] string psz1,
[MarshalAs(UnmanagedType.LPWStr)] string psz2
);
public static List<string> SortStrCmpLogicalW(string[] str) {
List<string> tmp = new List<string>(str);
tmp.Sort(StrCmpLogicalW);
return tmp;
}
}
}
'@
Add-Type -Language CSharp -TypeDefinition $srcCSharp
$str = [MyNamespace.MyClass]::SortStrCmpLogicalW($gci)
Write-Host ($str -join "`n")
$str | Set-Clipboard
Set-StrictMode -Version Latest
$str = @(Get-Clipboard -Format Text -TextFormatType UnicodeText)
$srcCSharp = @'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace MyNamespace {
public class MyClass {
[DllImport(
"Shlwapi.dll",
EntryPoint = "StrCmpLogicalW",
CharSet = CharSet.Unicode
)]
public static extern int StrCmpLogicalW(
[MarshalAs(UnmanagedType.LPWStr)] string psz1,
[MarshalAs(UnmanagedType.LPWStr)] string psz2
);
public static void SortStrCmpLogicalW(ref string[] str) {
List<string> tmp = new List<string>(str);
tmp.Sort(StrCmpLogicalW);
tmp.CopyTo(str);
}
}
}
'@
Add-Type -Language CSharp -TypeDefinition $srcCSharp
[MyNamespace.MyClass]::SortStrCmpLogicalW([ref]$str)
Write-Host ($str -join "`n")
$str | Set-Clipboard