Batch that creates and adds text to a Kodi .disc file
A .disc file is a .txt file used by the KODI program.
I have a list in .txt with the following information:
File Name 01 Texto AA Texto AB Texto AC Texto AD
File Name 02 Texto BA Texto BB Texto BC Texto BD
File Name 03 Texto CA Texto CB Texto CC Texto CD
File Name 04 Texto DA Texto DB Texto DC Texto DD
I need to create files with the name and content of each line.
The result should look something like this:
<discstub>
<title>Texto AA</title>
<message>Texto AB
Obs: Texto AC
Coleção: Texto AD</message>
</discstub>
I can now generate the files with this bat
#echo off
CHCP 65001
PAUSE
setlocal
for /f "tokens=*" %%a in (02_FilmesSitio.txt) do (type nul>"%%a.disc")
PAUSE
But I don't know the commands or the best way to insert the text in the file when creating it.
EDIT
Searching here on Stack I found a comment by #squashman that is perhaps the most suitable course.
In this topic
Windows Batch to create .txt from a list
It is a fairly trivial single line of code if the data is formatted horizontally with a comma as the delimiter between the file name and file content. for /f "tokens=1* delims=," %F in (filenames.txt) do echo %G>"%F.txt" – Squashman Mar 26 at 1:10
Each line of my .txt file has the 5 necessary information.
On the line they are separated by TAB.
But they can be separated by a comma or semicolon, or some other character.
At the beginning the text for the file name.
Then, separated by TABs the texts for each line of the file.
So my question is: What should I modify and/or add to my current .bat file?
I believe it is resolved.
List_Movies.txt
Movie Title 1 (YEAR) complement;Text Message 01;Text Message 02;Text Message 03
Movie Title 2 (YEAR) complement;Text Message 01;Text Message 02;Text Message 03
Movie Title 3 (YEAR) complement;Text Message 01;Text Message 02;Text Message 03
CreateDISCfileWithText.bat
#echo off
CHCP 65001
PAUSE
setlocal
for /f "tokens=1,2,3,4 delims=;" %%F in (List_Movies.txt) do (type nul>"%%F.disc"
echo ^<discstub^>>>"%%F.disc"
echo ^<title^>%%F^<^/title^>>>"%%F.disc"
echo ^<message^>%%G>>"%%F.disc"
echo %%H>>"%%F.disc"
echo %%I^<^/message^>>>"%%F.disc"
echo ^<^/discstub^>>>"%%F.disc"
)
PAUSE
Result:
.disc file with text. Example:
File title: Movie Title 1 (YEAR) complement.disc
Content
<discstub>
<title>Movie Title 1 (YEAR) complement</title>
<message>Text Message 01
Text Message 02
Text Message 03</message>
</discstub>
KODI Feature
https://kodi.wiki/view/Media_stubs
I come to ask for help.
I have a document that it created automatically. This is the result of a SQL query.
an example of line with line feed. With word we see that
"2K45.10 NEW";"ARC CA 125 CONTROL";"4";"0";"8 640";
"2K45.23 NEW";"ARC CA 125 REAGENT 400 TESTS ";"4";"0";"103 777"
"2K45.28 NEW";"ARC CA 125 REAGENT 100 TEST ";"4";"0";"27 113"
"2K46.01";"ARC ANTI TG CALIBRATOR ";"4";"0";"11 626"
"2K46.10";"ARC ANTI TG CONTROL";"4";"0";"8 483"
"2K46.25";"ARC ANTI TG RGT 100 TEST ";"4";"0";"26 872"
If i open by Nopad++
"2K45.10 NEW";"ARC CA 125 CONTROL";"4";"0";"8 640";"BOITE";"";"TAXE 39% CD 38220000000"
"2K45.23 NEW";"ARC CA 125 REAGENT 400 TESTS
";"4";"0";"103 777"
"2K45.28 NEW";"ARC CA 125 REAGENT 100 TEST
";"4";"0";"27 113"
"2K46.01";"ARC ANTI TG CALIBRATOR
";"4";"0";"11 626"
"2K46.10";"ARC ANTI TG CONTROL";"4";"0";"8 483"
"2K46.25";"ARC ANTI TG RGT 100 TEST
";"4";"0";"26 872"
The problem is that in certain lines, there are Line feed and when I run my script, there or there of the line feed me here cut my line. Below is the script I use.
#echo off & cls
Set "$c=1"
setlocal enabledelayedexpansion
(for /f "delims=" %%a in (input.txt) do (
if !$c!==1 (
set $l=%%a
set /a $c+=1
) else (
echo !$l!%%a
set "$c=1"
)
))>sortie.txt
And the result is
"2K45.23 NEW";"ARC CA 125 REAGENT 400 TESTS ";"4";"0";"103 777"
"2K45.28 NEW";"ARC CA 125 REAGENT 100 TEST ";"4";"0";"30 652";
"2K46.01" ;"ARC ANTI TG CALIBRATOR ";"4";"0";"11 626"
"2K46.10" ;"ARC ANTI TG CONTROL";"4";"0";"8 483" "2K46.25";"ARC ANTI TG RGT 100 TEST
";"4";"0";"26 872";"2K47.01";"ARC ANTI TPO CALIBRATOR
I don't understand why, For lines without LF, there are more CRLF
Thank you for the help you bring me.
#ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
SET "filename1=%sourcedir%\q35165390.txt"
Set "$c=1"
for /f "usebackqdelims=" %%a in ("%filename1%") do (
if !$c!==1 (
set $l=%%a
set /a $c+=1
) else (
echo !$l!%%a
set "$c=1"
)
)
ECHO ==============
Set "$c="
for /f "usebackqdelims=" %%a in ("%filename1%") do (
IF DEFINED $c (ECHO !line!%%a&SET "$c="
) ELSE (
SET "line=%%a"
SET "line=!line:"=_#_!"
IF "!line:~-3!"=="_#_" (echo %%a) else (set "$c=1"&SET "line=%%a")
)
)
GOTO :eof
The first part of this batch is your code with a couple of small changes to read the data from a file named to suit my system.
Given the data you show as the notepad++ version, the result of running this code is:
"2K45.10 NEW";"ARC CA 125 CONTROL";"4";"0";"8 640";"BOITE";"";"TAXE 39% CD 38220000000""2K45.23 NEW";"ARC CA 125 REAGENT 400 TESTS
";"4";"0";"103 777""2K45.28 NEW";"ARC CA 125 REAGENT 100 TEST
";"4";"0";"27 113""2K46.01";"ARC ANTI TG CALIBRATOR
";"4";"0";"11 626""2K46.10";"ARC ANTI TG CONTROL";"4";"0";"8 483"
"2K46.25";"ARC ANTI TG RGT 100 TEST ";"4";"0";"26 872"
==============
"2K45.10 NEW";"ARC CA 125 CONTROL";"4";"0";"8 640";"BOITE";"";"TAXE 39% CD 38220000000"
"2K45.23 NEW";"ARC CA 125 REAGENT 400 TESTS ";"4";"0";"103 777"
"2K45.28 NEW";"ARC CA 125 REAGENT 100 TEST ";"4";"0";"27 113"
"2K46.01";"ARC ANTI TG CALIBRATOR ";"4";"0";"11 626"
"2K46.10";"ARC ANTI TG CONTROL";"4";"0";"8 483"
"2K46.25";"ARC ANTI TG RGT 100 TEST ";"4";"0";"26 872"
Which means that the data would seem to contain characters that are interfering with the processing.
Note that your word version does not include "BOITE";"";"TAXE 39% CD 38220000000" for instance.
But my output from your code does not match your output from your code (and your output misses the entire ...BOITE... line.)
So - somewhere we are getting word and notepad++ interpreting the same data differently.
I use editplus, which allows me to see the actual hex-codes in the file. Perhaps if you could examine the file with a hex-editor, the true file contents would be revealed.
I am writing a windows script to read in a txt file with 9 columns of data
I want to write this data out to a csv file to be loaded into a database.
I have found that one column is sometimes blank, so I would like to enter code 'rdp'
another column has mostly numbers, but for reason some values are a '.' (presumably indicating value less than 1. I would like to change these values to '0'
my code
for /F %%b in (c:\ts_users\newfiles_list.txt) do (
for /F "tokens=1,2,3,4,5,6,7,8,9" %%i in (%%b) do (
echo %%i,%%j,%%k,%%l,%%m,!idle!,%%o %%p,%%q >>%%~nb.csv
)
)
this manages to read in the txt file, then write it out as a csv.
column k is sometimes empty, column n sometimes has a '.'
I have tried variations of
set var=rdp
if %%k="" then set !k:=!var!
which doesnt work, so I a little stumped (after googling internet for days)
current input
201401241611 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME eu1ptsw002
201401241611 julie.noble rdp-tcp#9 3 Active 18 24/01/2014 14:24 eu1ptsw002
201401241611 svc.perfmon18 7 Disc 3 24/01/2014 14:15 eu1ptsw002
201401241611 reto.hofstetter 10 Disc 40 24/01/2014 10:57 eu1ptsw002
201401241611 lester.valentin 14 Disc 1:16 24/01/2014 11:53 eu1ptsw002
201401241611 philippe.bachmann 15 Disc 2 24/01/2014 12:45 eu1ptsw002
201401241611 patrik.soderlund rdp-tcp#2 21 Active 24 24/01/2014 07:42 eu1ptsw002
current output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,7,Disc,3,,14:15 eu1ptsw002,
201401241611,reto.hofstetter,10,Disc,40,,10:57 eu1ptsw002,
201401241611,lester.valentin,14,Disc,1:16,,11:53 eu1ptsw002,
201401241611,philippe.bachmann,15,Disc,2,,12:45 eu1ptsw002,
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,,24/01/2014 07:42,eu1ptsw002
required output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,18,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,rdp,7,Disc,3,24/01/2014 14:15,eu1ptsw002
201401241611,reto.hofstetter,rdp,10,Disc,40,24/01/2014 10:57,eu1ptsw002,
201401241611,lester.valentin,rdp,14,Disc,1:16,24/01/2014 11:53,eu1ptsw002
201401241611,philippe.bachmann,rdp,15,Disc,2,24/01/2014 12:45,eu1ptsw002
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,24,24/01/2014 07:42,eu1ptsw002
#echo off &setlocal disableDelayedExpansion
for /f "delims=" %%a in (file) do (
set "line=%%~a"
setlocal enabledelayedexpansion
set "line=!line:,.,=,0,!"
set "line=!line:,,=,rdp,!"
echo(!line!
endlocal
)
Is anyone aware of a library suitable for writing an image in .TMB format?
The .TMB format is suitable for printing logos from a Epson thermal receipt printer.
After about an hour or so of looking at binary data, I came to the following conclusion:
A *.TMB image is really just a serialized ESC/POS command to print a raster image.
Using the following command:
od -t a -v [YOUR_TMB_FILE] | head
we can view the binary data, as ASCII character data, in the beginning of the TMB file.
I had a file that looked something like this:
0000000 gs v 0 nul 5 nul P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...
According to the ESC/POS Programming Guide, the ASCII command to print a raster image is:
GS V 0
Hmm.. Interesting!
On a whim, I decided to convert 5 and P to their decimal equivalents, which are 53 and 80 respectively, the exact dimensions of my .TMB image (actually, its 80x53)!
Everything fell into place after this. The remainder of a .TMB file is just the binary image data.
Here is a one-off Python script I wrote to test my theory:
1 out = open('test.TMB', 'wb')
2
3 width = 80
4 height = 53
5
6 NUL = chr(0)
7 GS = chr(29)
8 V = chr(118)
9 ZERO = chr(48)
10
11 W = chr(width)
12 H = chr(height)
13
14 out.write(GS)
15 out.write(V)
16 out.write(ZERO)
17 out.write(NUL)
18
19 out.write(H)
20 out.write(NUL)
21 out.write(W)
22 out.write(NUL)
23
24 for y in range(0, height):
25 for x in range(0, width):
26 out.write(chr(127)) # looks like `del` in ASCII mode
27
28 out.close()
I have a problem compiling a program I made in BASIC. It's a DOS simulator that I was making in attempts to see if it is posssible to write an operating system entirly in BASIC. Every time I try to compile, I get these messages:
!SYNTAX ERROR IN LINE 15, COLUMN 50
UNEXPECTED E
EXPECTING : OR END OF LINE
What do I change to sovle this?
10 PRINT
11 PRINT "Starting..."
12 PRINT
13 PRINT
14 INPUT "Type the location of the Command Interpretter:"; I$
15 IF I$ = "C:\WINDOWS\COMMAND.COM" THEN GOTO 14 ELSE GOTO 13
16 INPUT "C:\>"; D$
17 IF D$ = "FORMAT" GOTO 25
18 IF D$ = "FDISK" GOTO 47
19 IF D$ = "HELP" GOTO 16
20 IF D$ = "DIR" GOTO 16
21 IF D$ = "MKDIR" GOTO 16
22 IF D$ = "WIN" GOTO 16
23 IF D$ = "CD" GOTO 16
24 IF D$ = "DEL" GOTO 16
25 PRINT "WARNING, ALL DATA ON REMOVABLE DISK"
27 PRINT "DRIVE A: WILL BE LOST!"
28 INPUT "Proceed with Format (Y/N)"; F$
29 IF F$ = "Y" THEN GOTO 28
30 IF F$ = "N" THEN GOTO 16
31 PRINT
32 PRINT
33 PRINT
34 PRINT "Fotmatting 1.44MB"
35 PRINT "Format complete."
36 PRINT "Writing out file allocation table"
37 PRINT "Complete."
38 PRINT "Calculating free space (this may take several minutes)...................."
39 PRINT "Complete."
40 PRINT
41 INPUT "Volume Label (11 charchters, ENTER for none)"
42 PRINT
43 PRINT " 1,440MB total disk space"
44 PRINT " 1,440MB available on disk"
45 PRINT
46 PRINT " 512 bytes in each allocation unit."
47 PRINT " 32,624 allocation units available on disk."
48 PRINT "Volume Serial Number is 326A-1312"
49 GOTO 16
50 PRINT "Incorrect DOS Version"
51 PRINT
52 GOTO 16
I used Vintage BASIC 1.0.1 as the compiler. Anyone know what's going on?
Windoze NT
I don't think there is an ELSE keyword in vintage basic, which is why you're getting the unexpected 'E' error.
I assume vintage BASIC is unstructured BASIC, you can refer to the wikipedia article for an example:
http://en.wikipedia.org/wiki/BASIC_programming_language
Also, you have some duplicate line numbers for 26 and 27, which explains the other errors.
The first two warnings are caused by your program having two lines 26, and two lines 27.
I would guess that the third message comes from your BASIC only supporting IF THEN and not IF THEN ELSE. In this case, you can encode it with IF GOTO.
Are you sure your version of BASIC has ELSE? Not all have...
I guess you are learning to program, right? May I ask a question? Why Basic? I think there are a lot of more useful and powerful (and mainly using modern practices of programing) languages to learn that you can use in a graphic OS and they are not more complicated to learn like Python for example (my son has your age and he is loving python). It's a simple language for simple things but very powerful if you need (and complicated too!).
Good luck!
I note that you've changed the code originally posted, deleting the duplicate line numbers That will make the first part of this answer look weird, but I'll leave it.
The compiler is telling you that you're re-using the same line numbers. Notice the following section of code?
26 PRINT "DRIVE A: WILL BE LOST!"
27 INPUT "Proceed with Format (Y/N)"; F$
26 IF F$ = "Y" THEN GOTO 28
27 IF F$ = "N" THEN GOTO 16
The fix is to renumber your lines. Now you know why you don't usually use increments of 1 between lines in languages that require line numbers! (You can likely find - or even write - a tool to do it for you, however.)
Regarding the error from:
15 IF I$ = "C:\WINDOWS\COMMAND.COM" THEN GOTO 14 ELSE GOTO 13
I've not run across "Vintage BASIC" before, but assuming the other answers about it not supporting an else are correct, you'll want something like:
15 IF I$ = "C:\WINDOWS\COMMAND.COM" THEN GOTO 14
16 IF I$ <> "C:\WINDOWS\COMMAND.COM" THEN GOTO 13
You may need to replace "<>" with "!=" or whatever your BASIC uses as a not equal to operator. Also, you'll have to do more renumbering, since you already have a line 16.