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
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1mUzanqd695M/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 !
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 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 -----------------------------------------------------------------
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
)
I have sql files in a folder structure like the following :
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer1\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer2\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer3\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer4\test.sql
........
I want to make a script which reads the path (C:\Users\Peter\Desktop\SQL_FILES),
the name of the file(test.sql) and a text
and then concatenate the text in the end of each test.sql file.
Could you help me please ?
Thanks in advance
:: Hide Command and Set Scope
#echo off
setlocal EnableExtensions
mode 140,50
set /p AbsolutePath="Enter the path of root folder :"
echo.
set /p FileName="Enter the filename with it's extension (ie. test.sql):"
echo.
echo Enter your inserts
echo Press Enter twice when finished
echo (text may not contain ^<, ^>, ^|, ^&, or un-closed quotes)
ver > NUL
set new_line=""
:still_typing
set /p new_line=">"
if errorlevel 1 echo. >> temp.txt & set /p new_line=">"
if errorlevel 1 echo Sending message. . . & goto done_typing
echo %new_line% >> temp.txt
goto still_typing
:done_typing
echo done
:End
endlocal
pause >nul
=====================================
For example :
The file test.sql for example contains initially :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
And after the execution of batch supposing I add an empty line and two inserts in the text :
INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (1,2,3);
INSERT INTO TEST(COL1,COL2,COL3) VALUES (2,3,4);
The Batch file below use a different method to do the same, but in a simpler way. This code may be modified in any point you wish; for example, if you want not that the filename must include a wild-card.
#echo off
setlocal
set /p "AbsolutePath=Enter the path of root folder: "
echo/
set /p "FileName=Enter the filename with a wild-card (ie. test*.sql): "
echo/
echo Enter your inserts
echo Press Ctrl-Z and Enter when finished
copy CON temp.txt > NUL
echo/
echo Typing done
echo/
for /R "%AbsolutePath%" %%a in (%FileName%) do type temp.txt >> "%%a"
Hello guys as you read in topic how can i make a selected file to copy to another location.
Im using my own Lithuanian language in this, if some one find it hard to understand tell me ill translate it. Right now it only creates new file when i start " name.bat test.txt" its not full code since there is lots of copy paste of same thing any ideas since im realy bad at .bat files.
And i need to use command "FOR"
:DEKUPAZAS
echo Pasirinkote Dekupazo kursus
echo Bendrine informacija apie si bureli
echo.
type dekupazas.txt
echo.
set U=dekupazas.txt
echo Ar norite:
echo 1) Irasyti sia informacija i naujai sukurta faila?
echo 2) Grizti kitu bureliu pasirinkimu?
echo 3) Grizti prie srities pasirinkimo?
choice /C 123 /N /M "Iveskite savo pasirinkima(1,2 arba 3): "
if errorlevel 255 goto KLAIDA
if errorlevel 3 goto SRITIS
if errorlevel 2 goto KT
if errorlevel 1 goto IRASYMAS
goto PRADZIA
:IRASYMAS
echo Pasirinkote irasyti sia informacija i jusu sukurto pavadinimo faila
echo Failas bus perkeltas i aplanka Pasirinkimas
if exist Pasirinkimas rd /S /Q Pasirinkimas
md Pasirinkimas
for %%U in (U) do dir %%U >>%1
move %1 Pasirinkimas >nul
goto PAB
The FOR /F statement reads each line of the file then does a directory listing of it captured to the first parameter to the .bat script.
I also took the liberty of creating a variable for the new directory name so that it does not need to be hardcoded so many times. "Hardcode" is two, four-letter words.
echo Pasirinkote irasyti sia informacija i jusu sukurto pavadinimo faila
echo Failas bus perkeltas i aplanka Pasirinkimas
SET NEW_DIR=Pasirinkimas
if exist "%NEW_DIR%" (RMDIR /S /Q "%NEW_DIR%")
MKDIR "%NEW_DIR%"
for /F %%a in (%U%) DO (DIR "%%~a" >>"%~1")
move "%~1" "%NEW_DIR%" >nul
goto PAB