Nathan Schuetz
asked on
Script for finding and replacing text in a file name
Hello,
I am looking for a way to scrip a check of a file where it will read the first line in the file looking for a word like "Apple" in the text file, once it finds it I would like to change the name of the of the file using the word found in the middle of the file name.
For example, the file name 123_xxxxxxxxx.txt contains text in the first line that has the word Apple and if that word exists I need to change the name of that file to this 123_Apple_xxxxxxxxx.txt. Now if the word I am looking for is not there then no changes need to be made to the file. Also, I would like to ignore any other files that do not start with 123, say 134 for instance.
I would prefer to run this on Windows as much as possible and I would be running it on Windows 7 but might be moving to Windows 10 in the future.
Nathan
I am looking for a way to scrip a check of a file where it will read the first line in the file looking for a word like "Apple" in the text file, once it finds it I would like to change the name of the of the file using the word found in the middle of the file name.
For example, the file name 123_xxxxxxxxx.txt contains text in the first line that has the word Apple and if that word exists I need to change the name of that file to this 123_Apple_xxxxxxxxx.txt. Now if the word I am looking for is not there then no changes need to be made to the file. Also, I would like to ignore any other files that do not start with 123, say 134 for instance.
I would prefer to run this on Windows as much as possible and I would be running it on Windows 7 but might be moving to Windows 10 in the future.
Nathan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adam,
Thanks for the responce. Yes, this does solve my problem. It took me a few minutes to figure out that this was a Powershell scrip. Thanks again.