Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Create and write to a batch  (Read 3542 times)

0 Members and 1 Guest are viewing this topic.

SteveHell

  • Guest
Create and write to a batch
« on: April 15, 2007, 01:26:17 PM »
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
« Last Edit: April 15, 2007, 01:45:09 PM by SteveHell »

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Create and write to a batch
« Reply #1 on: April 15, 2007, 07:02:51 PM »
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... 8)

diablo416

  • Guest
Re: Create and write to a batch
« Reply #2 on: April 15, 2007, 10:11:58 PM »
this worked for me.. it produced the m3u file and loaded windows media player with it