You are not logged in.

#1 30 May 2014 08:25

apis
Member
Registered: 30 May 2014
Posts: 18

I have a problem

Hello, I am new here and I have a question.
I made a batch program, but there is a problem.

@echo off
color 0a
title test
:loop
cls
for %%a in (
""
" Batch test."
" Type your name."
) do echo;%%~a
set /p name="your name is:" || goto :loop

cls
for %%a in (
""
" Your name is %name%."
" Is it true?" >>(Problem in this line)<<
" Y. yes"
" N. no"
) do echo;%%~a
choice /c yn /n
if %errorlevel% == 1 exit
if %errorlevel% == 2 goto :loop

In the line "Is it true?" there is a problem. When the batch is executed,
that line not printed on the screen.

Please help!

(Also, sorry if my english is bad sad)

Offline

#2 30 May 2014 09:17

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 446

Re: I have a problem

You cannot use " ? " when you iterate strings. The plain FOR is intendended for file iteration and ? and * act as wildcards and cannot be escaped

Offline

#3 30 May 2014 09:37

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Oh, thanks!

Offline

#4 14 Jul 2014 13:18

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

How to make batch automatically find any files has .txt format and print the files names in screen?

Offline

#5 14 Jul 2014 13:33

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: I have a problem

In the simplest form:

dir /b/s *.txt

cmd | *sh | ruby | chef

Offline

#6 14 Jul 2014 13:54

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Thanks. You reply so fast. big_smile

Offline

#7 15 Jul 2014 10:34

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Another question, how to include a file inside batch? The example file is a .png picture.
When the batch is executed, it will extract the file.

Offline

#8 15 Jul 2014 11:20

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: I have a problem

You encode the image to a text representation by one of a number of methods.

The best method depends on the Windows version, 32 bit or 64 bit,  and if you want to use third party tools.

Last edited by foxidrive (15 Jul 2014 11:20)

Offline

#9 16 Jul 2014 06:02

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Thanks for reply. I have my own way to do this now, use CertUtil command.

Offline

#10 25 Jul 2014 07:01

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Is there someone here who knows VBScript and batch script? If there is, can you convert these scripts?
Script 1:

Sub Decode(InFile As String, OutFile As String)
    Dim Cypher As Byte
    Dim CypherPos As Long
    Dim I As Long
    Dim L As Long
    Dim File() As Byte
    Open InFile For Binary Access Read As #1
        L = LOF(1)
        ReDim File(L - 1)
        Get #1, , File
    Close #1
    CypherPos = (L And &HFFFFFFE) \ 2
    Cypher = File(CypherPos)
    For I = 0 To L - 1
        File(I) = (256 + File(I) - Cypher) And 255
    Next
    File(CypherPos) = Cypher
    
    Open OutFile For Output As #2
    Close #2
    Open OutFile For Binary Access Write As #2
        Put #2, , File
    Close #2
End Sub

Script 2:

Sub Encode(InFile As String, OutFile As String)
    Dim Cypher As Byte
    Dim CypherPos As Long
    Dim I As Long
    Dim L As Long
    Dim File() As Byte
    Open InFile For Binary Access Read As #1
        L = LOF(1)
        ReDim File(L - 1)
        Get #1, , File
    Close #1
    CypherPos = (L And &HFFFFFFE) \ 2
    Cypher = File(CypherPos)
    For I = 0 To L - 1
        File(I) = (256 + File(I) + Cypher) And 255
    Next
    File(CypherPos) = Cypher
    
    Open OutFile For Output As #2
    Close #2
    Open OutFile For Binary Access Write As #2
        Put #2, , File
    Close #2
End Sub

Thank you.

Someone? Anyone?

Nevermind.

Last edited by apis (27 Jul 2014 03:35)

Offline

#11 03 Aug 2014 09:30

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

How to get enter, up, down, left, and right button as input for choice command?

Offline

#12 17 Aug 2014 10:58

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Can someone tell me whats wrong on this script?

@echo off
cls
set "n=0"
set "r=%random%.bat"
:1
echo @echo off > %r%
call :create "A question here" "Answer 1" "Answer 2" "Answer 3" "Answer 4"
call :create "Another question here" "Answer 1" "Answer 2" "Answer 3" "Answer 4"
exit

:create
set /a "n+=1"
set /a "q=%n%+1"
for %%` in (
":data%n%"
"cls"
"echo."
"echo  Question #%n%:"
"echo  %~1"
"echo  a. %~2"
"echo  b. %~3"
"echo  c. %~4"
"echo  d. %~5"
"set /p ans="" | goto :data%n%"
"if "%%ans%%" == "a" goto data%q%"
"if "%%ans%%" == "b" goto data%q%"
"if "%%ans%%" == "c" goto data%q%"
"if "%%ans%%" == "d" goto data%q%"
"goto :data%n%"
) do (echo %%~`>>%r%)

If that script is executed, it will make another .bat file with random number.

@echo off 
:data1
cls
echo.
echo  Question #1:
echo  A question here
echo  a. Answer 1
echo  b. Answer 2
echo  c. Answer 3
echo  d. Answer 4
set /p ans="" | goto :data1
if "%ans%" == "a" goto data2
if "%ans%" == "b" goto data2
if "%ans%" == "c" goto data2
if "%ans%" == "d" goto data2
goto :data1
:data2
cls
echo.
echo  Question #2:
echo  Another question here
echo  a. Answer 1
echo  b. Answer 2
echo  c. Answer 3
echo  d. Answer 4
set /p ans="" | goto :data2
if "%ans%" == "a" goto data3
if "%ans%" == "b" goto data3
if "%ans%" == "c" goto data3
if "%ans%" == "d" goto data3
goto :data2

When that random.bat opened, press a or press b or c or d, then press enter, it repeats that question.
Can someone fix this?
Please, someone, reply...

Last edited by apis (18 Aug 2014 01:28)

Offline

#13 18 Aug 2014 08:20

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: I have a problem

You want a double pipe, rather than single, here:

set /p ans="" |

Might not fix it, but won't be helping.


cmd | *sh | ruby | chef

Offline

#14 20 Aug 2014 23:57

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: I have a problem

@apis

You has misspelled set /p ans="" |.
Must be:

set /p ans="" || goto :data1

.::{Honguito98}::.

Offline

#15 28 Aug 2014 13:04

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Oh. hmm

Offline

#16 29 Aug 2014 08:18

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,129

Re: I have a problem

There's nothing like an appropriate display of gratitude.


cmd | *sh | ruby | chef

Offline

#17 29 Aug 2014 10:02

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

How to get time/date of a file and save it in a variable?

Offline

#18 29 Aug 2014 20:31

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: I have a problem

for %D in (MyFile.txt) do set "FileDate=%~tD"

.::{Honguito98}::.

Offline

#19 04 Sep 2014 13:32

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

That script doesn't work for me. It's shows me an error.

~tD" was unexpected at this time.

Offline

#20 04 Sep 2014 22:13

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: I have a problem

Sorry for that!
Change  %%~tD and for %%D


.::{Honguito98}::.

Offline

#21 11 Sep 2014 15:22

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

Is it possible to have many colours in one screen?

Offline

#22 11 Sep 2014 22:06

Honguito98
Member
From: Mexico
Registered: 19 Sep 2013
Posts: 57

Re: I have a problem


.::{Honguito98}::.

Offline

#23 12 Sep 2014 01:21

apis
Member
Registered: 30 May 2014
Posts: 18

Re: I have a problem

How about sounds?
(Sorry if my questions make you tired.)

Offline

Board footer

Powered by