このpowershellコードをRustに置き換えてください
一時ファイルをCドライブに指定してください
#if folder name begins with "0", registry doesn't work ..... (\0) == "newline"
#flags used when robocopying (overwrites files):
#/E :: copy subdirectories, including Empty ones
#/NP :: No Progress - don't display percentage copied
#/NJH :: No Job Header
#/NJS :: No Job Summary
#/NC :: No Class - don't log file classes
#/NS :: No Size - don't log file sizes
#/MT[:n] :: Do multi-threaded copies with n threads (default 8)
#when merging, these are added to not overwrite any files:
#/XC :: eXclude Changed files.
#/XN :: eXclude Newer files.
#/XO :: eXclude Older files.
#Set UTF-8 encoding
[console]::InputEncoding = [text.utf8encoding]::UTF8
[system.console]::OutputEncoding = [System.Text.Encoding]::UTF8
#set high process priority
process=Get−Process−Idpid
$process.PriorityClass = 'High'
function NoListAvailable {
if (mode -eq "m") {
echo "List of folders to be string1 does not exist!"
Start-Sleep 1
echo "Create the list by right-clicking on folders and selecting string2."
Start-Sleep 3
exit
} elseif (mode -eq "s") {
echo "Folder to be stringstring2."
Start-Sleep 3
exit
}
}
#copy / move
command=args[0]
mode=args[1]
if (args[2]−eqnull) #pwsh 4 and less
{
$regInsert = (Get-itemproperty -Path 'HKCU:\RCWM').dir #must not be string, but string array
#fix inserts like "\0" into registry, which translates into new line ... (every folder that starts with "0" has this problem)
if ($regInsert.count -ge 2) { #if more than 1 line
foreach (partinregInsert) {
[string]tempString+=[string]part + "\0"
}
#subtract last 2 symbols
[string]pasteIntoDirectory=[string]tempString.substring(0,$tempString.length-2)
}
else {
if (regInsert[0][2] -eq '"') { #copying directly into a drive
pasteIntoDirectory = reginsert[0].substring(0,2)
} else {
pasteIntoDirectory = [string](Get-itemproperty -Path 'HKCU:\RCWM').dir
}
}
} else {
#fix issues with trailing backslash when copying directly into drives - like C:
If ((args[2][−1]−eq"′")−and(args[2][-2] -eq "" )){ #pwsh v5
args[2].substring(1,2)
} elseif ((args[2][-2] -eq ':' )){ #pwsh v7
args[2].substring(0,2)
} else {
args[2]
}
}
pasteDirectoryDisplay="′"+pasteIntoDirectory + "'"
if (command -eq "mv") {
flag = "/MOV"
string1="moved"string2 = "'Move Directory'"
string3=string4 = "move"
} elseif (flag=""
string2 = "'RoboCopy'"
string4 = "copy"
}
#add mirror command
#get array of contents of paths inside HKCU\RCWM\command
array = (Get-Item -Path Registry::HKCU\RCWM\command).property 2> $null
arrayLength=(array|measure).count
#delete '(default)' in first place
try {
if ( array[0] -eq "(default)" ) {
if (arrayLength -eq 1) {
array=null
} else {
array=array[1..(array.Length-1)]
}
} elseif ( array -eq "(default)" ) { #empty registry and powershell v2
NoListAvailable
}
} catch {
NoListAvailable
}
#check if list of folders to be copied exist
if ( $arrayLength -eq 0 ) {
NoListAvailable
}
#skip prompt on single mode
if ($mode -eq "m") {
if ( arrayLength -eq 1 ) {
Write-host "You're about to string4 the following folder into" pasteDirectoryDisplay":"
} else {
Write-host "You're about to string4 the following" array.length"foldersinto"pasteDirectoryDisplay":"
}
$array
#Prompt
Do {
Valid=True
[string]prompt=Reaprompt) {
default {
Write-Host "Not a valid entry."
Valid=False
}
{"y", "yes" -contains _} {
copy = $True
}
{"n", "no" -contains $_} {
Do {
[string]prompt=Read−Host−prompt) {
default {
Write-Host "Not a valid entry."
Valid=False
}
{"y", "yes" -contains _} {
Remove-ItemProperty -Path "HKCU:\RCWM\command" -Name * | Out-Null
Write-Host "List deleted."
Start-Sleep 2
exit
}
{"n", "no" -contains $_} {
Write-Host "Aborting."
Start-Sleep 3
exit
}
}
} Until (Valid)
}
}
} Until (Valid)
} else { #on single mode just set copytoTrue
copy=True
}
If ( copy−eqTrue ) {
write-host "Begin $string3 ..."
write-host ""
foreach (pathinarray) {
#get folder name
if (psversiontable.PSVersion.Major -eq 2) {
folder = (path -split "\\")[-1]
} else {
folder = $path.split("")[-1]
}
#concatenation has to be done like this
[string]destination=[string]pasteIntoDirectory + "" + [string]$folder
#does source folder exist?
if (-not ( Test-Path -literalpath "path" )) {
echo "Source folder" path "does not exist."
continue
}
#if exist folder (or file)
If (Test-Path -literalPath "destination") {
#store folders for merge prompt
#overwrite - or just copy
[string[]]merge += $path
} else {
#make new directory with the same name as the folder being copied
New-Item -Path "destination"−ItemTypeDirectory>null
C:\Windows\System32\robocopy.exe "path""destination" "$flag" /E /NP /NJH /NJS /NC /NS /MT:32
if (command -eq "mv") {
cmd.exe /c rd /s /q "path"
}
echo "Finished string3folder"
}
}
#if merge array exists
if ($merge) {
Write-host "Successfully copied" (arrayLength - merge.length)"outof"arrayLength "folders."
if (merge.length -eq 1) {
Write-host "The following folder already exists inside" pasteDirectoryDisplay":"
} else {
Write-host "The following" merge.length"foldersalreadyexpasteDirectoryDisplay":"
}
$merge
Do {
Valid=True
[string]prompt) {
{"o", "overwrite" -contains $_} {
echo "Overwriting ..."
for (i=0;i -lt merge.length;i++) {
path=merge[folder = destination = folder
C:\Windows\System32\robocopy.exe "path""destination" "$flag" /E /NP /NJH /NJS /NC /NS /MT:32
if (command -eq "mv") {
cmd.exe /c cmd.exe /c rd /s /q "path"
}
echo "Finished overwriting $folder"
}
}
{"m", "merge" -contains $_} {
Write-Host "Merging ..."
for (i=0;i -lt merge.length;i++) {
path=merge[folder = destination = folder
C:\Windows\System32\robocopy.exe "path""destination" "$flag" /E /NP /NJH /NJS /NC /NS /XC /XN /XO /MT:32
if (command -eq "mv") {
cmd.exe /c rd /s /q "path"
}
echo "Finished merging $folder"
}
}
{"A", "abort" -contains _} {
Write-Host "Aborted string3 the remaining folders."
Do {
[string]prompt=Read−Hostprompt) {
default {
Write-Host "Not a valid entry."
Valid=False
}
{"y", "yes" -contains _} {
Remove-ItemProperty -Path "HKCU:\RCWM\command" -Name * | Out-Null
Write-Host "List deleted."
Start-Sleep 2
exit
}
{"n", "no" -contains _} {
Write-Host "Aborting."
Start-Sleep 3
exit
}
}
} Until (Valid)
}
default {
Write-Host "Not a valid entry."
Valid=False
}
}
} Until ($Valid)
}
Remove-ItemProperty -Path "HKCU:\RCWM$command" -Name * | Out-Null
echo ""
Write-Host "Finished!" -ForegroundColor blue
Start-Sleep 1
}