dustock
asked on
Batch file help
I am creating a batch file to loop through the URL links on a users desktop and delete specific ones. Everything is working fine except for the if conditions in my loop. I thought maybe I had to add an escape character for the = sign for strOldurl and strNewurl but even putting in ^=PRD didn't seem to help.
What I want is to write the path to strOldPath and strNewPath so that I can delete them. When I debug by adding echo statements I can see that strOldPath and strNewPath have no value
What I want is to write the path to strOldPath and strNewPath so that I can delete them. When I debug by adding echo statements I can see that strOldPath and strNewPath have no value
rem @echo off
SETLOCAL
set strOldUrl = "https://url.com/logindisp?tenant=PRD"
set strNewUrl = "https://url.com/logindisp?tenant=TST"
set strOldPath = ""
set strNewPath = ""
set url = ""
FOR %%f in (dir "C:\Users\Public\Desktop\*.url") DO (
call:findurl %%f
if url == strOldUrl (
strOldPath = %%f
)
if url == strNewUrl (
strNewPath = %%f
)
)
rem Clean up shortcuts
del strOldPath
del strNewPath
copy "C:\Temp\NEW-Site.url" "C:\Users\Public\Desktop" /Y
:findurl inputfile
set url=
for /f "tokens=2 delims==" %%i in ('findstr URL %1') do set url=%%i
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome, exactly what I was looking for! Thank you.
Welcome, glad that helped.
~bp
~bp
Note that this script has two major errors:
1. It will delete a maximum of one URL file with strOldUrl in it, and a maximum of one URL file with strNewUrl in it. If two or more of either type are present, the first ones found will be left.
2. If not both strOldUrl and strNewUrl are found in URL files, the script will try to delete everything in the current folder, because there will be a 'del ""' statement.
1. It will delete a maximum of one URL file with strOldUrl in it, and a maximum of one URL file with strNewUrl in it. If two or more of either type are present, the first ones found will be left.
2. If not both strOldUrl and strNewUrl are found in URL files, the script will try to delete everything in the current folder, because there will be a 'del ""' statement.
Open in new window