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
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
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
~bp
Change your .bat or .cmd file as so.
Also, Move your powershell line into a separate file named filename.ps1
Also, Move your powershell line into a separate file named filename.ps1
powershell.exe -ExecutionPolicy Bypass -File "c:\path\filename.ps1"
pause
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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'}}"
ASKER
Related q, can anyone help? https://www.experts-exchange.com/questions/28902101/edit-and-retrieve-file-attribute-info-using-dos-command.html
thanks
thanks
ASKER