0

I have a bunch of files (and more coming) that are downloaded from the internet (pdf printed) but they do come with a lot of names that I do not need/want; so I want to have a text file with the things that I want to remove. example I have a text file with this two lines

Chapter 13. Text and Regular Expressions - Master-PowerShell _ With Dr. Tobias Weltner - PowerShell.com
- PowerShell Scripts, Tips, Forums, and Resources.htm

I want to keep adding lines of text to that file and then call it from another batch file to remove all the lines that are in this file, I got something working that I took from foxidrive here

I could keep adding strings to the rename, but I'm wondering if I could get all the lines to remove from a text file, and I know that there are programs out there (free ones) to do that, but I'd rather use the good old DOS batch. Thanks

Here is my code

@echo off
if Exist %CD%/temp.txt del %CD%/temp.txt
echo @echo off >%CD%/temp.txt
echo for /f "delims=" %%%%a in ('dir /a:-d /o:n /b') do call :next "%%%%a" >>%CD%/temp.txt
echo GOTO:EOF >>%CD%/temp.txt
echo :next >>%CD%/temp.txt
echo set "newname=%%~nx1" >>%CD%/temp.txt
Echo.>>%CD%/temp.txt
for /f "delims=" %%l in (%CD%\To_remove.txt) Do (
echo set "newname=%%newname:%%l=%%">> %CD%\temp.txt)
Echo.>>%CD%/temp.txt
echo ren %%1 "%%newname%%" >>%CD%/temp.txt
Start Temp.txt
Exit

I did save it as txt and opened at the end of script to see how it looks, it's just a matter of renaming it to .cmd and works. I had to add comments and edit my post to add it all together but works Thanks

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • Let me clarify I have a bunch of files downloaded from internet, you can create fake files with real names using all this in a text file Batch File Rename with Windows PowerShell.htm No More Lonely Nights Chords (ver 2) by Paul McCartney @ Ultimate-Guitar.Com.htm save it as Fake_Files.txt run this batch file For /F "tokens=*" %%G in (Fake_Files.txt) do Echo>%%G After that I wanted to write another text file that will contain _ PowerShell content from Windows IT Pro @ Ultimate-Guitar.Com _ Hey, Scripting Guy! Blog all that saved as a text file with the name To_remove.txt – user3055439 Oct 27 '17 at 15:21
  • and finally a script that will take all the lines in To_remove.txt and rename all the files in the folder removing the text that is in To_remove.txt. Found the solution and I'm posting it here just in case somebody could use it, it's a mix of two post one found here and the other I do not remember here is my batch – user3055439 Oct 27 '17 at 15:22

0 Answers0