May 19, 2015 at 8:13 am
Hi All,
So I have a list of directories:
D:\Data\Load\customer1\Archive
D:\Data\Load\customer2\Archive
D:\Data\Load\customer3\Archive
D:\Data\Load\customer4\Archive
We receive files with spaces and i want to replace those spaces with dashes, but i want to only target items in the archive directories.
Im using this but cant find the command to make it only look files in the archive folder
Get-ChildItem D:\Data\Load -Filter "*.zip" -Recurse | Rename-Item -NewName {$_.name -replace ' ','-' } -whatif
this works but will also touch files in the root of the customers folder, which i would prefer not to happen.
Thanks in advance!
May 19, 2015 at 9:01 am
jzieleniuk (5/19/2015)
We receive files with spaces and i want to replace those spaces with dashes...
Why? There should be no problem with handling files with spaces. You just need to encapsulate them with double-quotes in whatever you're doing.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 20, 2015 at 8:20 am
jzieleniuk (5/19/2015)
Hi All,So I have a list of directories:
D:\Data\Load\customer1\Archive
D:\Data\Load\customer2\Archive
D:\Data\Load\customer3\Archive
D:\Data\Load\customer4\Archive
We receive files with spaces and i want to replace those spaces with dashes, but i want to only target items in the archive directories.
Im using this but cant find the command to make it only look files in the archive folder
Get-ChildItem D:\Data\Load -Filter "*.zip" -Recurse | Rename-Item -NewName {$_.name -replace ' ','-' } -whatif
this works but will also touch files in the root of the customers folder, which i would prefer not to happen.
Thanks in advance!
You could do this:
Get-ChildItem D:\Data\Load\*\Archive -Filter "*.zip" | Rename-Item -NewName {$_.name -replace ' ','-' } -whatif
This assumes that you don't have any other Archive folders with a similar \data\load\*\ path.
-Recurse is making the PS script look in every directory in the path. You don't need it to just look in the Archive directory.
May 20, 2015 at 9:27 am
This is just a clean up step I want to do. Previously whoever archived these files would put a space between the file and the datetime stamp when they manually archive and renamed the files. I have since automated the procedure, and had a lot of old files that i just wanted to get in a standardized format.
May 20, 2015 at 4:10 pm
Normally you can tell PowerShell if you want to include directories or not.
Ex:
Get-ChildItem D:\Data\Load -Filter "*.zip" -Recurse | where {$_.psiscontainer -eq $false} | Rename-Item -NewName {$_.name -replace ' ','-' } -whatif
Joie Andrew
"Since 1982"
May 22, 2015 at 5:36 am
Get-ChildItem D:\Data\Load -Directory | Get-ChildItem -Filter "*.zip" | Rename-Item -NewName {$_.name -replace ' ','-' } -whatif
Get the folders, then within each folder get the ZIP files and for each ZIP file rename it.
Think of each logical step and DON'T combine them to avoid side effects!!!
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply