Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: Авторедактирование списка url-ов на основе HTTP статус кодов 
Author Message
MVV



PostPosted: Thu Jan 26, 2017 23:03    Post subject: Reply with quote

Батник (внутри вызывает повершелл) фильтрует урлы в буфере по валидным кодам возврата (2хх, 3хх - другие коды вызывают исключение внутри GetResponse):
Code:
@echo off
set "ARG_0=%~dpnx0"
powershell.exe -NoProfile -STA "iex (([IO.File]::ReadAllText($Env:ARG_0)) -replace '^(.*\n)*?.*<::::>.*\n', '')" & goto :EOF


Add-Type -Assembly System.Windows.Forms;


function testUrl($url, $timeout) {
   try {
      $webReq = [Net.WebRequest]::Create($url);
      $webReq.Method = 'HEAD';
      $webReq.Timeout = $timeout;
      $webRsp = $webReq.GetResponse();
      $webRsp.Close();
      Write-Host "``$url``: $([int]$webRsp.StatusCode)";
      $true;
   }
   catch {
      Write-Host "``$url``: $_";
   }
}


$urls = [Windows.Forms.Clipboard]::GetText() -split '\r?\n';
$goodUrls = @($urls | ? { $_ -match '^\w+://' -and (testUrl $_ $timeout) });
if ([Windows.Forms.MessageBox]::Show("Please click OK to copy $($goodUrls.Length) of $($urls.Length) urls to clipboard.", 'Url Filter', 1) -eq 1) {
   [Windows.Forms.Clipboard]::SetText(($goodUrls -join "`n") + "`n");
}


(добавлены установка метода HEAD и окошко сообщения в конце)
_________________
TCFS2 + TCFS2Tools: Полноэкранный режим и многое другое (обсуждение)
WINCMD.RU: AskParam, CopyTree, NTLinks, Sudo, VirtualPanel…


Last edited by MVV on Fri Jan 27, 2017 00:09; edited 2 times in total
View user's profile Send private message ICQ Number


Powered by phpBB © 2001, 2005 phpBB Group