The modified script here will do exactly as requested:
If it meets an item within the D:\OneDrive path* (from the Total Commander's source panel),
it changes this to \\localhost\OneDrive-based path* as the URL=value for the target URL file as requested.
* The literal strings there can be changed so the path(s) can be defined dynamically per-machine and or per-user via the $env:OneDrive family variables.
Here, however, I leave the literals on purpose.
So the resulting URL file will become:
Code: Select all
[InternetShortcut]
URL=\\localhost\OneDrive\deeper\path\item.nameCode: Select all
[InternetShortcut]
URL=D:\OneDrive\deeper\path\item.nameCode: Select all
# OneDrive and localhost literal definitions
$OneDrive = 'D:\OneDrive'
$localhost = '\\localhost\OneDrive'Apparently, in the OP environment, they somehow directly mapped a domain to their D:\ drive, so let it be.
Finally, the script itself (both powershell.exe/Windows PowerShell (5.1) and pwsh.exe/Cross-Platform PowerShell (7+) are supported).
- makeURLfiles.ps1 script :: version specific to the u/fc62's request
Code: Select all
$time = [diagnostics.stopwatch]::StartNew() $path = [IO.DirectoryInfo]$pwd.path if ($path){ 'current working path'|Write-Host -f DarkGray $path.FullName } '' if ($args){ '%WL list file'|Write-Host -f DarkGray $list = [IO.FileInfo]$args[0] $list.Name '' '%P source path'|Write-Host -f DarkCyan $source = [IO.DirectoryInfo]$args[1] $source.FullName '%T target path'|Write-Host -f DarkCyan $target = [IO.DirectoryInfo]$args[2] $target.FullName } '' if (-not $args){ Write-Warning 'no parameters have been passed, exiting...' sleep -seconds 3 exit } if ($args -and $list.length -le 2){ Write-Warning '%WL list file is empty, exiting...' sleep -seconds 3 exit } # read input list file and collect items $items = [IO.File]::ReadLines($list)|foreach{ if(-not [string]::IsNullOrWhiteSpace($_)){ $_ } } if (-not $items.count){ Write-Warning '%WL list file contains no items, exiting...' sleep -seconds 3 exit } # OneDrive and localhost literal definitions $OneDrive = 'd:\OneDrive' $localhost = '\\localhost\OneDrive' # process items from %WL list file 'processing {0} items from %WL list file...' -f $items.count|Write-Host -f Yellow foreach ($item in $items){ # URL address: if item is within $OneDrive change it to $localhost if($item -like "$OneDrive\*"){ $URL = $item -replace [Regex]::Escape($OneDrive),$localhost } else { $URL = $item # otherwise leave item intact } # display current URL 'URL={0}' -f $URL # uncomment the following line if you need URI-formatted $URL #$URL = ([URI]$URL).AbsoluteUri # URL file contents $text=[Text.StringBuilder]::new() [void]$text.AppendLine('[InternetShortcut]') [void]$text.AppendLine("URL=$URL") # URL file destination path and naming $base = Split-Path $item -leaf $URLfile = [IO.Path]::combine($target,"$base.url") # avoid naming collisions $counter = 1 while ([IO.File]::Exists($URLfile)) { $URLfile = [IO.Path]::combine($target,"$base($counter).url") $counter++ } # write URL file [IO.File]::WriteAllText($URLfile,$text,[Text.Encoding]::Unicode) } '' # finalize $time.Stop() '{0} items processed for {1:mm\:ss\.fff}' -f $items.count, $time.Elapsed|Write-Host -f DarkCyan 'by {0}' -f $MyInvocation.MyCommand.Name sleep -seconds 7 - makeURLfiles.ps1 script :: version for other users (no \\localhost\ substitutions in URL=path)
Code: Select all
$time = [diagnostics.stopwatch]::StartNew() $path = [IO.DirectoryInfo]$pwd.path if ($path){ 'current working path'|Write-Host -f DarkGray $path.FullName } '' if ($args){ '%WL list file'|Write-Host -f DarkGray $list = [IO.FileInfo]$args[0] $list.Name '' '%P source path'|Write-Host -f DarkCyan $source = [IO.DirectoryInfo]$args[1] $source.FullName '%T target path'|Write-Host -f DarkCyan $target = [IO.DirectoryInfo]$args[2] $target.FullName } '' if (-not $args){ Write-Warning 'no parameters have been passed, exiting...' sleep -seconds 3 exit } if ($args -and $list.length -le 2){ Write-Warning '%WL list file is empty, exiting...' sleep -seconds 3 exit } # read input list file and collect items $items = [IO.File]::ReadLines($list)|foreach{ if(-not [string]::IsNullOrWhiteSpace($_)){ $_ } } if (-not $items.count){ Write-Warning '%WL list file contains no items, exiting...' sleep -seconds 3 exit } # process items from %WL list file 'processing {0} items from %WL list file...' -f $items.count|Write-Host -f Yellow foreach ($item in $items){ # get URL (can be post-processed if needed, or used as it is) $URL = $item # display current URL 'URL={0}' -f $URL # uncomment the following line if you need URI-formatted $URL #$URL = ([URI]$URL).AbsoluteUri # URL file contents $text=[Text.StringBuilder]::new() [void]$text.AppendLine('[InternetShortcut]') [void]$text.AppendLine("URL=$URL") # URL file destination path and naming $base = Split-Path $item -leaf $URLfile = [IO.Path]::combine($target,"$base.url") # avoid naming collisions $counter = 1 while ([IO.File]::Exists($URLfile)) { $URLfile = [IO.Path]::combine($target,"$base($counter).url") $counter++ } # write URL file [IO.File]::WriteAllText($URLfile,$text,[Text.Encoding]::Unicode) } '' # finalize $time.Stop() '{0} items processed for {1:mm\:ss\.fff}' -f $items.count, $time.Elapsed|Write-Host -f DarkCyan 'by {0}' -f $MyInvocation.MyCommand.Name sleep -seconds 7


