I want to search "URL=" in a file. As I am quite a noob in such things I collected some code snippets from stackoverflow, ... ;-)
http://www.dostips.com/forum/viewtopic.php?f=3&t=2836&start=30
Get list of passed arguments in Windows batch script (.bat)
How to receive even the strangest command line parameters?
my prob.: If the file or path contains the german "ö/ä/ü" or letters/signs from foreign languages in path or filename
D:\...\fähren
is treated like this
D:\...\f"hren
and findstr says "cant open file". Here is a part of my .bat
rem %cmdcmdline%
...
:file rem url from .url file - im file steht URL=http.... .htm
for /f "delims=" %%a in ('findstr /b "URL=" "%~1"') do set URL="%%a"
echo. %URL% | FIND /I "URL=">Nul || (set URL=""&goto startit)
rem delete all until URL
set URL="%URL:*URL=%
rem delete =
set URL="%URL:~2%
the .bat is called from within windows like this
HKEY_CLASSES_ROOT\InternetShortcut\shell\chrome\command "D:\sources\chrome\portable\chrome\chrome.exe" "%1"
rem %cmdcmdline% at the beginning of .bat looks OK
D:\4all\reisen\istanbul\verkehr\fähren>rem C:\Windows\system32\cmd.exe /c ""C:\Users\gigoelri\AppData\Local\Temp\333A.tmp\chrome_pause.bat" D:\sources\chrome\portable\chrome\chrome.exe D:\4all\reisen\istanbul\verkehr\fähren\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url "
the output of the for loop looks like this:
D:\4all\reisen\istanbul\verkehr\fähren>for /F "delims=" %a in ('findstr /b "URL=" "D:\4all\reisen\istanbul\verkehr\fähren\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url"') do set URL="%a"
FINDSTR: D:\4all\reisen\istanbul\verkehr\f"hren\Bosp_emin"n?_2h_14h30_12tl_SehirHatlari.url kann nicht geöffnet werden.(cannot be opened)
D:\4all\reisen\istanbul\verkehr\fähren>echo. | FIND /I "URL=" 1>Nul || (set URL="" & goto startit )
Codepage of my cmd window:
D:\sources\firefox\_install>chcp
Aktive Codepage: 850.
Mofi 4: Trying mofis methode 4 - result: file cant be found
rem C:\Windows\system32\cmd.exe /c ""C:\Users\gigoelri\AppData\Local\Temp\F54D.tmp\firefox_pause.bat" D:\sources\firefox\portable\firefox\firefox.exe D:\4all\reisen\istanbul\verkehr\fähren\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url "
...
D:\4all\reisen\istanbul\verkehr\fähren>for /F "usebackq tokens=1* delims==" %a in ("D:\4all\reisen\istanbul\verkehr\fähren\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url") do (if /I "%a" == "URL" (
set "URL=%b"
goto startit
) )
Die Datei "D:\4all\reisen\istanbul\verkehr\fähren\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url"
kann nicht gefunden werden.
The reason this time seems to be that the filename contains turkish letters like "Ş" instead of "S"
Edit 20150629:
System is Windows7 and Drive D: is NTFS
%~s1 doesnt work either:
D:\4all\reisen\istanbul\verkehr\fähren>for /F "usebackq tokens=1* delims==" %a in ("D:\4all\reisen\istanbul\verkehr\FHREN~1\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url") do (if /I "%a" == "URL" (
set "URL=%b"
goto startit
) )
Die Datei "D:\4all\reisen\istanbul\verkehr\FHREN~1\Bosp_eminönü_2h_14h30_12tl_SehirHatlari.url" kann nicht gefunden werden.
Explorer filename is: Bosp_eminönü_2h_14h30_12tl_ŞehirHatları.url The URL file was created by drag&drop the following URL from chrome URL: http://en.sehirhatlari.com.tr/en/timetable/short-bosphorus-tour-363.html
%windir%\system32\cmd.exe dir command shows:
neither the Ş nor the ı at the end are displayed OK.
And the .exe seems to be called already with the wrong name:
Edit 20150630a:
I covert the .bat using Bat_To_Exe_Converter_(x64).exe. I do this e.g. because this way registry entries can be unchanged and .exe can be pinned without extra effort.
And you are right, if windows calls .bat everything OK.
HKEY_CLASSES_ROOT\IE.AssocFile.URL\Shell\firefox\command
"D:\sources\firefox\_install\firefox.bat" "%1"
Can it be that windows passes parameters differently depending on wether it calls .bat or .exe ?
!!!! @Mofi: Thank your for your extended 1a support !!!!
It does not seem a prob of the "bat to exe converter" because: Please have a look at the first line rem statement. It differs quite a bit from the .exe screenshot postet under Edit 20150629. There is an additional statement "C:\Users\gigoelri\AppData\Local\Temp\F411.tmp\firefox_pause.bat", "" are set different and the URL is spelled different at the end ...ı.url"" instead of ...i.url "