#!/usr/bin/perl #Url2Link v0.1 coded by Miguel D Velez use Tk; my $mw = new MainWindow; my $f = $mw->Frame->pack(-fill=>'x'); $mw->title( "Url2Link v0.1" ); $mw->geometry('+100+300'); $f->Label(-text=>'Url2Link v0.1') ->pack(); $f->Label(-text=>'by Miguel D Velez') ->pack(); my $report_variable = "Type in a list of URLs and press \"Process\" button to beging."; my $l = $mw->Frame->pack(-side=>bottom, -fill=>x, -ipadx=>10, -ipady=>3); $l->Label(-textvariable=>\$report_variable, -relief=>groove) ->pack(-fill=>both, -ipady=>3); my $b = $mw->Frame->pack(-side=>bottom, -fill=>'x', -pady=>5); $b->Button( -text=>"Exit", -relief=>groove, -command=> sub { exit } ) ->pack(-side=>bottom, -fill=>x, -ipadx=>10, -ipady=>3); $b->Button( -text=>"Process", -relief=>groove, -command=> sub { &process } ) ->pack(-side=>bottom, -fill=>x, -ipadx=>10, -ipady=>3); my $t = $mw->Frame->pack(-padx=>5); my $txt_body = $t->Scrolled(Text, -scrollbars=>e, -background=>white, -relief=>groove, -width=>50, -height=>15, -wrap=>'word') ->pack(); MainLoop; sub process { my @url_list = split /\s+/, $txt_body->get("1.0", "end"); my $count = 0; if (@url_list) { my $mkdir = mkdir "Links"; if (! $mkdir) { $report_variable = "Could not create \"Links\" folder in current directory. $!."; } else { $report_variable = "\"Links\" folder created."; } my $chdir = chdir "Links"; if (! $chdir) { $report_variable = "Could not access \"Links\" folder in current directory. $!."; } foreach(@url_list) { if ($_ =~ /^(http|https|ftp|ftps|w).+\.([a-zA-Z0-9_-]+)\..+/) { open FILEOUT, "> \u$2.url"; print FILEOUT '[DEFAULT]'."\n"; print FILEOUT "BASEURL=$_"."\n"; print FILEOUT '[InternetShortcut]'."\n"; print FILEOUT "URL=$_"."\n"; print FILEOUT 'Modified=0'."\n"; close(FILEOUT); ++$count } } chdir ".."; $txt_body->delete( "1.0", "end" ); $report_variable = "Converted $count URLs to link files. Please check the \"Link\" folder."; } else { $report_variable = "User input is empty. Please type at least one URL in textbox."; } }