Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

app to weld mpgs

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
suppose you got 1.mpg, 2.mpg, 3.mpg and so on till 10.mpg.
to get them all together i always have to do in a command prompt "copy /b 1.mpg+2.mpg ....."

so i wanna code an app that asks for the last file name without the extension (always supposed to be mpg), then creates a command and execs it with SHELL.

the app knows how many mpgs it has to get together by looking at the last character of the filename (video09, asf03, etc)

but i need a way to get all the filenames into the same string...
appending to a temp file doesn't work cause there's a line break for each print

thanks for your help and sorry if i made anyone dizzy (wait till you see how my code looks...)
 
Well, first of all, you can get rid of the line break that [tt]PRINT[/tt] inserts by adding a semicolon ; to the end of the line. However, there is a much better way to build up a string. You can simply add them together as though they were numbers:
[tt]
a$ = "Hello,"
b$ = "world!"
c$ = a$ + " " + b$
[/tt]
After this short sequence, [tt]c$[/tt] will contain the string [tt]"Hello, world!"[/tt] (with the space).

In general, though, you should strive to avoid using [tt]SHELL[/tt] whenever possible, because it makes your code require certain things of the OS. If the target system has a slightly different OS, or has been modified in some way (e.g., the command interpreter might not support the 'copy' command), then your code becomes broken. Consider the following snippet:
[tt]
LINE INPUT "Enter the number of the last file: ", a$
LINE INPUT "Enter the name of the output file: ", oFile$
lastFile% = VAL(a$)
OPEN oFile$ FOR BINARY AS #1
IF LOF(oFile$) THEN
PRINT
"The output file already contains data. Overwrite [y/N]? ";
DO
a$ = UCASE$(INPUT$(1)) ' read a character from the keyboard
IF a$ = CHR$(13) THEN a$ = "N" 'enter
IF a$ = CHR$(27) THEN a$ = "N" 'escape
LOOP UNTIL (a$ = "Y") OR (a$ = "N")
PRINT a$
IF a$ = "N" THEN END
CLOSE
#1 ' close the file,
KILL oFile$ ' delete the existing one,
OPEN oFile$ FOR BINARY AS #1 ' and start a new one
END IF
FOR
i% = 1 TO lastFile%
iFile$ = LTRIM$(RTRIM$(STR$(i%))) + ".mpg"
PRINT iFile$ + " ..."
ON ERROR GOTO notFound
OPEN iFile$ FOR INPUT AS #2 ' check if it exists first
CLOSE #2
OPEN iFile$ FOR BINARY AS #2
ON ERROR GOTO 0
buffer$ = SPACE$(4096)
bytesLeft& = LOF(2)
DO WHILE bytesLeft&
IF bytesLeft& < LEN(buffer$) THEN
buffer$ = &quot;&quot; ' free the string space as a separate operation, otherwise
buffer$ = SPACE$(bytesLeft&) ' it'll try to allocate more first
END IF
GET
#2, , buffer$ ' read in the buffer from the source file
PUT #1, , buffer$ ' write the buffer to the output file
bytesLeft& = bytesLeft& - LEN(buffer$)
totalBytes& = totalBytes& + LEN(buffer$)
LOOP
CLOSE
#2
NEXT i%
CLOSE #1
PRINT &quot;Done!&quot;; totalBytes&; &quot;bytes copied.&quot;
END

notFound:
PRINT &quot;Unable to access file &quot;; iFile$; &quot;, maybe it doesn't exist?&quot;
IF i% < lastFile% THEN
PRINT
&quot;Continue [Y/n]? &quot;;
DO
a$ = UCASE$(INPUT$(1)) ' read a character from the keyboard
IF a$ = CHR$(13) THEN a$ = &quot;Y&quot; 'enter
IF a$ = CHR$(27) THEN a$ = &quot;N&quot; 'escape
LOOP UNTIL (a$ = &quot;Y&quot;) OR (a$ = &quot;N&quot;)
PRINT a$
IF a$ = &quot;N&quot; THEN END
i% = i% + 1
iFile$ = LTRIM$(RTRIM$(STR$(i%))) + &quot;.mpg&quot;
RESUME
ELSE
END
END IF

[/tt]
(not tested by the way :))

Though this kind of thing may be beyond your current levels of stamina, they should be for what you strive :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top