Hi,
Please refer to this link. This might be helpful to you
Thanks
Anshul
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
can you kindly advise if this is possible?
We need to print in number order rather than name order.
The file name is currently in the format <Name> <Store number>. We'd like it to be in <Store number> <Name>. Can you kindly support?
Hi,
Please refer to this link. This might be helpful to you
Thanks
Anshul
Hi @Callum Treadwell ,
this should do the job:
$AllFiles = Get-ChildItem "C:\Temp" -Filter *.PDF
Foreach ($File in $AllFiles) {
$FileName = $File.Name
$StoreNumber = $FileName -replace "[^0-9]"
$StoreName = ($FileName).Substring(0,$FileName.IndexOf($StoreNumber))
$NewFileName = $StoreNumber + " " + $Storename + ".pdf"
Rename-Item -Path $File.Fullname -NewName $NewFileName
}
This is of course under the consideration that all files follow the same naming convention - "StoreName StoreNumber".
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!)
Regards
Stoyan Chalakov
You can try this:
# just some test data
$x = [PSCustomObject]@{BaseName='Anlaby 4688';FullName='c:\junk\Anlaby 4688'},
[PSCustomObject]@{BaseName='Archway 4028';FullName='c:\junk\Archway 4028'},
[PSCustomObject]@{BaseName='Arnos Grove 4952';FullName='c:\junk\Arnos Grove 4952'}
$x | # Replace this with your choice of file selection
ForEach-Object{
[PSCustomObject]@{
SortBy = ($_.BaseName -replace "^(.+?)\s(\d{4})$", '$2$1')
Orig = $_
}
} |
Sort-Object -Property SortBy |
Select-Object -Expand Orig
Hello there,
You can use the -replace operator together with a regular expression pattern to remove all strings from the start of the file name:
Get-ChildItem -Path C:\All -Filter *.pdf |
Rename-Item -NewName {$_.Name -replace '^\d+'}
A Windows PowerShell script for renaming files. https:// gist.github.com/csharpforevermore/94e6c1c4ca0ca1c2a91916fcd704dc92
-----------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer–