I have 2 txt files, first file is "recipes.txt", second is "sites.txt" where is website links,
i'm making txt files in a bulk with the names from file "recipes.txt", from second txt file "sites.txt" i want to take rows in a loop and input them into txt file which gonna be created from recipes.txt.
Here i have batch script, which creates files with specific name from "recipes.txt", but its appending only last row of the file "sites.txt".
What shoudl i change to amke it work properly?
#echo off
setlocal enableDelayedExpansion
for /f %%g in (recipes.txt) do (
for /f %%i in (site.txt) do (
(
echo SET !REPLAYSPEED MEDIUM
echo URL GOTO=%%i
)
)>C:\Users\Viktor\Desktop\Sites\Scripts\%%g".iim"
)
pause >nul
just extend your block for redirection to include the for itself:
for /f %%g in (recipes.txt) do (
(
for /f %%i in (site.txt) do (
echo SET !REPLAYSPEED MEDIUM
echo URL GOTO=%%i
)
)>C:\Users\Viktor\Desktop\Sites\Scripts\%%g".iim"
)
pause >nul
Your version overwrites your file with every iteration of %%i
Related
I don't have much experience with batch scripting but this seems like a suitable task for it:
I have a very large directory with recordings of a specific extension, say '.wav'. In the same folder, I'm supposed to have, for each of these recordings, an xml file, named the exact same as the recording filename, except with the extension .xml instead of .wav.
Now, I notice that the '.xml' files total count is slightly less then the '.wav' total; i.e some of the xml files are missing.
How can I extract a list of all recordings with missing xml files?
#echo off
for %%F in (*.wav) do if not exist "%%~dpnF.xml" echo %%F
You don't really need a batch file. You could enter the following directly on the command line:
for %F in (*.wav) do #if not exist "%~dpnF.xml" echo %F
Actually, you don't need the ~dp modifiers as I have written the code. But if you include path information like in (somepath\*.wav), then they become important.
This a little approch can did the trick
You should just change Set folder=c:\temp to your folder that contains your files :
#echo off
set folder=c:\temp
set ext1=wav
set ext2=xml
Set Log=c:\MissingFiles.txt
set /a count=0
cd /d "%folder%"
setlocal enabledelayedexpansion
(
for %%a in (*.%ext1%) do (
for %%b in (*.%ext2%) do (
If /I not "%%~na"=="%%~nb" ( SET /A COUNT+=1 && echo "%%~dpnxb" )
)
)
echo.
ECHO The total number of missing files is !COUNT!
Endlocal
) > %Log%
Start "" %Log%
I have a batch file, which I will post below, I am trying to have it copy the first line in a file and then stores it in a variable.
#echo off
setlocal enabledelayedexpansion
set SEPARATOR=/
set filecontent=
for /f "delims=" %%a in ("MavenInstructions.txt") do (
set currentline=%%a
set filecontent=!filecontent!%SEPARATOR%!currentline!
)
echo The file contents are: %filecontent%
echo %filecontent%
pause
The first line of the MavenInstructions.txt is TEST LINE but what I get when I run my batch file is:
The file contents are: /MavenInstructions.txt
/MavenInstructions.txt
Press any key to continue . . .
for /f "usebackqdelims=" %%a in ("MavenInstructions.txt") do (
usebackq is required if the filename is "quoted".
btw - set filecontent=!filecontent!%SEPARATOR%%%a
would suffice.
I have a line in a text file that I'm trying to modify using a batch file. The line in this case is the lastexportdate=2014-01-01. I'm trying to get the batch file to modify this from
lastexportdate=2014-01-01
to
lastexportdate= Current timestamp.
Is this possible to have this equal the timestamp of my computer? Not certain how to go about tackling this, so if anyone could help that would be awesome. I'm using Windows 7.
File contents below:
root.footer=</CREDITEXPORT>
root.header=<CREDITEXPORT>
emailaddronsuccess=test#test.com
emailaddronerror=test#test.com
rerunexportdate=2014-09-06
errorfilelocation=C:\\
lastexportdate=2014-01-01
xmloutputlocation=C:\\
#echo off
setlocal
rem getting current time stamp
set "beginJS=mshta "javascript:var t=new Date();var dd=t.getDate();var mm=t.getMonth()+1;var yyyy=t.getFullYear();if(dd^<10) dd='0'+dd;if(mm^<10) mm='0'+mm;close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write("
set "endJS=));""
:: FOR /F does not need pipe
for /f %%N in (
'%beginJS% yyyy+'-'+mm+'-'+dd %endJS%'
) do set cds=%%N
echo cds=%cds%
rem processing the file
rem set the location of the file
set "content_file=c:\some.file"
break>temp.file
for /f "usebackq tokens=1* delims==" %%a in ("%content_file%") do (
if "%%a" NEQ "lastexportdate" echo %%a=%%b>>temp.file
if "%%a" EQU "lastexportdate" echo %%a=%cds%>>temp.file
)
Not tested.Just change the location of the content_file and check if the created temp.file is ok.
To replace the file add move temp.file "%content_file%" at the end.
I'm using this script to combine multiple csv files all with the same header and all in the same directory. It works well, but it writes the file path to the last line in MASTER.csv, which is an issue when I go to process the data. I'd like to append this batch file so that it no longer outputs the file path, otherwise how would I delete the last line in the MASTER.csv
#echo off
setlocal EnableDelayedExpansion
set first=1
set fileName="MASTER.csv"
>%fileName% (
for %%F in (*.csv) do (
if not "%%F"==%fileName% (
if defined first (
type "%%F"
set "first="
) else more +1 "%%F"
)
)
)
Example of the last three lines of MASTER.csv:
2014/05/31,23:58:00, 22.0C, 22.33C, 16.17,OK,OK,OK,OK,OK,OK,OK,OK,OK,Off
2014/05/31,23:59:00, 21.9C, 22.39C, 16.11,OK,OK,OK,OK,OK,OK,OK,OK,OK,Off
C:\Users\ME\Desktop\program\data\enviro\MASTER.csv
file.bat | find /v "C:\Users\ME\Desktop\program\data\enviro\MASTER.csv" > MASTER.csv
What I want to accomplish is to rename all the .exe that I have in a folder.
Sample of random name should be "589uday5xpsa9iz.exe"
I would appreciate any help I can get on this, I have been trying to figure it out for a couple of days now.
Try this :
#echo off
setlocal enabledelayedexpansion
:://The string length of the output
set $Lcode=16
set $#=#
:://The char Map
set $l="#0=0" "#1=a" "#2=B" "#3=c" "#4=d" "#5=E" "#6=f" "#7=g" "#8=H" "#9=I" "#10=j" "#11=K" "#11=1" "#13=2" "#14=3" "#15=4" "#16=5"
:://Evaluating the char MAP
for %%a in (%$l%) do set %%~a
:://Looping in the directory for .exe files
for /f "delims=" %%x in ('dir /b/a-d "*.exe"') do (
for /l %%a in (0,1,%$Lcode%) do (
call:rand
)
ECHO ren "%%x" !$Fstring!.exe
set $Fstring=
)
pause
exit/b
:://Getting the random Char
:rand
set /a $n=!random!%%17
set $Fstring=!$Fstring!!#%$n%!
I made a char MAP of just 15 char but you can increase it with all the char (up and downcase + number). If you do it. You have to increase the value in !random!%%17
with the value of the total CHAR map(+1).
You can increase the length of the random string by changing the value in the variable : $Lcode (16) in this example.
The output :
ren CnpjSdee.exe 2aHg5I22EBBE2ff5.exe
ren DbatchCnpj.exe EIIg2E54aHHIEgfHE.exe
ren NTStreamColor.exe jg03f3dIfBfIfHj2.exe
ren savedialog.exe EgfdajIcdc2cf03E.exe
Press any key to continue. . .
If it's OK Remove the ECHO to realy rename the files.
this is a simple batch that will work from within the folder that contains the files to be renamed you could make a shortcut to use it from the desk top. use copy and paste for long names. C:\Documents and Settings\Owner\Desktop\New Folder\Rename.bat (file = Rename.bat) don't use the whole path.
#echo off
title Rename Bat
echo This bat must be in the folder that
echo contains the files to be renamed.
:begin
echo Enter File Name
set /p old=
echo Enter New Name
set /p new=
ren "%old%" "%new%"
echo File Renamed
ping -n 3 127.0.0.1 >NUL
goto begin
hope this works for you.
a much simpler approach ... try a for loop that cycles through all files in that folder and renames them one at a time giving each a unique number ...
#echo off
for /L %%n in (1 1 %random%) do (
for %%a in (*.exe) do (
rename "%%a" "%%a_%%n.exe"
)
)
so %%a represents all the files in that folder and %%n represents the unique number that is going to be assigned to each file in the for body separated with _ symbol
to use this batch file you have to place it in the folder containing your .exe files
this would rename files to original name_1 then original name _2 and so on if you want it to be completely random use only %random% in bracket of the first for loop and do away with the iteration "1" (see below) also at the renaming part do away with %%a to omit the original name of file so that you remain with only random numbers also see below e.g
#echo off
for /L %%n in (%random%) do (
for %%a in (*.exe) do (
rename "%%a" "%%n.exe"
)
)
hope this helps .....