I have four folders in drive d: and in each folder there is a file called file.txt. If I use the batch script below, all four txt files get compressed and they are compressed without the password and without hidding the file name inside. I only want to compress the file in Folder 4. My password is MYPass and my compressed bz2 is FileCompressed.bz2
I need to only compress the file in Folder 4, assuming yes on all queries, showing no messages, maximum compression, with password, with deletion of File.txt (on Folder 4) after compression, with encription of the name of the file. I used the "rar -?" in windows prompt but I am still not knowing how to get the results I need. Can anyone help?
d:
\Folder 1\file.txt
\Folder 2\file.txt
\Folder 3\file.txt
\Folder 4\file.txt
#echo off
rar a -hpMyPass -m5 -y -df "d:\Folder 4\FileCompressed.bz2" "d:\Folder 4\File.txt"
Try this sample code :
#echo off
Title Zip Files with rar.exe in command line
color 0A & Mode 75,10
Set "Folder2Compress=D:\Folder 4"
If Not exist "%Folder2Compress%\" MD "%Folder2Compress%\"
(echo This is a test to see if the compression with encryption in winrar works or not)>"%Folder2Compress%\File.txt"
Set "CompressedFolder=%~dp0FileCompressed.bz2"
set "RAR_Password=MyPass"
Set "Log=%~dpn0_Log.txt"
Set "strProgramFiles=%ProgramFiles%"
if exist "%ProgramFiles(x86)%" (
set "strProgramFiles=%ProgramFiles(x86)%"
) else (
set "strProgramFiles=%ProgramFiles%"
)
Set RAR="%strProgramFiles%\WinRAR\RAR.exe"
If Exist %RAR% ( Goto :RAR ) else ( Goto :Fail )
REM -----------------------------------------------------------------
:RAR
%RAR% a -m5 -y -df -hp%RAR_Password% "%CompressedFolder%" "%Folder2Compress%\">nul 2>&1
IF "%ERRORLEVEL%" EQU "0" ( GOTO Succes ) Else ( Goto Fail )
REM -----------------------------------------------------------------
:Succes
Echo(
Echo All Files are zipped succesfuly ! in "%CompressedFolder%"
Echo All Files are zipped succesfuly ! in "%CompressedFolder%" > "%Log%"
Start "" /MAX "%Log%"
Timeout /T 3 /nobreak>nul
Exit /b
REM -----------------------------------------------------------------
:Fail
Color 0C
Echo(
echo There was an error !
echo There was an error ! >"%Log%"
Start /MAX "" "%Log%
Timeout /T 3 /nobreak>nul
REM -----------------------------------------------------------------
Related
I currently have a batch file to create an nfo of all file inside a folder.
Now I'm looking to add a function for a "single file".
i have a part that works but the nfo file text includes the path of the file in the "Complete name" line.
I would like to know how to not display this path before the filename.
The nfo is currently saved at the location of the file, it should stay that way.
there is the batch file (without the "if single file") :
Tx to #Compo for this.
#Echo Off
SetLocal EnableExtensions
Set "MIExe=%UserProfile%\Standalone\MediaInfo\MediaInfo.exe"
Set "OutExt=nfo"
Set "HR=------------------------------------------------------------------"
For %%G In ("%~1") Do If "%%~aG" Lss "d" (If "%%~aG" GEq "-" (
Echo Error! File arg.
GoTo EndIt) Else (Echo Error! Invalid directory arg.
GoTo EndIt)) Else If "%%~dG" == "" (
Echo Error! Full directory path required.
GoTo EndIt)
If Not Exist "%MIExe%" (Echo Error! MediaInfo not found.
GoTo EndIt)
PushD "%~1"
Set "ExtLst="
For %%G In (aac ac3 aifc aiff ape asf au avi avr dat dts flac iff ifo irca m1v
m2v mac mat mka mks mkv mov mp2 mp3 mp4 mpeg mpg mpgv mpv ogg ogm paf pvf qt
ra rm rmvb sd2 sds vob w64 wav wma wmv xi) Do If Not Defined ExtLst (
Set "ExtLst=".":"*.%%G"") Else Call Set "ExtLst=%%ExtLst%% ".":"*.%%G""
Set "}=%PATHEXT%" && Set "PATHEXT="
%SystemRoot%\System32\where.exe /Q %ExtLst%
If ErrorLevel 1 (Echo Error! Directory has no supported files.
GoTo EndIt)
Set "i="
(For /F "Delims=" %%G In ('%SystemRoot%\System32\where.exe %ExtLst% 2^> NUL'
) Do (If Defined i Echo %HR%
"%MIExe%" "%%~nxG"
Set "i=T")) 1> "%~nx1.%OutExt%"
:EndIt
%SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1> NUL
GoTo :EOF
i want to add this part with a if it's a file not folder :
:SingleFile
"%MIExe%" "%~1" > "%~1.%OutExt%"
This work but produce a full path with name at the "Complete name" line..
And i also like to know if the "is a file check" can be use with this part (at the start of the batch) :
...
If "%%~aG" GEq "-" (
Echo Single file.
GoTo SingleFile
...
Thanks in advance for your help !
I need to batch convert all mkv files in a folder recursively to mp4.
If a filename exists and matches both extensions, ignore both files and process only filenames that contain mkv, without matching mp4.
Example: cat.mkv exists in folder with cat.mp4 = ignore both files
Example: cat.mkv exists in folder and cat.mp4 does not = process cat.mkv to cat.mp4
I have included a script that doesn't work well. It processes all mkv files and mp4 files. The mp4 files throw an error as FFmpeg will not encode the same format in this manner over itself.
As always thank you to anyone who might have a few ideas.
UPDATE: I may have gotten it to work. I changed a few things from the original. If anyone has success or an idea to improve I'm all ears. Thanks.
VERSION 2
#ECHO ON
SETLOCAL
PROMPT $G
COLOR 0A
REM Set FFmpeg.exe location if not in system PATH already
SET FF=C:\MAB\local64\bin-video\ffmpeg.exe
REM Set MKV files root folder to recursively search
SET "mkvPATH=C:\Encoding\1_Original\Test\"
REM Change into mkvPATH DIR
CD "C:\Encoding\1_Original\Test"
REM Set temp file name
SET TEMPFILE=convert_mkv.bat
REM Create empty convert file
COPY NUL "%TEMPFILE%" >NUL 2>&1
REM ADD #ECHO OFF to top of blank convert_mkv.bat script
ECHO #ECHO OFF >>"%TEMPFILE%"
REM Recursively search MKV root folder
FOR /R "%mkvPATH%" %%G IN (*.mkv *.mp4) DO (
SET "GPATH=%%~fG"
SET "GNAME=%%~nG"
SETLOCAL ENABLEDELAYEDEXPANSION
REM Ignore all files that have both
REM extensions ".mkv" and ".mp4" in the file name
IF "%%~nG.mkv"=="%%~nG.mkv" (
IF NOT EXIST "%%~nG.mp4" (
CALL :DO_FFmpeg "!GPATH!"
IF "%%~nG.mkv"=="%%~nG.mkv" (
IF EXIST "%%~nG.mp4" (
ECHO(>>"%TEMPFILE%"
) ELSE ENDLOCAL
)
)
)
)
GOTO END
REM CALL variables for use in FFmpeg's command line
:DO_FFmpeg
IF "%~1"=="" GOTO :END
FOR %%I IN ("%~1") DO (
SET "FOLDER=%%~dpI"
SET "NAME=%%~nxI"
)
REM Export info to "%TEMPFILE% and RUN ffmpeg.exe's command line in the cmd.exe window
ECHO %FF% -y -i "%~1" -ss 0 -t 300 -codec copy "%FOLDER%%~n1.mp4">>"%TEMPFILE%" && %FF% | %FF% -y -i "%~1" -ss 600 -t 30 -codec copy "%FOLDER%%~n1.mp4"
:END
PAUSE
EXIT /B
i would like to see if its possible to echo to an image like you can echo to a file:
echo Hello World! >>"%cd%/test.txt
Like this:
echo (base64 code) >>"%cd%/image.jpg"
what is even wrong with this?
it creates a jpeg file but it gives me the error that it can't be opened.
(probably of its code structure)
I checked it with the base64 to image converter and there is nothing wrong.
Why doesn't it create an image?
This batch file Certutil_B64_Encoding_Files.bat can let you to drag and drop any file like a jpg or png or any file else and generate another batch file with the encoded file inside, So, when you execute it, the file will be decoded and generated to the original.
Just save this code on your notepad or on notepad++ or on any text editor as :
Certutil_B64_Encoding_Files.bat and drag and drop any file over it to be encoded
#echo off
Title Encoding files with CERTUTIL utility by Hackoo 2018
color 0A & Mode 83,3
If "%~1"=="" (
color 0C & Mode 80,3
echo(
echo You must drag and drop a file over this batch script to be encoded !
Timeout /T 5 /nobreak>nul & exit /b
)
#for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
set "TempFile=%Temp%\Temp_b64
set "OutputFile=%~nx1_encoded%~x0"
If exist "%OutputFile%" Del "%OutputFile%" >nul 2>&1
echo(
echo Please wait a while ... Encoding "%~nx1" is in progress ...
certutil.exe -f -encode "%~1" "%TempFile%" >nul 2>&1
(
echo #echo off
echo Title My head kinda look like this
echo echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo echo and my head kinda look like this:
echo CERTUTIL -f -decode "%%~f0" "%%Temp%%\%~nx1" ^>nul 2^>^&1
echo Timeout /T 5 /nobreak^>nul
echo Start "%~n1" "%%Temp%%\%~nx1"
echo Exit
)>> "%OutputFile%"
copy "%OutputFile%" /b + "%TempFile%" /b >nul 2>&1
If exist "%TempFile%" Del "%TempFile%" >nul 2>&1
Timeout /T 2 /NoBreak>nul & exit
And here is an example that i tested with my avatar Hackoo.png
Hackoo.png_encoded.bat
#echo off
Title My head kinda look like this
echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo and my head kinda look like this:
CERTUTIL -f -decode "%~f0" "%Temp%\Hackoo.png" >nul 2>&1
Timeout /T 5 /nobreak>nul
Start "Hackoo" "%Temp%\Hackoo.png"
Exit
-----BEGIN CERTIFICATE-----
/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1
c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMD
BAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgW
FBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAQABAAwEiAAIRAQMRAf/E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQE
AAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBka
JSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SF
hoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY
2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgME
BQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKB
CBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNU
VVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip
qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/a
AAwDAQACEQMRAD8A/UA8HFGOM5oJzk+1AbOR2oIOV+Kfjq3+GPw68ReLbuFri20a
xmvXhUhTJsUkKCemSAM+9fmxrv8AwVG+I+s3cjaNpnh/R7TP7tfKe5fHuxcDP4D6
V9a/8FDfHdj4d/Zd8Y2K6hbrqGoLBZpaiZfNZXnQOQucnC5PSvxct7UBtyd88DtS
saRsfdWm/wDBSv4rWMiyXg8P30WcsktmY8j6q4r7w/ZV+P4/aO+GX/CTNYRabdwX
kljcwQSmSPzEVGypIBwQ44P5mvwvkARDn71fpn/wSJ8RfaPAXj7RS3/HtqUF2q5/
56RFT/6Ko1Tu2KR+gVGaQc0p4NMgw/HfjDT/AAB4P1nxHqrmPTtKtZLudkGW2opJ
AHcnGB7kV+Snxr/bh+Ivxe1G6itNVuPC/hwsyw6XpshjYp2MsowzNjqMhfav1t8a
eE9O8d+FtV8P6tD9o03U7aS0uI+hKOpU4PY4PBr8uvi//wAE5fiX4LvLmXwjHF4w
0RSTF5LrFeKmeA8bkBiB3QnPoOlRI0jY+NfGV5K/lM5aWaWUF5ZDuJ9ck1HZaWJo
Q3mZ/Wt/xNoGqeGtautE1zTZLDV7UhZ7C7UJLGSMjKHkZBB/GqdjbGNSgtmQg/dw
aV7I0sVG0dWXIkOe9a3w3+IHiX4d6zdzeF9c1HQ7ghQ81jcNEXwTw204PU9aY6dQ
YJPcKpq54e8M3uvava6To9lJPqd7KsUFqmPNlc9AF6kmkvMLH1D8Lv8Ago/8VPB1
zbxeI5LTxlpikB1u4lhuQuedssYHP+8pr9MPg38WNH+Nfw+0vxZoYmSyvVIMVwMS
RSKSro2OOGBGR161+cvwd/4Jr/EDxZd29z40nh8H6TlWlh3LPeSL6KqnapPqx4/u
mv0o+Gnw60T4U+DdM8MeH7Y2ul2EeyNWO53JOS7t3ZiSSfWrM5JHT1yHxY+Iln8K
vh/rfii+ikng023M3kxfekPZR9T37DJr5/8A2xf28dH/AGY5rfQ9M0xfEni6eLzm
tGn8uG0Q/daUgEkk9FGDjnIyM/mx8dv+CjHxd+OOg3mg3VzY6B4euSFuLTRYGjaZ
Qc7XlZmYg45AIB7ih6hGN2eH+PvGmo/EX4g6p4r1mUzanqd695M/bcWOAPQDGB7A
V9ZaR8SvD154BhN9b2cQurSOWC7uIgwYY+ZVO3HmAgqUJz0xmviuBftXzZ+VFz7Y
5r1f9nL4v2nhDVG0TXpE/sS4Z3imnOUglI/ix/AxC59CM+tc8o6Hb0sfYVz4x8JW
FrdabpUWk3eqfaPLMMMKieAL95nBXMajruOM5GOTXyp8NPiHaad+1JpPi+ZwljFr
kd00gGP3QkGSPbANbfxh/aEgufhbpOkaTNHL4k1O0Laxd26hfKBLDZlQBvK4zjoM
j6eGWEn2Wyiu4mw6KoqacLasWysf0k6ffW+pWcdzZzR3NtKoaOaFwyOOxBHBFWTk
Gvwm/Z+/bt+KXwGvre2tNYfxD4YjO0aFqrtJCiE5xE2d0Z64wcc8g1+qv7L/AO2l
4M/aYsmtrLfofieCPzLjRbxgz7R1eJxgOufoR3ArrRxOPKfil4s8U6h431a/8R6/
qEmp6rqM7TXFxOfmkc8Z/wAAOABgVwF9O00p2AKBwPVf8K3b/TxZ26HeXkBBd2Pf
oMDsMVz9s3nk8cE96k6FpqT6aWWO4hY9VyOe3f8AnTDaqAcKARyMCtO10/eQyqM9
DVyTTxFC52YIU81ViucyUswsKEDHrQl0VtmtQp3Mcs2eK3be1BijXAPGOlVbqzEU
hOwc9aklSZWs4WVwCCMeleh/DDx3q/wu8aaP4r0Cf7PqmmziaM87Txgqw7qykqR6
E157DqAs5VDruQnGe4rorF4riISRNuU1orGT11P/2Q==
-----END CERTIFICATE-----
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
certutil - Dump and display certification authority (CA) configuration information, configure Certificate Services, back up and restore CA components, verify certificates, key pairs or certificate chains.
You can use the command HEX2PNG.EXE to reconstruct a text file to an image.
Example :
smiley.txt
--------------#####--------------
-----------###.....###-----------
---------##...........##---------
-------##...............##-------
------#...................#------
-----#.....................#-----
----#...####........#####...#----
----#..####c#......####cc#..#----
---#..#####cc#....#####ccc#..#---
---#..#####cc#....#####ccc#..#---
--#...####ccc#....####cccc#...#--
--#..#cccccccc#..#ccccccccc#..#--
--#..#cccccccc#..#ccccccccc#..#--
-#...#cccccccc#..#ccccccccc#...#-
-#...##########..###########...#-
-#.............................#-
-#.............................#-
-#.............................#-
--#..#######################..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
---#..#aaaaaaaaaaaaaaaaaaa#..#---
---#..#aaaaaaaaaaa;;;;aaaa#..#---
----#..#aaaaaaaaa;;;;;;aa#..#----
----#...#aaaaaaa;;;;;;;;#...#----
-----#...##aaaa;;;;;;;##...#-----
------#....###;;;;;###....#------
-------##.....#####.....##-------
---------##...........##---------
-----------###.....###-----------
--------------#####--------------
To build the image you have to replace each kind of char with an hexa color and then run hex2png.exe against the smileuout.txt :
In this case
The char [c] with white [FFFFFFFF]
The char [a] with maroon [103E66FF]
The char [.] with yellow [00EAFFFF]
The char [-] with transparent (black + transparent value to 00) [00000000]
The char [#] with black (non transparent) [000000FF]
The char [;] with red [0000FFFF]
This bat will do that :
#echo off
set $fichier=smiley.txt
set $taille=33;31
set $TotPix=1023
set $Fsortie=smiley.png
:::Crátion de la première ligne de sortie.txt (width_pixel;Height_pixel;Name_of_file.PNG;Total_number_of_pixel)
echo %$taille%;%$Fsortie%;%$TotPix%>SmileyOut.txt
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type %$fichier%') do (echo %%a
set $ligne=%%a
set $ligne=!$ligne:c=FFFFFFFF !
set $ligne=!$ligne:a=103E66FF !
set $ligne=!$ligne:.=00EAFFFF !
set $ligne=!$ligne:-=00000000 !
set $ligne=!$ligne:#=000000FF !
set $ligne=!$ligne:;=0000FFFF !
set /a $c+=1
for %%b in (!$ligne!) do (echo %%b>>SmileyOut.txt))
endlocal
hex2pngV1.3.exe smileyout.txt
del smileyout2>nul
start smiley.png
The output will be this nice smiley :
The structure of the file smiley.txt is very important !
This vars must be setted correctly or the image will be corrupted :
$fichier=smiley.txt
$taille=33;31 => width;height of the output file each char is one pixel
$TotPix=1023 => The total of pixel (width * height)
$Fsortie=smiley.png => the name of the output PNG
The command PNG2HEX will do exactly the contrary an generate a txt file from an image !
I searched a file in command prompt using
dir /s *584.pdf
The file was found and the result is as follows
Volume in drive Z is New Volume
Volume Serial Number is E49F-4208
Directory of Z:\OHE_Design\DFCC\EMP-4 OHE\Submissions\References\Received\CTP-1 & 2\05-Bridge Mast files\CTP 1 & 2 DETAILS\OHE approval letters\L-NKC-SLT-PMC-1612-48
12/14/2016 05:11 PM 8,180,090 2-MB-13-011-OHE_Rev.0 584.pdf
1 File(s) 8,180,090 bytes
Total Files Listed:
1 File(s) 8,180,090 bytes
0 Dir(s) 47,574,523,904 bytes free
Now, i want to open the file that i searched for, is there any command to do that? How shall i proceed?
for /r "Z:\OHE_Design" %%a in ("*584.pdf") do (
start "" "%%~fa"
)
Try this.
I tried with some code and it seemed to work for me luckily.
#echo off
set /p search="Enter the file : "
cd "C:\users\suneel\desktop\Potato 23"
dir /s /b /a-d "*%search%*.pdf">"test.txt"
if '%ERRORLEVEL%'=='0' GOTO OPEN
if '%ERRORLEVEL%'=='1' echo Please search manually or Confirm with Authorities
:CONT
del "test.txt"
PAUSE
EXIT
:OPEN
set /p extract=<"test.txt"
start "" "%extract%"
echo FILE FOUND
echo Please wait while the file opens.
GOTO CONT
I need to download 300 images from site.com/folder/ using the following format: 1.png, 2.png ... 300.png
Is there a way to do this inside a batch file or using the command prompt?
Wth curl like this:
curl -o "#1.png" http://example.com/folder/[1-300].png
Here is an example to download some batch codes from a file that can be created by this script if not exist, and of course you can add or modify what you want of urls in this file !
You can add your urls in the text file named Urls.txt
Firstly, the script check for the text file named Urls.txt if exist in same location where this batch is executed and read from it the urls line by line to download them !
So, if you want to change those urls to yours, just change it from the text file Urls.txt not from the batch, i mean you can create a text file and name it to Urls.txt and put what you want as urls on this file line by line of course and let the script do its job
#echo off
Mode 110,3 & color 0A
Title Download file from web using powershell and batch by Hackoo 2017
Set "List_Urls_File=Urls.txt"
If not exist "%List_Urls_File%" Call :Create_Urls_File
Setlocal enabledelayedexpansion
#For /f "delims=" %%a in ('Type "%List_Urls_File%"') do (
Set "URL=%%a"
Rem we set the Filename from the variable !url!
#for %%# in (!url!) do ( set "File=%%~xn#" )
Rem Check if the file name contains a dot "."
Rem If not we increment the counter +1 for file to be download
ECHO !File! | FIND /I ".">Nul 2>&1
If "!errorlevel!" NEQ "0" (
Set /a Count+=1
cls & echo(
echo Downloading file "File-!Count!.bat" from URL : "!URL!"
Call :BalloonTip 'information' 10 '"Downloading File-!Count!.bat"' "'Please wait... Downloading File-!Count!.bat....'" 'info' 4
Call :Download "%%a" "File-!Count!.bat"
) else (
cls & echo(
echo Downloading file "!File!" from URL : "!URL!"
Call :BalloonTip 'information' 10 '"Downloading !File!"' "'Please wait... Downloading !File!....'" 'info' 4
Call :Download "%%a" "!File!"
)
)
Explorer "%~dp0" & exit
::*********************************************************************************
:Download <url> <File>
Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
exit /b
::*********************************************************************************
:Create_Urls_File
(
echo https://pastebin.com/raw/XvyhRzT6
echo https://pastebin.com/raw/QqnZ0MjQ
echo https://pastebin.com/raw/tHsKw15V
echo https://pastebin.com/raw/VCnTbLB6
echo https://pastebin.com/raw/3zUTrWUz
echo https://pastebin.com/raw/31auQeFz
echo https://pastebin.com/raw/xF0uXThH
echo https://pastebin.com/raw/uzsGQD1h
echo https://pastebin.com/raw/3TmVYiZJ
echo https://pastebin.com/raw/Ntc8SZLU
echo https://pastebin.com/raw/jnpRBhwn
echo https://www.virustotal.com/static/bin/vtuploader2.2.exe
echo http://devbuilds.kaspersky-labs.com/devbuilds/KVRT/latest/full/KVRT.exe
)>"%List_Urls_File%"
exit /b
::*********************************************************************************
:BalloonTip $notifyicon $time $title $text $icon $Timeout
PowerShell ^
[reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
[reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
$notify = new-object system.windows.forms.notifyicon; ^
$notify.icon = [System.Drawing.SystemIcons]::%1; ^
$notify.visible = $true; ^
$notify.showballoontip(%2,%3,%4,%5); ^
Start-Sleep -s %6; ^
$notify.Dispose()
%End PowerShell%
exit /B
::*************************************************************************
Numbered-Files Downloader 1.0
Here is a complete batch script that is doing exactly what you asked for. You don't need to download any executable files, this is 100% batch script and it should works on any (recent) Windows installation.
All you need to do is to edit the _URL variable (Line 11) and replace "example.com/folder..." with the actual URL of the files you want to download. After that, you can run the script and get your files.
Note that in your URL, this string: _NUMBERS_ is a keyword-filter that will be replaced by the incremented numbers in the final download function.
All your downloaded files will be saved in the directory where this script is located. You can choose an other directory by uncommenting the _SAVE_PATH variable (Line 15).
Finally the following variables can be changed to configure the series of numbers:
_START : The file numbers starts with this value.
_STEP : Step between each files.
_END : The file numbers ends with this value.
Leading Zeros
Currently, the counter doesn't support leading zeros.
EX. From Picture_001.jpg to Picture_999.jpg
But otherwise it should work fine for something like this:
EX. From Picture_1.jpg to Picture_999.jpg
I will try to find some time to add this option, it shouldn't be too difficult.
Feel free to modify & enhance this script if you need!
Numbered-DL.cmd
#echo off
setlocal EnableDelayedExpansion
rem STACKOVERFLOW - QUESTION FROM:
rem https://stackoverflow.com/questions/45796990/batch-download-images-from-url-with-for
:VARIABLES
rem WHERE YOU WANT TO SAVE FILES
rem "%~dp0" is a variable for the same folder as this script, so files should be saved in the same folder.
rem If you want to save the downloaded files somewhere else, uncomment the next line and edit the path.
SET "_SAVE_DIR=%~dp0"
rem SET _SAVE_PATH=C:\Folder\
rem DOWNLOAD THIS FILE URL
rem
rem "_NUMBERS_" WILL BE REPLACED BY THE COUNTER
rem CURRENLY IT DOESN'T SUPPORT CHOOSING A NUMBERS OF ZEROS FOR THE COUNTER EX: 001,002,003...
rem BUT IT SHOULDN'T BE TOO HARD TO IMPLEMENT, MAYBE ILL ADD THIS IN THE FUTURE.
rem
rem SET _FILE_URL=https://example.com/folder/_NUMBERS_.png
SET "_FILE_URL=https://cweb.canon.jp/eos/lineup/r5/image/downloads/sample0_NUMBERS_.jpg"
rem FOR THIS EXAMPLE THE SCRIPT WILL DOWNLOAD FILES FROM "sample01.jpg" TO "sample05.jpg"
SET _START=1
SET _STEP=1
SET _END=5
:CMD_PARAMS
IF NOT [%1]==[] SET "_FILE_URL=%1"
IF NOT [%2]==[] SET "_SAVE_DIR=%2"
:PATH_FIX
rem REMOVE THE LAST CHAR IF IT IS "\"
IF [%_SAVE_DIR:~-1%] == [\] SET "_SAVE_DIR=%_SAVE_DIR:~0,-1%"
:DETAILS_DISPLAY
ECHO.
ECHO SCRIPT: Numbered-Files Downloader 1.0
ECHO AUTHOR: Frank Einstein
ECHO.
ECHO.
ECHO INPUTS
ECHO _URL: %_FILE_URL%
ECHO _SAVE_DIR: %_SAVE_DIR%
ECHO.
ECHO _START: %_START%
ECHO _STEP= %_STEP%
ECHO _END= %_END%
ECHO.
ECHO.
CALL :DOWNLOAD_LOOP
ECHO.
ECHO EXECUTION COMPLETED
ECHO.
PAUSE
EXIT /B
:DOWNLOAD_LOOP
SET FINAL_URL=%_FILE_URL%
FOR /L %%G IN (%_START%,%_STEP%,%_END%) DO (
rem REPLACE URL'S KEYWORD WITH NUMBERS
SET NUM=%%G
SET FINAL_URL=%FINAL_URL:_NUMBERS_=!NUM!%
rem CUMSTOM BATCH FUNCTION FOR DOWNLOADING FILES
rem
rem SYNTAX:
rem echo CALL :DOWNLOAD !FINAL_URL!
CALL :DOWNLOAD !FINAL_URL! !_SAVE_DIR!
)
Goto :EOF
rem PAUSE
rem EXIT /B
rem FUNCTIONS
:DOWNLOAD
setlocal
SET "DL_FILE_URL=%1"
SET "DL_SAVE_DIR=%2"
rem EXTRACT THE FILENAME FROM URL (NEED TO FIX THIS PART?)
FOR %%F IN ("%DL_FILE_URL%") DO SET DL_FILE_NAME=%%~nxF
IF "%DL_SAVE_DIR:~-1%" == "\" SET "DL_SAVE_DIR=%DL_SAVE_DIR:~0,-1%"
IF NOT [%2]==[] SET "DL_SAVE_FILE=%DL_SAVE_DIR%\%DL_FILE_NAME%"
IF [%2]==[] SET "DL_SAVE_FILE=%~dp0%DL_FILE_NAME%"
rem :BITSADMIN
ECHO.
ECHO DOWNLOADING: "%DL_FILE_URL%"
ECHO SAVING TO: "%DL_SAVE_FILE%"
ECHO.
bitsadmin /transfer mydownloadjob /download /priority foreground "%DL_FILE_URL%" "%DL_SAVE_FILE%"
rem BITSADMIN DOWNLOAD EXAMPLE
rem bitsadmin /transfer mydownloadjob /download /priority foreground http://example.com/filename.zip C:\Users\username\Downloads\filename.zip
endlocal
GOTO :EOF
try with winhttpjs.bat:
set "baseLink=http://example.org/folder/"
for /l %%a in (1;1;300) do (
winhttpjs.bat "%baseLink%%%a.png" -saveto %%a.png
)