1.

Solve : Create and write to a batch?

Answer»

WinXP servicepack 2

Here's my problem
I'm trying to create a batch file that will create a m3u file for my mp3's.
This much i have got done, but the problem I'm having is this.

when it goes to create the "gg.bat" output file, when it get to the %Choice% command it doesn't write to the file. Is there a simple way to fix this?

I really need to have this all in one batch because I'm going to convert it to exe formate when done.
Thanks
SteveHell



@echo off
dir /b/S *.mp3 >"MyM3uMaker-PlayList.M3U"
START /wait MyM3uMaker-PlayList.M3U
ECHO @ECHO off>> gg.bat
ECHO cls>> gg.bat
ECHO :start>> gg.bat
ECHO ECHO.>> gg.bat
ECHO ECHO 1. (Y)es>> gg.bat
ECHO ECHO 2. (N)o>> gg.bat
ECHO SET choice= >> gg.bat
ECHO set /p choice=Save the M3u file?>> gg.bat
ECHO if not '%choice%'=='' set choice=%choice:~0,1%>> gg.bat
ECHO if '%choice%'=='y' goto Yes>> gg.bat
ECHO if '%choice%'=='n' goto No>> gg.bat
ECHO ECHO "%choice%" is not valid please try again>> gg.bat
ECHO ECHO.>> gg.bat
ECHO goto start>> gg.bat
ECHO :Yes>> gg.bat
ECHO cls>> gg.bat
ECHO ECHO.>> gg.bat
ECHO ECHO M3u file saved to current mp3 directory.>> gg.bat
ECHO goto end>> gg.bat
ECHO :No>> gg.bat
ECHO cls>> gg.bat
ECHO del ".\"MyM3uMaker-PlayList.M3U">> gg.bat
ECHO ECHO.>> gg.bat
ECHO ECHO m3u file deleted.>> gg.bat
ECHO goto end>> gg.bat
ECHO :end>> gg.bat
ECHO PING 1.1.1.1 -n 5 -w 2 >NUL>> gg.bat
CALL gg.bat
I wouldn't use a batch... I'd write it in C++, and use temp files that can be created and deleted. Your program would compile as an EXE as you need. If you know C++ or another language, I'd use that language if you are familiar with it to run the processes that you need. In C++ you can use the "SYSTEM" command to pass commands to a command shell like a batch, and the VALUES that you want to pass can run within the C++ program and can be written to a log file as raw ascii etc.

With the batch if your batch is named gg.bat and you are trying to write to it, you might be hitting a file in use problem, where you cant write to the file until it is closed when the batch ends. You can work around this by using a combination of batch files to pass data back and forth and one closes as the other takes control in a back and forth motion, but self CONTAINING in a single exe might not be possible.

Which compiler are you using for converting the *.bat to *.exe Some of the higher end ones have advanced features which cost money, but I dont believe combining batches into a single exe is supported through any of them.

Probably not much help, but FIGURED I'd share this with you... this worked for me.. it PRODUCED the m3u file and loaded windows media player with it



Discussion

No Comment Found