Link to home
Start Free TrialLog in
Avatar of xenium
xenium

asked on

find replace in windows 10

hi,

i want to find replace a bunch of filenames, the following bat file doesn't work because the second line isn't processed after the first, how do i fix it?

powershell
Dir | Rename-Item –NewName { $_.name –replace “smp3“,”smp19” }
pause


thanks
Avatar of xenium
xenium

ASKER

Avatar of Bill Prew
How are you running this?  It is a powersheel command, so you will need to either be typing in the second line into a powershell session, or placing it in a *.PS1 file and then executing it.  Please provide info on how you are running it.

~bp
Change your .bat or .cmd file as so.

Also, Move your powershell line into a separate file named filename.ps1

powershell.exe -ExecutionPolicy Bypass -File   "c:\path\filename.ps1"
pause

Open in new window

Avatar of xenium

ASKER

Thanks.

In a bat file. couple qs:

1. I prefer not to specify an absolute path, is a relative reference possible?

2. And is a single file execution possible? eg just a bat file
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenium

ASKER

Perfect thankyou!
I am glad to help, xenium. Have a nice day...
BTW, in your particular example, if you get a error "Source and destination path must be different." during the run, change from DIR to this:
PowerShell -ExecutionPolicy Bypass -Command "& {get-childitem .\* -include *smp3* | Rename-Item -NewName { $_.name -replace 'smp3','smp19'}}"

Open in new window