Friday, March 23, 2012

Change the URLs in all .url files in the favorites folder

I wanted to play a joke on a co-worker and replace all the addresses in the .URL files in their favorites with a funnier (to me) address.

Now there's a lot of easier ways to do this, like making a generic .URL file, or just deleting them and downloading some new ones, but I wanted to make it difficult and parse through all the files and leave everything in tact just change the address in the URL= line.

-=The Script=-

@echo off
setlocal ENABLEDELAYEDEXPANSION
cd "%userprofile%\favorites"

for /f "tokens=* delims=" %%g in ('dir /b ^| find ".url"') do (
    for /f "usebackq delims=" %%a in ("%%g") do (
        set p=%%a
        echo !p!
        set u=!p:~0,4!
        echo !u!
        if /i "!u!" == "URL=" echo URL=http://lemonparty.org >> "%temp%\%%g"
        if /i not "!u!" == "URL=" echo %%a >> "%temp%\%%g"
    )
)
del /f /q *.url
copy /y "%temp%\*.url" *.url
del /f /q "%temp%\*.url"
pause

No comments:

Post a Comment

All comments moderated.
Comments like "sweet dude" or "this is awesome" or "thanks" will be denied,
if you've got something genuinely interesting to say, say it. Other than that just sit back and bask in the glory.