Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

901.

Solve : Question about tokens and delimeters?

Answer»

I'm just curious about something I couldn't find any more information about.

In the following code:

Code: [Select]echo off
for /f "tokens=1,2* delims=, " %%a in (test.txt) do echo %%a %%b %%c
pause

test.txt contains:

Code: [Select]This, is, just, a, test,
The delimeters are not applied after the first and second token, even though a wildcard was used.

Code returned the following:

Code: [Select]This is just, a, test,
Only way I could get delimiters to be applied on all tokens was by adding additional FOR variables and using a token range. If I was to display a bigger amount of text ALONG with using the delimiters, I would be limited to 52 active FOR variables.

Does this mean that the delimiters are not compatible if the tokens are set using a wildcard? Or are the delimiters dependent to the amount of the set FOR variables?

Perhaps I MISSED something in help for the FOR command. Any ideas? Quote from: Night on August 10, 2014, 08:45:40 AM


In the following code:

Code: [Select]echo off
for /f "tokens=1,2* delims=, " %%a in (test.txt) do echo %%a %%b %%c
pause

test.txt contains:

Code: [Select]This, is, just, a, test,
Code returned the following:

Code: [Select]This is just, a, test,

I'm not clear on your question but that is correct. 
The spaces and commas are treated as separators up the the start of the third term, which starts with just

The * means "put the rest of the line into the next variable"

If it's unclear then explain what you expected, or what you need it to look like.

Example from help for FOR command.

Quote
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do echo %i %j %k

    would parse each line in myfile.txt, ignoring lines that begin with
    a semicolon, passing the 2nd and 3rd token from each line to the for
    body, with tokens delimited by commas and/or spaces.  Notice the for
    body statements reference %i to get the 2nd token, %j to get the
    3rd token, and %k to get all remaining tokens after the 3rd.

From that example, as said, %k variable displays all the remaining tokens. I'm not sure why the delimiters are not applied to the remaining tokens after the variable (%k). As it's stated from that example that the variable %k stands for ALL following tokens, not just the rest of the line. The delimiters are only applied to the given tokens (2,3) while the wildcard that represents all the remaining tokens is ignored.

I hope this clarifies my question a BIT more. Quote from: Night on August 10, 2014, 10:26:06 AM
it's stated from that example that the variable %k stands for ALL following tokens, not just the rest of the line.

As you have FOUND, the variable %k stands for the rest of the line, that is, any remaining tokens and separators all together. The help documentation could be clearer in EXPLAINING that, I suppose,  (it can be occasionally opaque or seemingly incomplete) but you have discovered by experiment the way it works.

Quote
the wildcard that represents all the remaining tokens is ignored.

It is not "ignored". It is correctly interpreted. The asterisk ("wildcard") represents the whole remainder of the line. There are no more "tokens" to process.







Thanks for the clarification! I guess the documentation isn't all that good after all.

That would be all.
902.

Solve : Error??

Answer»

Hi, I wanted to see my hand at scripting and got started, it took me 5 minutes to make a canculator that worked, but I wanted something more... special. But one I finished coding, it didnt work! it errors.
QUOTE

ECHO off
:start
echo Welcome to Batch Canculator!
echo What do you wish number one too be?
set /p num1=
echo The number you picked was %num1%
echo What do you wish number two too be?
set /p num2=
echo The number you picked was %num2%
echo Number 3 is not needed, put a "nil" if you don't need a third number, OTHERWISE, enter the number!
set /p num3=
echo The number you picked was %num3%
echo Which would you like, to Add, Subtract, Multiply, or Divide? UNLESS you want to Leave.
set /p type=
if %type%==Add goto Add
if %type%==Subtract goto Subtract
if %type%==Multiply goto Multiply
if %type%==Divide goto Divide
if %type%==Leave goto Leave
:Add
set /Add Answer=%num1%+%num2+num3%
echo %Answer%
pause
goto start
:Subtract
set /Subtract Answer=%num1%-%num2-num3%
echo %Answer%
pause
goto start
:Multiply
set /Multiply Answer=%num1%*%num2*num3%
echo %Answer%
pause
goto start
:Divide
set /Divide Answer=%num1%/%num2/num3%
echo %Answer%
echo
pause
goto start
:Done
echo. Done!
The set command to do maths is set /a

Type set /? and you can read the portions about the arithmetic. Quote from: TheLastAlly on August 16, 2014, 05:03:34 PM
But one I finished coding, it didnt work! it errors.

You invented a set of switches for the SET command that do not exist... /Add, /Subtract, /Multiply, and /Divide. The way to produce code that works is not to guess and hope the computer understands what you meant, but rather to study the documentation.

You may be interested to know that set /a can evaluate a string e.g. 5+226 or 34-12 or 27*5 or 55/11 or (5*30)/10 or 6+5+4+3+2+1

e.g.

Code: [Select]echo off
echo Welcome to Batch Calculator!
:loop
set /p tocalc="Enter an expression, or 0 to quit: "
if "%tocalc%"=="0" goto done
set /a result=%tocalc%
echo Answer=%result%
goto loop
:done
echo Done!
sample run:

(Do you notice anything about the 4th result?)

Code: [Select]Welcome to Batch Calculator!
Enter an expression, or 0 to quit: 5-3
Answer=2
Enter an expression, or 0 to quit: 6+5+4+3+2+1
Answer=21
Enter an expression, or 0 to quit: 15*3
Answer=45
Enter an expression, or 0 to quit: 10/3
Answer=3
Enter an expression, or 0 to quit: 0
Done!Isn't 10/3 like 3.33333333333333
Or unless it doesn't go into decimals
Quote from: shiverbob on August 17, 2014, 12:34:10 AM
Isn't 10/3 like 3.33333333333333
Or unless it doesn't go into decimals

You got it.

Now try 10000000000/2

Quote from: Salmon Trout on August 17, 2014, 12:24:48 AM
The way to produce code that works is not to guess and hope the computer understands what you meant, but rather to study the documentation.

Of course that is not right; making mistakes and learning from them is part of learning too.
903.

Solve : Increment value in xml file?

Answer»

Hi Guys,

I'm running into an ISSUE where an xml file is not read unless the number is higher than the locally cached xml file. I need this file read every day, so i'm looking for a batch file to increment the number by 1. I'll put this into a scheduled task so the file number increases daily.

The file name is: enterprise-sitelist.xml

The file contents are below:

Code: [Select]<rules version="2">
  <emie>
    <domain exclude="false">URL1</domain>
    <domain exclude="false">URL2</domain>
    <domain exclude="false">URL3</domain>
    <domain exclude="false">URL4</domain>
    <domain exclude="false">URL5</domain>
    <domain exclude="false">URL6</domain>
    <domain exclude="false">URL7</domain>
    <domain exclude="false">URL8</domain>
    <domain exclude="false">URL9</domain>
    <domain exclude="false">URL10</domain>
  </emie>
</rules>

Basically I just need rules version to be CURRENT +1You could probably do this with batch using brute force but using VBScript and the XML document object MIGHT be a whole lot easier.

Code: [Select]Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False

xmlDoc.Load("enterprise-sitelist.xml")
Set singleNode = xmlDoc.selectSingleNode("//rules")

singleNode.attributes.getNamedItem("version").text = singleNode.attributes.getNamedItem("version").text + 1

xmlDoc.save "enterprise-sitelist.xml"


Save the code with a VBS extension and run from the command prompt as cscript <scriptname>.vbs

 Thank you very much! That works a charm.

Shaun

904.

Solve : Batch File - batch window auto-focus??

Answer»

I've GOT a batch file I'm using to maintain my disk image backups.

As it stands now, the batch window will open on top of whichever window I currently have open, (my browser for example), but the browser will remain focused.
A click in the batch window will give it focus so I can address the prompt(s) contained therein, but I'm wanting it to auto-focus.

Is this possible?Command windows opened with the START command have focus.

Umm, I'm not completely following you.

You're saying I need to use the START command from within the batch file itself or in the Task Scheduler?


EDIT:

You see, the batch file isn't starting any external programs/etc.
All it's really doing is manipulating some files in a subfolder where the batch file itself resides and, via CHOICE, asking me if Acronis is done creating the latest backup before it renames and moves said backup into the subfolder...Make a one-line launcher batch script; add it to your scheduled tasks. It will launch the batch you want to run in a new window, and give it focus, and then exit.

Example:

Code: [Select]start "" "cmd" /c "C:\Path to Batch\Bla bla bla\Batch-that-gets-focus.bat"If I understand correctly, you have a batch file running in the background that will POP up errors on your disk images and you want it to bring it to the top. 

here is how I would do it:

Code: [Select]echo off
echo THIS IS THE ERROR!!!!!!!!!!!!
echo THIS IS AN ERROR!!!!!!!

pause
REM this stops it from opening 1000000000000000000000000000000000000000000 windows

start er.bat

er.bat
Code: [Select]echo off

title = call
REM this lets you know that it has responded to an error
REM it can be replaced with whatever you want (or taken out)

call ertest.bat
REM this brings you back to the initial page (thus showing you all your errors)


hope this helps (even a bit)  Quote from: Salmon Trout on March 30, 2012, 11:40:23 AM

Make a one-line launcher batch script; add it to your scheduled tasks. It will launch the batch you want to run in a new window, and give it focus, and then exit.

Example:

Code: [Select]start "" "cmd" /c "C:\Path to Batch\Bla bla bla\Batch-that-gets-focus.bat"

Thanks ST, but that script does nothing.
My batch doesn't won't run even though Task Scheduler reports a status of "Running".

Presumably your code is completely suppressing the window altogether?


Quote from: Lemonilla on April 01, 2012, 06:34:16 PM
If I understand correctly, you have a batch file running in the background that will pop up errors on your disk images and you want it to bring it to the top. 

Nope, you've got it wrong.
My batch is waiting on my input before it's allowed to continue or quit.

The batch file opens up on top of other windows just fine.
My issue is that it's not in focus when I let Task Scheduler run it on a schedule.
Needless to say, running it manually via task scheduler, or simply double clicking the batch file directly, will give the window focus.

FWIW, Here's how things are working.

Machine is on at backup time:
Acronis images my drives at 8AM every Monday.
Task Scheduler kicks in two hours later, plenty of time for Acronis to finish creating the file, and manipulates said images.

Machine is off at backup time:
BOTH Acronis and Task Scheduler want to run immediately at next system boot.
Since the file exists but isn't finished yet, I have the batch sitting at a prompt waiting for a "Y" keystroke.
When Acronis is done, I press "Y" and the batch continues.

Here's my file it this helps:
This "version" has all the network attached storage stuff removed for ease of testing from the Desktop if you're so inclined...


Code: [Select]ECHO OFF

C:
CHDIR %~dp0

CLS
ECHO WAITING FOR ACRONIS FILE DUMP
PING 1.1.1.1 -n 1 -w 3000 >NUL

IF NOT EXIST *.tib CALL :ABORT

CLS
CHOICE /M "IS ACRONIS DONE DUMPING DRIVE IMAGE"
IF %ERRORLEVEL% EQU 2 CALL :EXIT


CLS
ECHO RENAMING BACKUP.
PING 1.1.1.1 -n 1 -w 3000 >NUL
IF EXIST *.tib REN *.tib Backup.tib

IF NOT EXIST ".\BACKUPS\" CALL :MAKEFOLDER

:MOVEFILE
CLS
ECHO MOVING BACKUP INTO STORAGE DIRECTORY
PING 1.1.1.1 -n 1 -w 3000 >NUL
MOVE Backup.tib ".\BACKUPS\"

CLS
ECHO RESTRUCTURING BACKUP STORAGE DIRECTORY
PING 1.1.1.1 -n 1 -w 3000 >NUL
CHDIR ".\BACKUPS\"
IF EXIST Backup2.tib DEL Backup2.tib
IF EXIST Backup1.tib REN Backup1.tib Backup2.tib
IF EXIST Backup.tib REN Backup.tib Backup1.tib

CLS
ECHO ALL DONE!
PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT


REM *************SUBROUTINES**************

:ABORT
CLS
ECHO NO BACKUP FOUND, ABORTING
PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT

:MAKEFOLDER
MKDIR ".\BACKUPS\"
CLS
ECHO NO STORAGE DIRECTORY FOUND, CREATING IT NOW
PING 1.1.1.1 -n 1 -w 3000 >NUL
CALL :MOVEFILE

:EXIT
CLS
ECHO OK, EXITING.
PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT



Hmm, now that I'm thinking about it...
I wonder if I can make the batch read the date/time the was last modified?
If so, perhaps I could create an argument along the lines this for when the job is missed:

If last modified within the last two hours, ask me if Acronis is done.

That way, I could do away with the prompt altogether when the job runs as scheduled. Quote from: S3NTYN3L on April 03, 2012, 08:36:45 AM
Thanks ST, but that script does nothing.

Works fine on my system. I set it to run with highest privileges. I presume the path and file name are correct? What OS are you running this on?

Quote from: Salmon Trout on April 03, 2012, 10:49:21 AM
Works fine on my system. I set it to run with highest privileges. I presume the path and file name are correct? What OS are you running this on?


Running with highest privileges as well on Windows 7, (as stated on the left of my posts).I have got this to run at a set time and also on demand

(1) Launcher.bat

Code: [Select]start "" "cmd" /c "C:\Batch\Test\After 22-01-2012\Batchfocus\CHBatchfocus.bat"
(2) CHBatchfocus.bat

Note: I have commented out various ping and CLS commands to make the screen capture tell a story, and added a couple of lines to make things clearer.

Code: [Select]ECHO OFF

echo The time is %time%

set /p dummy="if we have focus, you can type SOMETHING here "

C:
CHDIR %~dp0

REM CLS
ECHO WAITING FOR ACRONIS FILE DUMP
REM PING 1.1.1.1 -n 1 -w 3000 >NUL

IF NOT EXIST *.tib CALL :ABORT

CLS
CHOICE /M "IS ACRONIS DONE DUMPING DRIVE IMAGE"
IF %ERRORLEVEL% EQU 2 CALL :EXIT


CLS
ECHO RENAMING BACKUP.
PING 1.1.1.1 -n 1 -w 3000 >NUL
IF EXIST *.tib REN *.tib Backup.tib

IF NOT EXIST ".\BACKUPS\" CALL :MAKEFOLDER

:MOVEFILE
CLS
ECHO MOVING BACKUP INTO STORAGE DIRECTORY
PING 1.1.1.1 -n 1 -w 3000 >NUL
MOVE Backup.tib ".\BACKUPS\"

CLS
ECHO RESTRUCTURING BACKUP STORAGE DIRECTORY
PING 1.1.1.1 -n 1 -w 3000 >NUL
CHDIR ".\BACKUPS\"
IF EXIST Backup2.tib DEL Backup2.tib
IF EXIST Backup1.tib REN Backup1.tib Backup2.tib
IF EXIST Backup.tib REN Backup.tib Backup1.tib

CLS
ECHO ALL DONE!
PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT


REM *************SUBROUTINES**************

:ABORT
REM CLS
ECHO NO BACKUP FOUND, ABORTING
pause
REM PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT

:MAKEFOLDER
MKDIR ".\BACKUPS\"
CLS
ECHO NO STORAGE DIRECTORY FOUND, CREATING IT NOW
PING 1.1.1.1 -n 1 -w 3000 >NUL
CALL :MOVEFILE

:EXIT
CLS
ECHO OK, EXITING.
PING 1.1.1.1 -n 1 -w 3000 >NUL
EXIT


















I was trying to put the start command into the add arguments field, my bad.

OK, your way works, but it doesn't do anything.
It just opens and closes the launcher window, opens and closes my original batch file and blows through the original (known working) script without processing any commands contained within...

I also tried your edited batch and get the same results. Everything works fine on my system. Mine is Windows 7 Professional 64-bit; my user account has Administrator privileges.


Would this help? Combine the launcher and the batch file code in a single batch file:

Code: [Select]echo off
setlocal

if [%1]==[Recurse] goto %2
start "Focused Window" "%0" Recurse Label %1 %2 %3 %4 %5 %6 %7 %8 %9
exit

:Label
  echo Your Batch Code Here

If it seems a bit dinky, well, it is! But it should keep thing simple.  Quote from: Sidewinder on April 03, 2012, 04:06:24 PM
Would this help? Combine the launcher and the batch file code in a single batch file:

This does not address the question of why my solution works for me but not for him.
I have devised a method to allow you to launch an elevated command prompt via the command line, with no clicking, and the new prompt gets focus, with no clicking.  You can just keep typing.

Here's how to do it:

1.  Create a task using task scheduler, as detailed elsewhere on this thread.  The task's command line is simply:
      Code: [Select]cmd
and the "Run with highest privileges" box must be checked.

2. Create a batch file called "sudocmd.cmd" in your PATH with this:
  Code: [Select]schtasks /run /tn "myTasks\sudocmd"
sudocmd.vbs

3.  Create a file called "sudocmd.vbs" also in your path, most conveniently in the same folder, as:

Code: [Select]set wshShell = CreateObject("WScript.Shell")
WScript.Sleep 500
wshShell.AppActivate("Administrator: taskeng.exe")

This last little bit is the trick that will bring the new command window into focus.

4. Then just type sudocmd at a command prompt and voila!

Another possibility is this little gem I found:
     http://sourceforge.net/projects/sudowin/
905.

Solve : Batch for checking file?

Answer»

I need to check a log.txt file if it is changed, so if it is than must copy XL.txt file
If it is not than must copy ML.txt file

The Idea of checking that is to copy log.txt to log1.txt and than
use fc command like
fc  log.txt log1.txt > nul
 if errorlevel 1 (goto C) else (goto D)

But problem is because log.txt fill up very slowly and as I see fc chek a file size and file size changes takes more than 10 minutes.

How can solve that problem to check if log.txt was changed last 5 minutes?
Maybe this might help you.  If some even happens only once every  ten minuets,  you should not be testing all the time because that will burden the CPU. Instead, you may schedule a task to be performed every ten minuets.
Here is a general discussion about the windows schedule thing for batch.
Run a batch file with Windows task scheduler (From stackoverflow.com)

Quote

... the same problem, but I found another solution without having to modify my batch script.  The only thing that I missed out is at the 'Action' settings - "Start in (Optional)" option.
Go the task properties --> Action tab --> Edit --> Fill up as below:
    Action: Start a program
    Program/script: path to your batch script e.g. C:\Users\beruk\bodo.bat
    Add arguments (optional): <if necessary - depending on your script>
    Start in (optional): Put the full path to your batch script location e.g. C:\Users\beruk\
Then Click OK
...
For more info, search for:
Windows task scheduler

Hope that helps 
thanks, task scheduler is not a solution I need a batch.
Perhaps  you did not understand. Batch does not have an effective scheduler. Wasting time in batch is a bad idea. Instead  you create a batch file that does what you want. It must be a cone time self-contained batch. No LOOPING. It runs once and stops.

The n you make a task e to start that batch file every ten minutes.
Make a batch file. Name it  My_Job.bat  and it must be a job that can be done  in well under ten minutes.
In an abstract way, it will do this:

Start Task::
  For every ten minutes
    Do My_Job.bat
  Next time frame
End.

No, you don't write that code, that is an abstract of what you tell the task schedule thing GADGET in Windows. It is not a batch command.
Maybe a video will help
https://www.youtube.com/watch?v=8tMzockuB2g
Does that help?
...
Yeah, the video has too much stuff. Here is a simple explanation
Here is a simple explanation:
Schedule a task in Windows 7
You have to give the name of a batch file with the full path.
- Unless it is in the path.





Quote from: GEEK-9pm on August 04, 2014, 11:16:02 AM
Perhaps  you did not understand. Batch does not have an effective scheduler. Wasting time in batch is a bad idea. Instead  you create a batch file that does what you want. It must be a cone time self-contained batch. No looping. It runs once and stops.

Start Task::
  For every ten minutes

Batch can do that very efficiently, Geek.

Code: [SELECT]:loop
echo ...
timeout /t 600 /nobreak
goto :loop
Quote from: foxidrive on August 04, 2014, 11:23:15 AM
Batch can do that very efficiently, Geek.

Code: [Select]:loop
echo ...
timeout /t 600 /nobreak
goto :loop

OK. That will work.
That is easier that reading up on how to use the Scheduler.
Ok that's sounds good.
But how can I use that loop, because file is filling up differend time to get 1k and than to get 2k to get noticable for command FCI guess I would check the Archive Attribute.  Every time a file changes the archive attribute should be turned on.
Code: [Select]H:\>echo hello>mylog.txt

H:\>attrib mylog.txt
A            H:\mylog.txt

H:\>xcopy /m mylog.txt H:\test\
H:mylog.txt
1 File(s) copied

H:\>attrib mylog.txt
             H:\mylog.txt

H:\>echo hello again>>mylog.txt

H:\>attrib mylog.txt
A            H:\mylog.txtok how can I check with this if file is changed last 5 minutes?bump
906.

Solve : batch for finding batch?

Answer»

I have some batch files with the same name and differend folders and I need to be executed.
So I need a batch to find copylog.bat
find path for that file and than use it for execute it
and than find another copylog.bat
find path for that file and use it with copylog.bat to execute it.
Untile the last copylog.bat and all executed.

Can someone helps me please?How many files? Why not do it by hand?
Who did this? Why not make him do it?
In the future, implement a practice of using number to disambiguate files  with the  same name. Like Copyright(1),   Copyright(2),   Copyright(3),  an so on.

This command at the drive root
Code: [Select]DIR *.bat /b /s >likstWill makes a list of all bat files with path name. The list can be parsed in a FOR loop. Or you can look at the list ans SEE what was found.

this didn't show any path of it.
I am not so good with forfiles tooThis MIGHT be what you are after:


Code: [Select]echo off
for /r "d:\base\folder" %%a in (copylog.bat?) do (
   cd /d "%%~dpa"
      call "%%a"
)
thank you this works now.No I found out it doesn't work, because it runs another batch file which should not be runned instead of the right one.
this I have in runbats.bat
Code: [Select]echo off
for /r "d:\base\folder" %%a in (copylog.bat?) do (
   cd /d "%%~dpa"
      call "%%a"
)and it is in \\mysrv\Drivers\DVD

and this are batch filles all the same in difrend subfolders copylog.bat

Code: [Select]echo off
pushd "..\logfiles"
del /Q ..\logfiles\new\*.txt
for /f "delims=" %%a in ('dir LOGH*.txt /b /od /a-d ') do set "lastest_file=%%a"
copy "%lastest_file%" "..\logfiles\new\"
popd

but instead of this batch it runs this one user_sel.bat

Code: [Select]robocopy \\mysrv\Drivers\DVD\conf\aleksandar\log \mysrv\Drivers\DVD\conf\maja\chk /W:5
robocopy \\mysrv\Drivers\DVD\conf\aleksandar\log \\mysrv\skleda\Drivers\DVD\conf\suzana\chk /W:5

exit
both copylog.bat and user_sel.bat are in the same folder
\\mysrv\skleda\Drivers\DVD\conf\suzana

and next copylog.bat and user_sel.bat
\\mysrv\skleda\Drivers\DVD\conf\maja

and next copylog.bat and user_sel.bat
\\mysrv\skleda\Drivers\DVD\conf\jure

etctry changing the line`call "%%A" ` to ` if "%%A"=="copylog.bat" call "%%A"`. Quote from: Blisk on AUGUST 04, 2014, 03:18:55 AM

but instead of this batch it runs this one user_sel.bat

The code that I suggested will not do that when using a local drive, and you need to say that you are using a network.



Quote from: Lemonilla on August 04, 2014, 06:20:05 AM
try changing the line`call "%%A" ` to ` if "%%A"=="copylog.bat" call "%%A"`.
That doesn't work, nothing happends Quote from: foxidrive on August 04, 2014, 09:21:11 AM
The code that I suggested will not do that when using a local drive, and you need to say that you are using a network.
sorry, that's why I posted now allCan you map the network share to a local drive letter?

Do the batch file use network paths in them too? Quote from: foxidrive on August 04, 2014, 11:25:44 AM
Can you map the network share to a local drive letter?

Do the batch file use network paths in them too?
no unfotunally can not map it, because I use %computername% for string in each users backup

for this  what I need is all above, paths and batchs.
All use newtorks pathsbump
no luck with this one So if I get this right you want two files to be ran.
Simple IF it is in the same directory use " start  filename.bat " then use " taskkill filename.bat " mabye a sleep command in the middle of then but if there not in the same dir use " for  " or " forfiles " and/ or you could help you understand this batch stuff like I did trial and error and this website
http://ss64.com/nt/
Hope this helps
Shiverbob
907.

Solve : .VBS file that play sound. I don't know how to stop it?

Answer»

Hello, sorry for my poor english.
Sorry if this is not the right place to post about VBscript.

I have the following code, that play a sound without openning any player. The code repeats the sound in LOOP.
I don't know how to STOP the sound. The only way to stop is "kill" the wscript.exe in windows TASK manager.
How can I add a messagebox with an "OK" button to stop the sound ?


Thanks!

Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "c:\windows\media\notify.wav"
nada = 1
do while nada = 1
wscript.sleep 100
Sound.Controls.play
loop
wscript.sleep (int(Sound.currentmedia.duration)+1)*1000
Solved!

ADDED commands in the first .VBS file to call another .vbs file. This another .vbs file displays a popup on the screen with an only "OK" button. When "ok" button is pressed, the rest of code kill the wscript.exe application.

'This was added in first .vbs file to call the second .vbs file:

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "inter.vbs"   
Set objShell = Nothing

'This is added in second .vbs file to display message and then kill the wscript.exe after "ok" button is pressed:

x=msgbox ("Message", 0+16+4096, "Tittle")

strComputer = "."
strProcess = "'wscript.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcess )

For Each objProcess in colProcess
   objProcess.Terminate()
NextSeems like it would have been easier to break the loop by Opening a message box and then setting the NADA variable to 0 if they click OK.

908.

Solve : Batch AI?

Answer»

Hello, I am make a game where you have your city that you build and create armys to attack the other ai's city but I have know idea how to get the ai to do stuff. And I don't know if this is posible but anything would help
Thanks a millon,
ShiverbobHere is how I did AI in my "game".  I had a 'turn' variable that changed each "day" in game.  Then I had a file like this:
Code: [Select]5. call :build House 5 6
15. call :build Armory 7 8
...Then something along these lines to run it:
Code: [Select]for /F "tokens=1-2 DELIMS=." %%A in (ai.txt) do if %turn% EQU %%A %%B

But mine was centered around NATURAL disasters, and not REALLY a competent opponent.Should it all be a BUNCH of %randoms% and ifs

909.

Solve : Find Hard Drive ID Without Using WMIC?

Answer»

Hi,

I have a problem trying to find the Hard Drive ID but cannot use WMIC as I am using a version of Windows PE that does not have it.

I know VOL C: Will return the volume ID, but I need the actual HD serial number.

Is there a way of doing this?

CheersIt'll be on the HDD label...Is Powershell an option?

Code: [Select]powershell "Get-WmiObject Win32_PhysicalMedia | Format-Table Tag, SerialNumber"Lol .. yes I know that, I need to find it using DOS and then (hopefully) SAVE it in a variable.

This is for a bespoke method of unattended imaging from a generic IMAGE onto several devices - all the devices are the same architecture ie same size hard drive, same PARTITION set up, same RAM, CPU etc.

Quote from: foxidrive on September 03, 2014, 09:09:23 AM

Is Powershell an option?

Code: [Select]powershell "Get-WmiObject Win32_PhysicalMedia | Format-Table Tag, SerialNumber"

Unfortunately no
The OP mentione4d WMIC as not available.
http://en.wikipedia.org/wiki/Windows_Management_Instrumentation
More info about it:
http://technet.microsoft.com/en-us/library/bb742610.aspx

Question: Why can it not be run under PE?
Because it's not included...and you cannot run outside apps on PE. Quote from: Fugazi on September 03, 2014, 09:15:11 AM
Unfortunately no

Is WSH/VBS available?But this thread says it can be installed into WIN_PE
http://www.msfn.org/board/topic/143622-how-to-install-wmic-in-winpe/Creating a WinPE LiveCD for WMI lookups

https://www.404techsupport.com/2012/03/creating-a-winpe-livecd-for-wmi-lookups/
Quote from: Geek-9pm on September 03, 2014, 09:47:30 AM
The OP mentione4d WMIC as not available.
http://en.wikipedia.org/wiki/Windows_Management_Instrumentation
More info about it:
http://technet.microsoft.com/en-us/library/bb742610.aspx

Question: Why can it not be run under PE?

Because it was not included in the wim when it was created. I am trying to use an already created wim without making changes to it. Quote from: Salmon Trout on September 03, 2014, 12:24:18 PM
Creating a WinPE LiveCD for WMI lookups

https://www.404techsupport.com/2012/03/creating-a-winpe-livecd-for-wmi-lookups/

Thank you, was hoping that I wouldn't have to create a NEW winpe livecd Quote from: Fugazi on September 04, 2014, 02:14:29 AM
Thank you, was hoping that I wouldn't have to create a new winpe livecd
Not that that is going to take you all day.     While you are at it, you might as well switch over to WinPE USB stick!
910.

Solve : Need help on approaching a problem..?

Answer»

Not sure if DOS can help me here.. but does DOS, or VB, or any programming language have the ability to change the monitor settings on a machine?

So i'd like to make a script which when RUN will active the "Extended Display" function on my computer, and another which will change it to "Computer only"

Any thoughts? If you were using Windows 7 there is a built in command to do this CALLED displayswitch.exe. You could just use a shortcut to launch each option.
On XP I am not sure. I remember doing it with a third party program.This tool called nircmd may help - it has many more features for batch file use.

http://www.nirsoft.net/utils/nircmd.html


Quote

setdisplay {monitor:index/name} [width] [height] [color bits] {refresh rate} {-updatereg} {-allusers}

Changes your display settings. The [width] and [height] parameters represents the number of pixels on your screen. The [color bits] parameter represents the number of colors shown on your screen (8 - 256 color, 16 - 16bit color, 24 - 24bit color, and so on). {refresh rate} is an optional parameter that specifies the monitor refresh rate. If you specify the {-updatereg} parameter, the new settings will be saved in the Registry. If you specify both {-updatereg} and {-allusers} parameters, the new settings will be saved in the Registry for all users.
If you have multiple monitors, you can use the optional monitor parameter, which specifies for which monitor you want to change the display settings. You can specify the monitor by index (0 for the FIRST monitor, 1 for the second ONE, and so on) or by SPECIFYING a string in the system monitor name. The monitor name can be found in the Device manager of Windows: Right click on the monitor item, and then choose 'Properties'. The string displayed in the 'location' field is the monitor name.

Example:

setdisplay 800 600 24 -updatereg
setdisplay 1024 768 24 90
setdisplay 1024 768 8
setdisplay monitor:1 1024 768 24 90
setdisplay monitor:name1 1024 768 24 90

setprimarydisplay [Monitor index/name]

Set the primary monitor, for systems with multiple monitors only.

Example:
setprimarydisplay 1
setprimarydisplay 2
setprimarydisplay \\.\DISPLAY3
911.

Solve : Add -Val- to file names?

Answer»

Hello

i wanna ADD different values to file name (after and before)

before, i will select file types (rar - zip - dat)

val = Date, time, directory
AddOn_words (i will add in to batch file)


directory1 = c:\Uk1\Ali
directory2 = c:\NL\Stock
directory3 = c:\NL\Veli    and others...  LAST directory name important on path

file name = Test-File1.rar

After File Names :
format_1 =   #FileName_#Directory__#Date

result 2 :   Test-File1_Ali__22_08_2014.rar   /   Test-File1_Veli__22_08_2014.rar    /   Test-File1_Stock__22_08_2014.rar

format_2 =   #FileName_#Directory__#Date__#Time

result 2 :   Test-File1_Ali__22.08.2014__12_26.rar   /    Test-File1_Veli__22.08.2014__12_26.rar   /   Test-File1_Stock__22.08.2014__12_26.rar

format_3 =   #FileName_#Directory__#Date_#Word   (i will write value word in to batch file... example = Sales, Order, Wait)

result 3 :   Test-FileXXX_Ali__22.00.2014_Order.rar     /    Test-FileXXXX_Veli__22.08.2014_Input.rar     /     Test-FileXXXX_Stock__22.08.2014_Input.rar


Before File Names:
#Directory__#Date__#Time__#FileName :    Ali__22.08.2014__12_26__Test-File1.rar   /    Veli__22.08.2014__12_26__Test-File1.rar   /   Stock__22.08.2014__12_26__Test-File1.rar
#Directory__#Date__#FileName
#Directory__#FileName
#Date__#Time__#FileName

and others FORMATS....

i will change, i will create new/different formats for my files

how i can do ?

thank you very muchDo any filenames contain ! characters?

Are the files all in one single folder?Hello

before i am changing all different chars on file-names ! ' " , ... &LT;>[]()
your pre-batch files doing   

what i do ?

have much files in directory
before i will create format with bacth file
and will CALL Format  from directory, changes will execute in there

and.. i will change directory, will call different or same batch file for THAT Directory

yes... execute will be in one single folder, but folder name is variable

could you help me ?Will the date and time variables be fixed for a directory?

If you have dynamic date and time then each file could have a different time, or date if it is around midnight.when call the batch file.. time and date its
examle... now 
22_08_2014   (not .  using _ ) ;   04_42 (not : and 24h)

when i change directory and call the batch file will insert that time and date (yes dynamic D-T)This will rename files like my file.txt to my file - foldername - date - time.txt

Test it in a folder with copies of your files first.

CODE: [Select]echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "d=YYYY%-%MM%-%DD%"
set "t=%HH%-%Min%-%Sec%"
for %%b in ("%cd%") do set "folder=%%~nxb"

for /f "delims=" %%a in ('dir /b /a-d ') do (
     ren "%%a" "%%~na - %folder% - %d% - %t%%%~xa"
)

pause

912.

Solve : Extracting from a Text file using FOR /f?

Answer»

Need some advice -

Trying to use the FOR /f command to extract specific data from a text file and into an output file.

Looking to do the following:
00024803830002480383002480383

Need bytes 5-10 (480383) and dump to another text file.
And then add to the beginning and end of that data

So ultimately:  test480383test

Using this so far: 

FOR /f "tokens=1,2 delims=0002" %%a in (test.txt) do echo %%a %%b

But this only gives me:  48 383

Kinda new to this command so looking for a little help - really appreciate it.
Thanks
It is not clear what you want.
Give more examples.
00024803830002480383002480383

The above set of numbers are contained w/in a text file (and there are 100's of lines like this with different values)

I want to extract bytes 5-10 (which in the above EXAMPLE would be 480383) and place into a separate text file as:

test480383test

test.txt
00024803830002480383002480383
00022621170002480383002480383
00056432510002480383002480383
00069137560002480383002480383

Example batch
echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in (test.txt) do (
    set inputline=%%A
    set sliceline=!inputline:~4,6!
    echo INPUT  !inputline!
    echo Output test!sliceline!test
    )

Batch output
Input  00024803830002480383002480383
Output test480383test
Input  00022621170002480383002480383
Output test262117test
Input  00056432510002480383002480383
Output test643251test
Input  00069137560002480383002480383
Output test913756test


This is a robust option

Code: [Select]type file.txt |repl "^....(......).*" "test$1test" >newfile.txt
This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Salmon Trout -

Thanks - that's exactly what I needed.  Made a few edits:

echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in (test.txt) do (
    set inputline=%%A
    set sliceline=!inputline:~4,6!
    echo test!sliceline!test
    ) >>log.log


Is there a specific command to obtain just the data that STARTS at a specific column/byte?

example:

11111 22222 33333
111 222 333 444

Both '33333' and '444' start on byte/column 13

=-=-=-=
Just figured this out...while I was saving this postThis is a post script.
If you know ahead of time that you have to parse file NAMES, it helps to adopt some conventions for file naming. The underline char _ is allowed both in Windows and some other systems and can be used om  the internet. That could be used to show where a key begins or ends. Otherwise, you have to make things position dependent.  In on e example it was ALWAYS chars 5 to 10 inclusive. However, the use of delimiters makes it easier to avoid human errors when naming files.


913.

Solve : find some words and add a word after them in batch script?

Answer»

I have a txt files in a FOLDER. I want a batch script which

   - goes to that directory and
   - in that file it looks and insert “timestamp” for whatever comes after "AAA" or "BBB" and before "{".

Example:
AAA mmmmmmmmmm {

After running the script: AAA mmmmmmmmmm_timestamp {

how can I do it? any suggestion?I'd look into using the helper program repl.bat.  I'm going to SEE if I can figure it out past that.God Bless the DOS Helpers...
They get no respect for answering some of the queerist questions onboard...

Kudos to you guys.... Quote from: Lemonilla on September 02, 2014, 05:31:16 PM

I'd look into using the helper program repl.bat.  I'm going to see if I can figure it out past that.

How did you go Lemonilla?  I was going to let this question slide coz it hasn't got enough info
but now that you've mentioned repl.bat I also had a CRACK at it.

Code: [Select]echo off
type "file.txt" | repl "(.*)(AAA|BBB)(.*)({.*)" "$1$2$3timestamp$4"
pause


file.txt
AAA mmmmmmmmmm {aaa

BBB mmmmmmmmmm {bbb

ZAAA mmmmmmmmmm {ccc

ZBBB mmmmmmmmmm {ddd


and the output:

AAA mmmmmmmmmm timestamp{aaa

BBB mmmmmmmmmm timestamp{bbb

ZAAA mmmmmmmmmm timestamp{ccc

ZBBB mmmmmmmmmm timestamp{ddd


This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Thanks Foxidrive, I tried * for the wildcard, but it didn't seem to do anything.  From you're code it looks like (.*) is the wildcard? Quote from: Lemonilla on September 03, 2014, 02:53:23 PM
From you're code it looks like (.*) is the wildcard?
That is common syntax for most programs that do regular expressions.  Many of them are very similar.
The parenthesis are a GROUPING.  The period matches any character.  The asterisk matches zero or more OCCURRENCES of the previous character.
914.

Solve : bat file to move folder(s) containing certain file type?

Answer»

I need the bat file to scan a directory (Folder A) and look at all of the SUBFOLDERS. If a subfolder contains any .PDF files (subfolder A1) then I need that folder to be moved into a NEW location (Folder B). Is this even possible via bat? The tree looks like this:

Folder A
   A1
     1.txt
     2.txt
     3.pdf
   B1
     1.txt
     2.jpg

So only the A1 subfolder would be moved to Folder B because it contained a .pdf fileTest this on some COPIES of your folders.

Code: [Select]ECHO off
for /r "d:\folder A" %%a in (*.pdf) do if exist "%%a" move "%%~dpa" "d:\folder B"

915.

Solve : How can i modify a windows 7 services with a bat?

Answer»

What the command to modify by example in WINDOWS 7 the searchindexer.xe service ?

Best Regards
One way is net start/stop (service name) (INDEXING service is listed as Windows Search in services.msc) and service name is Wsearch

examples:

net start Wsearch
net stop Wsearch

In services.msc the service STARTUP type MUST be set to one of:

Automatic (delayed start)
Automatic
Manual

If it is set to Disabled, then net start will not work.

Also

use the SC (service control) command, for help  type SC /? at the PROMPT, type SC QUERY to see a list of running services, type SC QUERY | FIND "SERVICE_NAME:" to just see the service names, read help for more...








Wonderful indeed.
Tried and running with net start and stop

putting the service name between ""

Best Regards

916.

Solve : Batch to move files in a single directory into separate folders in groups of 10?

Answer»

I have a directory with almost 500 pdfs in it.  They are all named/numbered sequentially with a 3 digit numeral in the 8th, 9th, and 10th place in the file NAME.  I would like to create a batch that moves those files into separate folders in groups of 10.  So when it was over, I'd have 50 or so folders named "001-010", "011-20", etc. with the corresponding files placed in each.  I could obviously do this manually, but I'll have a new batch of files every week that I will need to do this for.  The other variable is that there won't necessarily be the same number of files every week.  This week I may have 488, next week I may have 506 and so on and so forth.  I'd appreciate any help!  Thanks.Could you give some typical file names, obfuscating non-essential parts if you like?

******_001_**_****_***_*****_*****.pdf

This is an example of a typical file name.  Like I said, the 8th to 10th spot is the counter.  The rest are all variable, but the files will all follow this format, including number of characters.  Thanks.So in theory the 3 digit section could go from 000 up to 999? Or is it more restricted than that?
And you want to classify them into decades potentially from "001-010" ... "991-999" is going to have only 9 possible members...

You are correct, except there will be no 000.  The first number will always be 001.  And while in theory it will go up to 999, most likely it will top out in the 500 range. The number scheme is easy enough, I show the first 3 and the last 3 possible decades; Directories only to be created if there are files to go in them? Is that right?

Directory name: 001-010
Files [if they are found]:
******_001_**_****_***_*****_*****.pdf
******_002_**_****_***_*****_*****.pdf
******_003_**_****_***_*****_*****.pdf
******_004_**_****_***_*****_*****.pdf
******_005_**_****_***_*****_*****.pdf
******_006_**_****_***_*****_*****.pdf
******_007_**_****_***_*****_*****.pdf
******_008_**_****_***_*****_*****.pdf
******_009_**_****_***_*****_*****.pdf
******_010_**_****_***_*****_*****.pdf
Directory name: 011-020
Files [if they are found]:
******_011_**_****_***_*****_*****.pdf
******_012_**_****_***_*****_*****.pdf
******_013_**_****_***_*****_*****.pdf
******_014_**_****_***_*****_*****.pdf
******_015_**_****_***_*****_*****.pdf
******_016_**_****_***_*****_*****.pdf
******_017_**_****_***_*****_*****.pdf
******_018_**_****_***_*****_*****.pdf
******_019_**_****_***_*****_*****.pdf
******_020_**_****_***_*****_*****.pdf
Directory name: 021-030
Files [if they are found]:
******_021_**_****_***_*****_*****.pdf
******_022_**_****_***_*****_*****.pdf
******_023_**_****_***_*****_*****.pdf
******_024_**_****_***_*****_*****.pdf
******_025_**_****_***_*****_*****.pdf
******_026_**_****_***_*****_*****.pdf
******_027_**_****_***_*****_*****.pdf
******_028_**_****_***_*****_*****.pdf
******_029_**_****_***_*****_*****.pdf
******_030_**_****_***_*****_*****.pdf


...


Directory name: 971-980
Files [if they are found]:
******_971_**_****_***_*****_*****.pdf
******_972_**_****_***_*****_*****.pdf
******_973_**_****_***_*****_*****.pdf
******_974_**_****_***_*****_*****.pdf
******_975_**_****_***_*****_*****.pdf
******_976_**_****_***_*****_*****.pdf
******_977_**_****_***_*****_*****.pdf
******_978_**_****_***_*****_*****.pdf
******_979_**_****_***_*****_*****.pdf
******_980_**_****_***_*****_*****.pdf
Directory name: 981-990
Files [if they are found]:
******_981_**_****_***_*****_*****.pdf
******_982_**_****_***_*****_*****.pdf
******_983_**_****_***_*****_*****.pdf
******_984_**_****_***_*****_*****.pdf
******_985_**_****_***_*****_*****.pdf
******_986_**_****_***_*****_*****.pdf
******_987_**_****_***_*****_*****.pdf
******_988_**_****_***_*****_*****.pdf
******_989_**_****_***_*****_*****.pdf
******_990_**_****_***_*****_*****.pdf
Directory name: 991-999
Files [if they are found]:
******_991_**_****_***_*****_*****.pdf
******_992_**_****_***_*****_*****.pdf
******_993_**_****_***_*****_*****.pdf
******_994_**_****_***_*****_*****.pdf
******_995_**_****_***_*****_*****.pdf
******_996_**_****_***_*****_*****.pdf
******_997_**_****_***_*****_*****.pdf
******_998_**_****_***_*****_*****.pdf
******_999_**_****_***_*****_*****.pdf



That is exactly what I'm looking for.Note: code below is a quick hack, it seems to work, please try it out on test data! I have to go now and 1. wash the dishes 2. shower 3. get a whisky and sit with the family and watch The Walking Dead 4. go to bed so give it a whirl and report back any issues. Back tomorrow evening in about 20 HOURS I am in Europe and it is now 8:56 PM. Place it in the folder where the PDFs are, which is where the new folders will be created. If you re-run it later with different files it will place them in these folders according to the 3 digit number and create more folders if needed. It does not check for name collisions in the destination folder or anything else fancy like that.

I created a folder and put in it 567 files with this format

Abcdef_555_gH_ijkl_mno_pqrst_uvWXy.pdf

I ran this batch

echo off
setlocal enabledelayedexpansion
for /l %%A in (10,10,1000) do (
    set n1=%%A
    set /a n1=n1-9
    set n2=%%A
    set dn1=00!n1!
    set dn2=00!n2!
    set dn1=!dn1:~-3!
    set dn2=!dn2:~-3!
    if "!dn2!"=="000" set dn2=999
    Set DirName=!dn1!-!dn2!
    for /L %%B in (!n1!,1,!n2!) do (
        set fn=00%%B
        set fn=!fn:~-3!
        if not "!fn!"=="000" (
            for %%C in (*.pdf) do (
                set fname=%%C
                set fnum=!fname:~7,3!
                if "!fnum!"=="!fn!" (
                    if not exist !Dirname! md !dirname!
                    echo Moving file: !fname! to Folder: !Dirname!
                    move !fname! !Dirname!
                    )
                )
            )
        )
    )

and it moved those files into 57 folders, names starting at 001-010 and ending at 561-570, in 20 seconds, screen output like this

They were only small files, bigger ones may TAKE longer overall

Moving file: Abcdef_548_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 541-550
        1 file(s) moved.
Moving file: Abcdef_549_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 541-550
        1 file(s) moved.
Moving file: Abcdef_550_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 541-550
        1 file(s) moved.
Moving file: Abcdef_551_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 551-560
        1 file(s) moved.
Moving file: Abcdef_552_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 551-560
        1 file(s) moved.
Moving file: Abcdef_553_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 551-560
        1 file(s) moved.
Moving file: Abcdef_554_gH_ijkl_mno_pqrst_uvWXy.pdf to Folder: 551-560

note that this post was edited:

This is another way to do it: like Salmon Trout's solution it will have problems with filenames that contain ! characters.

Code: [Select]echo off
setlocal enabledelayedexpansion
set c=0
for /L %%a in (1001,1,1999) do (
   set /a counter=c %% 10, num2=c+10, c=c+1
   set "num=%%a"
   set "num=!num:~-3!"
   set "num2=000!num2!"
   set "num2=!num2:~-3!"
         if !counter! EQU 0 rd "!folder!" 2>nul & set "folder=!num!-!num2!" & MD "!folder!" 2>nul
         if exist "??????_!num!_*.pdf" (
            echo moving file !num! to !folder!
    move "??????_!num!_*.pdf" "!folder!" >nul
         )
)
rd "!folder!" 2>nul
Quote from: GWJ3 on August 25, 2014, 11:36:23 AM

******_001_**_****_***_*****_*****.pdf

This is an example of a typical file name.  Like I said, the 8th to 10th spot is the counter.  The rest are all variable, but the files will all follow this format, including number of characters.  Thanks.
Weird.  That looks exactly like the file naming we use for our PDF's where I work..The OP has not indicated if he/she still needs a solution. Anyhow, this is how I would do it these days; I filled a folder with 999 pdf files, of mixed sizes from 29 KB to 14 MB, named them with the number part from 001 to 999. It should be saved as a .vbs file in the folder to be processed. DOUBLE click to run, or create a shortcut somewhere



strHost = Right(WScript.FullName, 11)
strHost = LCase(strHost)
If strHost <> "wscript.exe" Then
        Set objShell = CreateObject("WScript.Shell")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strCmdLine = Chr(34) & objFSO.BuildPath(WScript.Path, "wscript.exe") & Chr(34)
        strCmdLine = strCmdLine & " "
        strCmdLine = strCmdLine & Chr(34) & WScript.ScriptFullName & Chr(34)
        objShell.Run strCmdLine
        Set objShell = Nothing
        Set objFSO = Nothing
        WScript.Quit
End If
Set fso        = CreateObject("Scripting.FileSystemObject")
ThisFolder     = fso.GetParentFolderName(Wscript.ScriptFullName)
Set objFolder  = fso.GetFolder(ThisFolder)
Set AllFiles   = objFolder.Files
FilesMoved     = 0
FoldersCreated = 0
Ssec=DateDiff("s", "01/01/1970 00:00:00", Now)
For Each File in AllFiles
    FileName = File.Name
    FileExt  = fso.GetExtensionName(File)
    If lcase(FileExt) = "pdf" Then
        NumPart = Mid(Filename, 8,3)
        DS      = 1+(Int((NumPart-1)/10)*10)
        DE      = DS + 9
        If DE = 1000 Then DE = 999
        FolderName   = Right(DS + 1000, 3) & "-" & Right(DE + 1000, 3)
        FolderExists = fso.folderExists(FolderName)
        If Not folderExists Then
           fso.CreateFolder(FolderName)
           FoldersCreated = FoldersCreated + 1
        End If
        fso.movefile FileName, FolderName & "\"
        FilesMoved = FilesMoved + 1
    End If
Next
Esec=DateDiff("s", "01/01/1970 00:00:00", Now)
Elapsed = Esec - Ssec
MsgText = FilesMoved & " Files moved " & vbcrlf & FoldersCreated & " Folders created" & vbcrlf
MsgText = MsgText & "Elapsed: " & Elapsed & " second(s)" & vbcrlf
MsgBox MsgText, 0, "Script finished"

917.

Solve : Get selective columns from a dump file using MS DOS and make new dump?

Answer»

Hi:
I've a dump file in text format (pipe separator). I need to select specific columns from the file and make a new file. For EXAMPLE

Original Dump (I need to select column 3, 4 and 6; and make a new dump). How can I do it in MS DOS using a batch file?
----------------
AAA|BBB|CCC|DDD|EEEE|FFFF|GGGG|HHHH
TTT|MMM|KKK|123|FFFF|VVVV|IIII|BBBB
XXX|SSS|AAA|ZZZ|TTTT|JJJJ|RRRR|YYYY

Output Dump
---------------
CCC|DDD|FFFF
KKK|123|VVVV
AAA|ZZZ|JJJJ

Please help.

TanvirAssuming you are using CMD.exe from Windows and not actually a version of MS DOS.
Code: [Select]echo off
for /F "tokens=3,4,6 delims=|" %%G in (file.txt) do echo %%G^|%%H^|%%I>>newfile.txtThanks Squashman. Your post is really helpful. But I need one more help, I need to extract file with any name (*.txt or file*) instead of a static name (file.txt).

echo off
for /F "tokens=3,4,6 delims=|" %%G in (file.txt) do echo %%G^|%%H^|%%I>>newfile.txt

I've TRIED with *.txt or file* but it doesn't work. Could you please let me know how to resolve it.

Thanks,TanvirI've found a problem in the script. It doesn't recognize blank field. Please help me in this issue as well. Picked column 3, 4 and 6. For Example:

INPUT:
--------
VVVVV|BBBB|3212|9M9M|7777|MMMM|899
sssss||4444|AAAA|3333|LLLL|101
RRRR|PPPP|5555|1111|5555|PPPP|770

It returns OUTPUT:
---------------------
3212|9M9M|MMMM
AAAA|3333|101
5555|1111|PPPP

Actual Output should be:
---------------------------
3212|9M9M|MMMM
4444|AAAA|LLLL
5555|1111|PPPP

Thanks, Tanvir Quote from: tanvir.khan on September 04, 2014, 05:59:43 AM

I've found a problem in the script. It doesn't recognize blank field. Please help me in this issue as well. Picked column 3, 4 and 6. For Example:

INPUT:
--------
VVVVV|BBBB|3212|9M9M|7777|MMMM|899
sssss||4444|AAAA|3333|LLLL|101
RRRR|PPPP|5555|1111|5555|PPPP|770

It returns OUTPUT:
---------------------
3212|9M9M|MMMM
AAAA|3333|101
5555|1111|PPPP

Actual Output should be:
---------------------------
3212|9M9M|MMMM
4444|AAAA|LLLL
5555|1111|PPPP

Thanks, Tanvir
Not a problem with the script.  It is more of a problem with your data.  The FOR /F command always sees consecutive delimiters as one. If you would have provided that information upfront, I could have coded for that instance.  That is the main problem with providing obfuscated data.  It is better to provide real world examples up front.Thanks for your feedback. As I've said the script works fine if all the fields have value like below: (real time example)

SUBCOS|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY|
2|30|20150830|0|0|20160226235959|11|3|20170101000000|
2|44|20140329|0|0|20140923235959|12|4|20140328003330|
2|20|20140722|2|0|20150118235959|11|3|20140518151446|

But if few fields are NULL, i.e. in second ROW there is no RATE (3, 4 & 6 columns are picked)

SL|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY|
2|30|20150830|55|99|20160226235959|11|3|20170101000000|
2||20140329|33|90|20140923235959|12|4|20140328003330|
2|20|20140722|22|91|20150118235959|11|3|20140518151446|

Output comes:
----------------
DATE|ACCSTATE|ACTTIME|
20150830|55|20160226235959|  ----Ok
33|90|12|                                  -----As RATE field is blank, insted of picking DATE column, it picks ACCSTATE as column 3 which actually is 4
20140722|22|20150118235959|  -----Ok   

Please let me know if you need any information.

Thanks, TanvirThis uses dbenham's ParseCSV.bat to reformat the file and then Squashman's code to output the data.

Save both batch files into the same folder as file.csv and run this one.

Code: [Select]echo off
call ParseCSV.bat "/i:|" "/o:|" <file.csv >file.csv.tmp
for /F "tokens=3,4,6 delims=|" %%G in (file.csv.tmp) do >>newfile.csv echo %%~G^|%%~H^|%%~I
del file.csv.tmp




ParseCSV.bat
Code: [Select]if (X)==(Y) end /* harmless hybrid line that begins a JScrpt comment

::************ Documentation ***********
::parseCSV.bat version 1.0
:::
:::parseCSV  [/option]...
:::
:::  Parse stdin as CSV and write it to stdout in a way that can be safely
:::  parsed by FOR /F. All columns will be enclosed by quotes so that empty
:::  columns may be preserved. It also supports delimiters, newlines, and
:::  quotes within quoted values. Two consecutive quotes within a quoted value
:::  are converted into one quote.
:::
:::  Available options:
:::
:::    /I:string = Input delimiter. Default is a comma.
:::
:::    /O:string = Output delimiter. Default is a comma.
:::
:::    /E = Encode output delimiter in value as \D
:::         Encode newline in value as \N
:::         Encode backslash in value as \S
:::
:::    /D = Escape exclamation point and caret for delayed EXPANSION
:::         ! becomes ^!
:::         ^ becomes ^^
:::
:::parseCSV  /?
:::
:::  Display this help
:::
:::parseCSV  /V
:::
:::  Display the version of parseCSV.bat
:::
:::parseCSV.bat was written by Dave Benham. Updates are available at the original
:::posting site: http://www.dostips.com/forum/viewtopic.php?f=3&t=5702
:::

::************ Batch portion ***********
echo off
if "%~1" equ "/?" (
  setlocal disableDelayedExpansion
  for /f "delims=: tokens=*" %%A in ('findstr "^:::" "%~f0"') do echo(%%A
  exit /b 0
)
if /i "%~1" equ "/V" (
  for /f "delims=:" %%A in ('findstr /bc:"::%~nx0 version " "%~f0"') do echo %%A
  exit /b 0
)
cscript //E:JScript //nologo "%~f0" %*
exit /b 0


************ JScript portion ***********/
var args     = WScript.Arguments.Named,
    stdin    = WScript.Stdin,
    stdout   = WScript.Stdout,
    escape   = args.Exists("E"),
    delayed  = args.Exists("D"),
    inDelim  = args.Exists("I") ? args.Item("I") : ",",
    outDelim = args.Exists("O") ? args.Item("O") : ",",
    quote    = false,
    ln, c, n;
while (!stdin.AtEndOfStream) {
  ln=stdin.ReadLine();
  if (!quote) stdout.Write('"');
  for (n=0; n<ln.length; n++ ) {
    c=ln.charAt(n);
    if (c == '"') {
      if (quote && ln.charAt(n+1) == '"') {
        n++;
      } else {
        quote=!quote;
        continue;
      }
    }
    if (c == inDelim && !quote) c='"'+outDelim+'"';
    if (escape) {
      if (c == outDelim) c="\\D";
      if (c == "\\") c="\\S";
    }
    if (delayed) {
      if (c == "!") c="^!";
      if (c == "^") c="^^";
    }
    stdout.Write(c);
  }
  stdout.Write( (quote) ? ((escape) ? "\\N" : "\n") : '"\n' );
}
I had found another post online about changing the DOUBLE PIPES to |#null#| and then running that output to another FOR /F command to un-delimit the output.  But then you have to run that data through another SET command to remove the #null#.  Would probably have issues with poison characters as well.Thanks to both of you. It returns the correct output now but each field comes with " like below:

"2"|"147500"|"1906342342"|"2"|"20140830125243"
"2"|"0"|"1903312025"|"197"|"20140327111829"
"2"|"765952"|"1903312029"|"160"|"20140327174850"

I've tried removing " from parser file but the output become wrong again. Just need to eliminate the ". As I'm very beginner with DOS need further help.

Another help I need - How can I call multiple files instead of a single one here

call ParseCSV.bat "/i:|" "/o:|" <file.csv >file.csv.tmp

i.e. call ParseCSV.bat "/i:|" "/o:|" <*.csv >file.csv.tmp ---I tried but it doesn't work

Please help.

Thanks/
TanvirIs it OK if I ask a question?
If this was a CSV file --
Why not just use a SPREADSHEET to parse it.
Just  asking. Quote from: Geek-9pm on September 08, 2014, 08:42:21 AM
Is it OK if I ask a question?
I think the OP's last post answers your question.  They need to do it on multiple files.  Would you want to open up multiple files and manually process all of them on a daily basis? Quote from: tanvir.khan on September 08, 2014, 08:27:03 AM
Thanks to both of you. It returns the correct output now but each field comes with " like below:

"2"|"147500"|"1906342342"|"2"|"20140830125243"
"2"|"0"|"1903312025"|"197"|"20140327111829"
"2"|"765952"|"1903312029"|"160"|"20140327174850"
That is not the correct output. It has more than 3 fields. Nor would it be the correct input because you said you wanted columns 3, 4 & 6 and you only have 5 columns.

I used your last data example
Code: [Select]SL|RATE|DATE|ACCSTATE|PREVBALANCE|ACTTIME|USERSTARE|RATEPLAN|EXPIRY|
2|30|20150830|55|99|20160226235959|11|3|20170101000000|
2||20140329|33|90|20140923235959|12|4|20140328003330|
2|20|20140722|22|91|20150118235959|11|3|20140518151446|And this is the output I got.
Code: [Select]DATE|ACCSTATE|ACTTIME
20150830|55|20160226235959
20140329|33|20140923235959
20140722|22|20150118235959Program is working for the 2nd time as you described your data.  I used the following input which has surround quotes around each field
Code: [Select]"2"|""|"147500"|"1906342342"|"2"|"20140830125243"
"2"|""|"0"|"1903312025"|"197"|"20140327111829"
"2"|""|"765952"|"1903312029"|"160"|"20140327174850"And the output does not have any surround quotes.  I did not change any of the code that Foxidrive posted.
Code: [Select]147500|1906342342|20140830125243
0|1903312025|20140327111829
765952|1903312029|20140327174850Dear Geek-9pm: Actually it's not a CSV, those are text files as I mentioned in my first post.

Dear Squashman: No, files will come in a folder automatically with extension .txt; I've to parse those make a single dump (an auto job will run every 1 hr) and upload into a Oracle database using SQL Loader. So, I need to parse all a files of .txt extension an make a single dump.

My Input files don't have quotes. But when I run the Parse Script the output comes with quote. These quotes appear because of this line in the parse script:

if (c == inDelim && !quote) c='"'+outDelim+'"' ---I removed quotes from here, quotes disappear but returns wrong result 

Did you use the same parse script foxidrive provided and also parsed from text file?

Need further help.

Thanks/Tanvir Quote from: tanvir.khan on September 08, 2014, 10:01:29 AM
My Input files don't have quotes. But when I run the Parse Script the output comes with quote. These quotes appear because of this line in the parse script:

if (c == inDelim && !quote) c='"'+outDelim+'"' ---I removed quotes from here, quotes disappear but returns wrong result
No.  It is not because of that line. 

Quote from: tanvir.khan on September 08, 2014, 10:01:29 AM
Did you use the same parse script foxidrive provided and also parsed from text file?
Quote from: Squashman on September 08, 2014, 09:50:42 AM
I did not change any of the code that Foxidrive posted.
918.

Solve : note.bat?

Answer»

So I've been working on this project to redirect stdout and stderr into a temporary text file so you can view help MENUS in a separate window easily.  It works for the most part at the moment, but for some reason it crashes with no error when executed on a batch file.  Does anyone have any idea's what could be going wrong or how to fix it?

Code: [Select]:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::
::: SCRIPT.........: note.bat
::: VERSION........: 3.0
::: DATE...........: 09/11/2014
::: AUTHOR.........:
::: DESCRIPTION....: Script that will TAKE input and execute
:::                  the input, sending all stdout to a temporary
:::                  file located at note.txt.  The script
:::                  will then open the file and display stdout
:::                  in as text in a notepad document.
:::                  This allows for movement and recollection of
:::                  help menus and other key information.
:::
:::      note [command]
:::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


rem echo off
setlocal

set _=%*
if not defined _ goto :help
if /i "%1"=="/?" goto :help

%_% >note.txt 2>&1
ping ::1 -n 2 >nul
start notepad note.txt
ping ::1 -n 2 >nul
del /f note.txt
goto :exit

:help
echo.
echo Enter command to send stdout to a notepad window.
echo.
echo.  note [command]
echo.
:exit
endlocal

How did you learn all that batch? Programming?

If you wouldn't mind also telling me what program do you use to DEBUG and run your scripts and programs?..See if this solves the issue.  Without sample input command lines it's unclear how you are using it.

Code: [Select]call %_% >note.txt 2>&1 Quote from: RedDos7665 on September 17, 2014, 09:35:38 AM

How did you learn all that batch? Programming?

If you wouldn't mind also telling me what program do you use to debug and run your scripts and programs?..
There really isn't a TRUE IDE for writing batch.  You basically can write your programs in any text editor and then double click on them to run them or run them from the cmd line by typing the name of the batch file.

Most people do chose to use a programming text editor which helps in highlighting key words that are commands or variables.  Some of these editors allow you to also run the program from editor.  I prefer to use Notepad++ for all my batch files. Quote from: foxidrive on September 17, 2014, 10:36:43 AM
See if this solves the issue.  Without sample input command lines it's unclear how you are using it.

Code: [Select]call %_% >note.txt 2>&1

I just tried that, and here is what I found:
*I edited it to write to %temp%\note.txt instead of just note.txt, Should not alter outcome.

Code: (cmd (no call)) [Select]Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\cmdPlugins>note repl /?

C:\cmdPlugins>rem echo off

C:\cmdPlugins>setlocal

C:\cmdPlugins>set _=repl /?

C:\cmdPlugins>if not defined _ goto :help

C:\cmdPlugins>if /I "repl" == "/?" goto :help

C:\cmdPlugins>repl /?  1>note.txt 2>&1
Code: (cmd (call %_%)) [Select]C:\cmdPlugins>note repl /?

C:\cmdPlugins>rem echo off

C:\cmdPlugins>setlocal

C:\cmdPlugins>set _=repl /?

C:\cmdPlugins>if not defined _ goto :help

C:\cmdPlugins>if /I "repl" == "/?" goto :help

C:\cmdPlugins>call repl /?  1>C:\Users\LEMONI~1\AppData\Local\Temp\note.txt 2>&1


C:\cmdPlugins>ping ::1 -n 2  1>nul

C:\cmdPlugins>start notepad C:\Users\LEMONI~1\AppData\Local\Temp\note.txt

C:\cmdPlugins>ping ::1 -n 2  1>nul

C:\cmdPlugins>del /f C:\Users\LEMONI~1\AppData\Local\Temp\note.txt

C:\cmdPlugins>goto :exit

C:\cmdPlugins>endlocal

So it runs when you use 'call %_%' but it writes the help menu to call and not repl (the batch file I'm testing with).


'start %_%' does not work, because it opens the help menu for repl in another cmd window, and does not redirect it to note.txt

Quote from: RedDos7665 on September 17, 2014, 09:35:38 AM
How did you learn all that batch? Programming?

If you wouldn't mind also telling me what program do you use to debug and run your scripts and programs?..

I learned mostly by reading these threads and downloading and examining other people's scripts. Quote
but it writes the help menu to call and not repl

That's funny. 

It's a bug in cmd that shows the help for the call command, but this is all you need:

Code: [Select]echo off
%* >"%temp%\note.txt" 2>&1 & notepad "%temp%\note.txt"


It will only ever have the one temp file and will overwrite it every time.

Quote from: foxidrive on September 17, 2014, 09:01:46 PM
That's funny. 

It's a bug in cmd that shows the help for the call command, but this is all you need:

Code: [Select]echo off
%* >"%temp%\note.txt" 2>&1 & notepad "%temp%\note.txt"


It will only ever have the one temp file and will overwrite it every time.

Wow, no idea why that fixed it, but it works now.  Thanks! Quote from: Lemonilla on September 18, 2014, 10:38:46 AM
no idea why that fixed it, but it works now.

If you write a batch file - and that script executes another batch file - then you need to use call to return to the next line in the script, otherwise the executed batch file will take full control and never return.

This is the reason why your batch file didn't continue when you used note repl /? because repl ran and then it exited.
Owing to the bug you found with call, you can't use call to simply fix your script.

The batch file I posted above only has one real line so call isn't needed to return control to the script - and notepad is launched using the & command separator.

HTH
919.

Solve : batch counter?

Answer»

I MIGHT need some help on a batch thing i'm working on. I need a COUNTER that goes from 1% to 100%, with variables that I can EASILY change the values with. Can someone just post the code here, and tell me where I can play around with the variables such as speed and LENGTH?

ty  This progress bar is pretty neat: miskox is the Author

Code: [Select]::miskox
::Dostips: Re: Counting records
::cnt_all is the number of records (INCREASE this number if your computer is too fast).
echo off
cls
call :createbinvalue 218
call :createbinvalue 196
call :createbinvalue 191
call :createbinvalue 179
call :createbinvalue 192
call :createbinvalue 217
call :createbinvalue 219

set spaces=                                                                                &rem
set fillr13=%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%%chr219%
set fillr=%fillr13%%fillr13%%fillr13%%fillr13%%fillr13%%fillr13%
cls
set /a cnt=0
set /a cnt_all=11111
set /a old_percent=-1

:00
set /a cnt=cnt+1
set /a percent=100 * cnt / cnt_all


if not %percent%==%old_percent% set old_percent=%percent%&&call :create_progress_bar %percent%
if %cnt%==%cnt_all% goto :EOF
goto :00

:create_progress_bar

set /a proc=(77 * %1 + 22 ) / 100
title %1 %%

call set strng1=%%fillr:~0,%proc%%%
set strng2=%strng1%%spaces%
set strng3=%strng2:~0,77%

set lines=%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%
set line0=0 %%                                 50 %%                                 100 %%&rem
set line1=%chr218%%lines%%lines%%lines%%lines%%lines%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr191%
set line2=%chr179%%strng3%%chr179%
set line3=%chr192%%lines%%lines%%lines%%lines%%lines%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr196%%chr217%

cls
echo %line0%
echo %line1%
echo %line2%
echo %line3%

goto :eof


:createbinvalue
set par1=%1
type nul > t.tmp
makecab /d compress=off /d reserveperdatablocksize=26 /d reserveperfoldersize=%par1% t.tmp %par1%.chr > nul
type %par1%.chr | ( (for /l %%N in (1,1,38) do pause)>nul & findstr "^" > temp.tmp )
>nul copy /y temp.tmp /a %par1%.chr /b
del t.tmp temp.tmp
for /F "delims=" %%a in (%par1%.chr) do set "chr%par1%=%%a"
del %par1%.chr
goto :EOF
thank you! that was great and the instructions were clear

920.

Solve : Batch file to ping everyday and save in notepad?

Answer»

Hello,

Please i need to create a batch file to check whether a server is on everyday and save
the results in a notepad folder on the desktop.

Kindly assist me with this.

Thanks in advance.

Do you have any code to START with?Please no code at the moment. Quote from: Akod on September 10, 2014, 05:25:09 AM

Please no code at the moment.

ok.  Which server are you going to ping?  An internet server or a local server on the LAN?

or do you have to do this for an assignment?A local server on LAN Code: [Select]echo off
ping IPADDRESS >>"C:\path to\logfile.txt"Use Windows Task Scheduler to have it run every day at the time you WANT it to run.Please how can i make it name itself after the current date so that it will not replace each other?Please explain in better detail what you are trying to do.  Please list examples of what you want.  If you KEEP changing the parameters of what you need eventually people will not help you with your problem.The solution you GAVE saves the notepad file with the name logfile. I will prefer if it saves it with the name of the current date. This will change the name of the TEXT file with the current date.
Code: [Select]echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do SET "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%"
set "timestamp=%HH%%Min%%Sec%"
ping IPADDRESS >>"C:\path to log\%datestamp%.txt"Thanks.
921.

Solve : VBscript named pipe?

Answer»

Quick ask for a change - I want to USE VBScript to create, and write to, a named pipe in Windows 7 Professional 64 bit. All the stuff I have found on the web says that named pipe SUPPORT in VBscript is limited to treating the pipe as a text file, e.g.:

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("\\.\pipe\PipeName", True)
a.WriteLine("This is a test.")
a.Close

There are lots of variants of this I have seen but all I get is

pipetest.vbs(2, 1) Microsoft VBScript runtime error: File not found

I have tried 32 and 64 bit cscript and wscript, no difference. Any ideas? Am I missing something really basic here? Some setting I have OVERLOOKED or not thought of?





It's not part of my knowledge - is this of any use?

http://translate.google.com.au/translate?hl=en&sl=de&u=http://www.ms-office-forum.net/forum/showthread.php%3Ft%3D213124&prev=/search%3Fq%3Dnamed%2Bpipe%2Bvbs%26sa%3DG%26hl%3DenThat link was interesting. I have found I was making a newbie mistake which was I was getting the named pipe server and client back to front. The script I wrote was failing because there was nothing for it to write to, the pipe had to be created first. I found this out by getting the diagnostic tools makepipe.exe and readpipe.exe off a Microsoft SQL Server 2000 install CD and running makepipe which creates a pipe and WAITS for a message to come down it from readpipe (or my script).

922.

Solve : cos/sin 90 in vbs?

Answer»

Solved, vbs uses radians.So do most programming languages, don't they? 1 CIRCLE = 2pi radians
Pi' R round...Which is funny, since vbs doesn't have a static pi value or function.  You have to calculate it. QUOTE from: Lemonilla on September 22, 2014, 04:13:46 PM

Which is funny, since vbs doesn't have a static pi value or function.  You have to calculate it.

Dim PI
PI=ATN(1)*4
923.

Solve : Give me 10 example of batch file?

Answer»

Please help me.. GIVE me 10 examples of batch file and its function.. send me your ANSWER to my  private email [email protected] I really NEED your help in 3 days. thanks




EMail Addy removed...SORRY, we don't do homework.

924.

Solve : Help to move files based on filename - Batch Script?

Answer»

Hi Experts,

Need your urgent help to create my batch script. I am pretty NEW to batch scripting, so need your help to solve my problem.

I have .xls files in my directory with names ending with *MONYY.xls (e.g. NL_PO_Accrual_Aug14.xls)

Now, I want a batch script to check if any folder exists in same directory named "Aug14". If yes then just move all the files ending with Aug14.xls to "Aug14" else create folder "Aug14" and then move the files.

I can schedule this batch file daily to check the newly created files in the directory and move them to their respective month folders.

Please help!! (let me KNOW if you need more details)

Regards,
SimranTest this on a folder of sample files:

Code: [Select]echo off
setlocal enabledelayedexpansion
cd /d "c:\folder\xlsfiles"
for %%a in (*.xls) do (
   set "monYY=%%~na"
   set "monYY=!monYY:~-5!"
   md "!monYY!" 2>nul
   if EXIST "%%a" move "*!monYY!.xls" "!monYY!"
)
pause
Great...thanks a lot...it worked.

One more thing...just a small one

the batch file would not be placed at the directory. So, i need to do this function at some other location.

Where should I enter the path as current code you provided checks XLS files in same folder.

Please advise!!

-SimranI added one line to the code above. 
Thanks Foxidrive

You solved my problem in seconds...I do appreciateHi All,

One more small issue...i m not able to give proper path for the directories/lists

I am giving value as
cd /d "\\server123\WEB\Acc_Report\Test\rcv"

But when I run the code it says "

'\\server123\WEB\Acc_Report\Test\rcv'
CMD does not support UNC paths as current directories.

Please help!!!

THanks,
SimIt worked guys....I used pushd command instead of cd /d

Now its working

  If you just WANTED a directory list you COULD just use the DIR command with the UNC path.
Code: [Select]C:\>dir  \\server\share\folder

925.

Solve : Need to Transfer Files to External Hard Drive?

Answer»

I have a laptop running Windows 8 that won't boot.  I am trying to copy all the subdirectories under games to an external hard drive to save them.  They are all in d:\program files (x86)\games.  I can GET to the command prompt but that is all I can do.

I need the DOS command to copy all of the subdirectories to drive H, my external hard drive.  I've tried all the commands but none have worked.  Can someone help me with this issue?

Thanks.

PatWhat commands have you tried? What kind of command prompt is this?
I've tried:  d:\program files (x86)\games>robocopy games h:\
d:\program files (x86)\games>robocopy d:\program files (x86)\games h:\
plus several others but I can't seem to find the right COMBINATION to copy the entire directory of games plus the subdirectories to the external hard drive.
You do realise these games are not gonna run after being moved...correct ?Yes, I realize that they won't be playable, at least most of them but that's okay---I just want to move them to the hard drive.

OK...So can you help me with the right command to do this?
You can boot up a Linux live cdrom/usb and USE the GUI file manager to copy the folders.

If you have ACCESS to robocopy then try this: (I'm not sure how you are accessing the drive)

Code: [Select]robocopy "d:\program files (x86)\games" "h:\games-backup" /mir
Don't just use h:\ because it will wipe the rest of the h: drive too if you specify the root directory.Thanks but this command didn't work!   

I'm still working on it.

Pat

Quote from: patetc on September 21, 2014, 04:22:57 PM

Thanks but this command didn't work!   

What did it say after you entered the command?
926.

Solve : call self without passing variables?

Answer»

So I have a program that reorganizes math equations into a different format that some friends showed me.  Instead of writing 5+7 it would be written 57+.  Or instead of 1+4/2 it would be 42/1+.  It started to get a little complicated when (1+4)/(4+6) came around, which should be 14+46+/.  To handle the parenthesis I am trying to call a new instance of my batch file with the operation withing the parenthesis to store in that space.  The script I have below stores each character in a different slot in a psudoarray, and them moves them around based on what they are and uses a second parallel array to handle order of operations.
Code: (Example of Steps) [SELECT]T:\>math 5+2/4
*** start ***
OP = 5+2/4

array1_0=5
array1_1=+
array1_2=2
array1_3=/
array1_4=4
array2_0=0
array2_1=2
array2_2=0
array2_3=1
array2_4=0
array2_5=0


array1_0=5
array1_1=+
array1_4=24/
array2_0=0
array2_1=2
array2_2=0
array2_3=1
array2_4=0
array2_5=0


array1_0=5
array1_1=+
array1_4=24/
array2_0=0
array2_1=1
array2_2=0
array2_3=0
array2_4=0
array2_5=0


array1_4=524/+
array2_0=0
array2_1=1
array2_2=0
array2_3=0
array2_4=0
array2_5=0


array1_4=524/+
array2_0=0
array2_1=0
array2_2=0
array2_3=0
array2_4=0
array2_5=0


array1_4=524/+
array2_0=0
array2_1=0
array2_2=0
array2_3=0
array2_4=0
array2_5=0

524/+

The problem I think I'm running into is that when I call a new instance of the program to convert 1+4 to 14+, it is passing the FULL array in as well.  How would I go about stopping this?  My code is below. :open is the function that does the calling.  There are currently some debug commands thrown in to show the CHANGE in my arrays.  They will be removed.
Code: (math.bat) [Select]echo off
setlocal EnableDelayedExpansion
setlocal
set op=%~1
set a=-1
set "self=%~pdnx0"


echo *** start ***
echo op = %op%


REM set up array1 to contain the characters of %op%
:a
set /a a+=1
set working=!op:~%a%,1!
if not "%working%"=="" (
set "array1_%a%=%working%"
goto :a )
set op_size=%a%


REM set up array2 to contain order of operations starting from 1
REM a value of 0 signifies no operation to run, but a digit to MOVE
set b=-1
set count=1
:b
set /a b+=1
if not defined array1_%b% set array2_%b%=

set z=%b%
set tocall=
if "!array1_%b%:~0,1!"=="(" call :open
set b=%z%


if "!array1_%b%:~0,1!"=="/" (
set array2_%b%=%count%
set /a count+=1
)
if "!array1_%b%:~0,1!"=="*" (
set array2_%b%=%count%
set /a count+=1
)
if not "%b%"=="%op_size%" goto :b
set b=-1
:c
set /a b+=1
if "!array1_%b%:~0,1!"=="+" (
set array2_%b%=%count%
set /a count+=1
)
if "!array1_%b%:~0,1!"=="-" (
set array2_%b%=%count%
set /a count+=1
)
if not "%b%"=="%op_size%" goto :c
set b=-1
:d
set /a b+=1
if "!array2_%b%!"=="" set array2_%b%=0
if not "%b%"=="%op_size%" goto :d
set a=
set b=

echo.
set array
echo.

REM locate operations before and after first operation
:locate
set loc=0
set a=-1
set last=-1
set next=
:e
set /a a+=1
if not "!array2_%a%!"=="0" (
if not "!array2_%a%!"=="1" (
if "%loc%"=="0" set last=%a%
if "%loc%"=="1" (
set next=%a%
goto :combine
)
)
)
if "!array2_%a%!"=="1" set loc=1
if not "%a%"=="%op_size%" goto :e
set next=%a%
goto :combine

:combine
set working=
set /a next=%next%-1
:f
set /a last=%last%+1
if not "!array2_%last%!"=="1" (
set "working=%working%!array1_%last%!"
set "array1_%last%="
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
if not "%last%"=="%next%" goto :f
set "working=%working%%store%"
set "array1_%next%=%working%"

echo.
set array
echo.

REM Check if done
set g=0
for /f "tokens=2 delims==" %%A in ('set array2') do if not "%%A"=="0" set g=1
set a=0
set z=
set b=-1
set count=1
set next=
set last=
set working=
set store=
if "%g%"=="1" goto :b



REM Echo Output and exit
set output=
set a=-1
:out
set /a out+=1
if defined array1_%out% (
set output=!array1_%out%!
goto :end
)
goto :out
:end
echo %output%
goto :exit






:open
set "array1_%z%="
set /a z+=1



if not "!array1_%z%:~0,1!"==")" (
set "tocall=%tocall%!array1_%z%!"
set "array1_%z%="
set "array2_%z%=:
goto :open
)
echo :open %tocall%
set "array1_%z%="

for /f "delims=" %%A in ('call %self% %tocall%') do set array1_%z%=%%A
echo !array1_%z%!
goto :eof


:exit

EDIT: I know the system is somewhat stupid, but I'm doing it as more a challenge than to produce anything useful.If it helps, the script stalls on the for command in :open, but only if there are two or more  ( characters.I found a work around if anyone is interested.

Code: [Select]echo off
setlocal EnableDelayedExpansion
if not "%~2"=="" setlocal
set op=%~1
set a=-1
set "self=%~pdnx0"
for /f "tokens=1 delims==" %%A in ('set array 2^>nul') do set "%%A="


REM set up array1 to contain the characters of %op%
:a
set /a a+=1
set working=!op:~%a%,1!
if not "%working%"=="" (
set "array1_%a%=%working%"
goto :a )
set op_size=%a%



REM set up array2 to contain order of operations starting from 1
REM a value of 0 signifies no operation to run, but a digit to move
set b=-1
set count=1
:b
set /a b+=1
if not defined array1_%b% set array2_%b%=

if "!array1_%b%:~0,1!"=="(" call :open

if "!array1_%b%:~0,1!"=="/" (
set array2_%b%=%count%
set /a count+=1
)
if "!array1_%b%:~0,1!"=="*" (
set array2_%b%=%count%
set /a count+=1
)
if not "%b%"=="%op_size%" goto :b
set b=-1
:c
set /a b+=1
if "!array1_%b%:~0,1!"=="+" (
set array2_%b%=%count%
set /a count+=1
)
if "!array1_%b%:~0,1!"=="-" (
set array2_%b%=%count%
set /a count+=1
)
if not "%b%"=="%op_size%" goto :c
set b=-1
:d
set /a b+=1
if "!array2_%b%!"=="" set array2_%b%=0
if not "%b%"=="%op_size%" goto :d
set a=
set b=


REM locate operations before and after first operation
:locate
set loc=0
set a=-1
set last=-1
set next=
:e
set /a a+=1
if not "!array2_%a%!"=="0" (
if not "!array2_%a%!"=="1" (
if "%loc%"=="0" set last=%a%
if "%loc%"=="1" (
set next=%a%
goto :combine
)
)
)
if "!array2_%a%!"=="1" set loc=1
if not "%a%"=="%op_size%" goto :e
set next=%a%
goto :combine

:combine
set working=
set /a next=%next%-1
:f
set /a last=%last%+1
if not "!array2_%last%!"=="1" (
set "working=%working%!array1_%last%!"
set "array1_%last%="
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
if not "%last%"=="%next%" goto :f
set "working=%working%%store%"
set "array1_%next%=%working%"


REM Check if done
set g=0
for /f "tokens=2 delims==" %%A in ('set array2') do if not "%%A"=="0" set g=1
set a=0
set z=
set b=-1
set count=1
set next=
set last=
set working=
set store=
if "%g%"=="1" goto :b



REM Echo Output and exit
set output=
set a=-1
:out
set /a out+=1
if defined array1_%out% (
set output=!array1_%out%!
goto :end
)
goto :out
:end
echo %output%
endlocal
goto :exit





REM comine equations in paranthisis and convert them
:open

set last=%b%
set o=%b%
set "array1_%o%="
:op
set /a o+=1
if not "!array1_%o%!"==")" goto :op
set next=%o%

set working=
set /a next=%next%-1
:f2
set /a last=%last%+1
if not "!array1_%last%!"=="+" (
if not "!array1_%last%!"=="/" (
if not "!array1_%last%!"=="*" (
if not "!array1_%last%!"=="-" (
set "working=%working%!array1_%last%!"
set "array1_%last%="
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
) else (
set "store=!array1_%last%!"
set "array1_%last%="
)
if not "%last%"=="%next%" goto :f2
set "working=%working%%store%"
set "array1_%next%=%working%"
set /a next+=1
set "array1_%next%="

goto :eof




:exit

927.

Solve : deshabilitate my net adapters or habilitate.?

Answer»

deshabilitate my net adapters or habilitate.
I would LIKE with a bat or similar be able to habilitate the net adapters or inhabilitate them.

How can i do this exactly  ?

Best Regards
This is what I came across with a google search. I have never used netsh before, so you'll have to wait for someone else to post if you are hesitent.
Code: [Select]netsh interface set interface name="Local Area Connection" disable

netsh interface set interface name="Local Area Connection" enable

source: http://www.sevenforums.com/network-sharing/306896-how-turn-wifi-adapter-command-line-how-turn-hotspot.html
I have tried in many ways.
Perhaps I don't take the real name of the process.
Until this moment I only could deshabilite the virtualbox adapter.

I am from Spain.

My bat :

Code: [Select]rem netsh interface set interface name="Local Area Connection" disable
rem netsh interface set interface name="Local Area Connection" enable
rem Conexión de red inalámbrica
rem Conexión de área local
rem VirtualBox Host-Only Network
netsh interface set interface name="VirtualBox Host-Only Network" disable
netsh interface set interface name="Atheros AR5B93 Wireless Network Adapter" disable
rem encontré buscando en el registro
rem HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{F82F9A1B-61B5-4612-ACB6-2B5F595ED213}\Connection
rem Conexión de área local* 3
netsh interface set interface name="Conexión de área local* 3" disable
rem no deshabilitó la 3
netsh interface set interface name="Conexión de área local* 1" disable
rem tampoco
rem pruebo con Conexión de área local, que ya se que no funciona
rem qué puedo hacer : pues meter todas las de la clave en el registro
rem HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network
rem vamos con todas
netsh interface set interface name="Conexión de área local" disable
netsh interface set interface name="Conexión de área local* 8" disable
netsh interface set interface name="Conexión de red inalámbrica 3" disable
netsh interface set interface name="Conexión de área local* 1" disable
netsh interface set interface name="Conexión de área local* 14" disable
netsh interface set interface name="Conexión de área local* 7" disable
netsh interface set interface name="Conexión de área local*" disable
netsh interface set interface name="Conexión de área local* 10" disable
netsh interface set interface name="Conexión de área local* 2" disable
netsh interface set interface name="Conexión de área local* 13" disable
netsh interface set interface name="Conexión de red inalámbrica" disable
netsh interface set interface name="Conexión de área local* 5" disable
netsh interface set interface name="Conexión de área local* 12" disable
netsh interface set interface name="Conexión de área local* 6" disable
netsh interface set interface name="Conexión de área local* 4" disable
netsh interface set interface name="Conexión de red inalámbrica 2" disable
netsh interface set interface name="Teredo Tunneling Pseudo-Interface" disable
netsh interface set interface name="Conexión de área local* 9" disable
netsh interface set interface name="Conexión de área local* 11" disable
netsh interface set interface name="Conexión de área local* 3" disable
rem Teredo Tunneling Pseudo-Interface
rem Adaptador de tunelización Teredo de Microsoft
rem Atheros AR5B93 Wireless Network Adapter
rem no existe una interfaz con este nombre con el enrutador
rem claves que contienen una entrada al nombre correcto del virtualbox
rem HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network
rem HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Network
rem HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network
rem HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network
rem netsh interface set interface name="Broadcom NetLink (TM) Gigabit Ethernet" disable
rem no funciona : netsh interface set interface name="Conexión de área local" disable
rem no funciona : netsh interface set interface name="Conexión de red inalámbrica" disable
rem SOLAMENTE se desactivó la de virtualbox , el resto no y me pregunto si tienen que ver los asuntos o si se les puede dar otro nombre en anglosajón
rem creo que TIENE que ver con sus nombres reales
rem mirando en el administrador de dispositivos los obtengo
rem Atheros AR5B93 Wireless Network Adapter acer
rem Broadcom NetLink (TM) Gigabit Ethernet acer
rem vamos a probarlo

I have enter in the registry to see the keys, but no one seems goes well for me.

deshabilitate  habilitate.

Those words aren't common English.

What are you trying to do?  Do you want to disable the internet connection on a computer?

Does it connect to the internet through an ethernet network CARD?  Is there only one of these in the computer? Quote from: foxidrive on September 10, 2014, 09:04:26 AM

deshabilitate  habilitate.

Those words aren't common English.

What are you trying to do?  Do you want to disable the internet connection on a computer?

Does it connect to the internet through an ethernet network card?  Is there only one of these in the computer?

I take note is enable/disable

I have a laptop
Yes I want to disable with a bat the internet connection disabling the net adapters (wifi, lan,...)
Best Regards

Quote from: Esgrimidor on September 14, 2014, 09:33:10 AM
I have a laptop
Yes I want to disable with a bat the internet connection disabling the net adapters (wifi, lan,...)

If your laptop uses standard DHCP to connect to the modem/router then you can use this:

To disable the connections (until a reboot or by running the enable batch file)

Code: [Select]echo off
ipconfig /release

To enable the connections

Code: [Select]echo off
ipconfig /renew


It works !!!!!!!!

Wonderful Wonderful

Best Regards !
 Glad to HEAR you were able to "deshabilitate"...
928.

Solve : Browse to a folder in Android from the command line?

Answer»

Browse to a folder in Android from the command line

i try to reach the folder with the path. But don't work in windows 7-64
My device is Samsung S4 with Android

How can I go directly to a folder of my election ?

Best Regards
Then your path is wrong...find it in Win Explorer...right clik it and SELECT Properties...the path will be shown.Android devices are not mounted as drives and are not accessible from the command line, as far as I know. Is this a USB connection?LOOK at adb.exe Quote from: patio on September 24, 2014, 08:30:12 AM

Then your path is wrong...find it in Win Explorer...right clik it and select Properties...the path will be shown.

I continue INVESTIGATING. Seems necessary to root the device and adb.exe as shown above.
But I RECEIVED information about the possibility to use Dropbox in the windows environment and in google environment.....
I'll try and comment.
929.

Solve : MS DOS edit function?

Answer»

Hello there!

Sorry if this thread is ALREADY POSTED (I couldn't find any related ONES). I am still learning the basics of command prompt.

Just would like to ask, I have been TRYING out this command prompt command which is to create or EDIT a file using 'edit'. I have look at many sources on the net, which all mention : just type in ie h:\>edit hello.txt. But when I try it out on my pc, it mentions that 'edit' is not recognized as an internal or external command, operable program or batch file.

By the way, I am using Windows 7 OS.

Does anyone have any idea about this problem? Thanks!!  The edit text editor is not available in 64 bit Windows.Means that I have to use another way instead of edit to create file?

Btw, thanks for replying! You can use notepad to create a file.

Explain further if that isn't what you need to do.

930.

Solve : Batch File Issue?

Answer»

How do we include supporting FILES in batch file. Suppose i have created batch file and i need some files like .exe files and pictures to be included in it and if i created exe of batch i should get an option to include all the supporting files to make the batch file a complete set . So if user downloads the batch file then even the supporting files should go with it.

Secondly suppose i have downloaded the batch file in the system anywhere and i want batch file should automatically take up the path where i have downloaded the file. How do we get that.

Please help me guys i am STUCKED very badly. Holy RED Batman!  That is super annoying.

If you want to publish this for other people to download and use, why don't you just put all the files in a ZIP file or a SELF extracting zip file.

In regards to your second QUESTION.  The path to where the batch file is this variable.
Code: [Select]%~dp0 Quote from: aakashraj47 on September 24, 2014, 01:06:39 AM

How do we include supporting files in batch file.

Encoding the binaries into the batch script is one option.

Quote
i want batch file should automatically take up the path where i have downloaded the file.

Can you explain what you mean by that?


Quote
Secondly suppose i have downloaded the batch file in the system anywhere and i want batch file should automatically take up the path where i have downloaded the file. How do we get that.

Batch automatically makes the current directory that of the batch file as it is run.  If you want reference that in your code, you can have a 'set home=%cd%' command at the beginning, or you can use '%~pd0' if you don't use the 'shift' command in your script. Quote from: Lemonilla on September 24, 2014, 08:40:34 AM
Batch automatically makes the current directory that of the batch file as it is run.

It does, except if you elevate PERMISSIONS when the c:\windows\system32 folder becomes the working directory.General Reference for BAT files:
Information on batch files  (CH)
931.

Solve : Unauthorized icon/smiley in my post?

Answer»

Hey, what gives?!
There is an unauthorized ACTION figure in my post earlier today where I SAY "I ALSO tried using ..."



Thats because certain CHARACTER keys enable smileys...
For example 8  ) enables this:...

I have no idea how you invoked a dancin banana HOWEVER...it is an open parentheses followed by a pipe. (| turns into

In the "attachments and other options" section, you can check off "Don't use smileys" to prevent smileys from being inserted where matching text is found.

932.

Solve : luanch of executable from within .bat file fails?

Answer»

I am trying to get started with Google's Android Studio. I have installed the studio software and the Android SDK on my d:\ drive, as follows...

d:\dev\android\android-studio
d:\dev\android\sdk

In the SDK, there is a .bat file, android.bat, that in turn calls another .bat file, find_java.bat.

When I run android.bat, it fails to launch the second file...

d:\dev\android\sdk\tools>android
'"d:\dev\android\sdk\tools\lib\\find_java.bat" -s' is not recognized as an internal or external command,
operable program or batch file.

The following command entered on the command line does in fact run the find_java.bat file...

d:\dev\android\sdk\tools\lib\\find_java.bat -s

...but the find_java.bat file cannot be found from within the android.bat file.

I have sought help from Google, and the engineer assigned to the problem reports that when he runs android.bat on his machine, it works fine.

Any suggestions as to why the same .bat file works on the Google machine and not on mine?

The Google OS is Windows 7 Home Premium x64, mine is Windows 7 Ultimate x64.

Thanks.

JerryWell, the two commands are not the same.
Please copy and paste the command so we can see it.

The -s must come right after the find command.
Would probably help to see the contents of each batch file.Sorry if I was not precise in my initial description of the problem. I was trying to keep my discussion brief.  But it's a complicated situation that, I guess, requires more verbiage.

When I install the Android SDK, the installer offers to run the SDK Manager at the conclusion of the installation.  I say yes, and I get the following error message...

Failed to execute tools\android.bat:
The system cannot find the file specified.

But I have already set an Environment Variable, ANDROID_SDK_HOME, to d:\dev\android\sdk and added that variable to my PATH, so I expect there to be no problem reaching tools\android.bat from anywhere on the system. 

When I open a command window and cd to the SDK directory and run android.bat manually, I get this...

D:\dev\android\sdk\tools>android
'"D:\dev\android\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command,
operable program or batch file.

There is now a problem running another file, find_java.exe, in the tools\lib folder. 

Actually, android.bat runs lib\find_java.bat, which in turn attempts, and fails, to run find_java.exe, with this command...

for /f "DELIMS=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a

And yet, if I go to the tools directory in a command window and enter that exact same command that just failed, it does in fact run...

D:\dev\android\sdk\tools>lib\find_java.exe -s
C:\PROGRA~3\Oracle\Java\javapath\java.exe
D:\dev\android\sdk\tools>

(And yes, I have tried it with and without the double quotes, and with and without the double slash in the path. Nothing works.)

The batch files, BTW, appear to be correct, with no broken syntax.  These files do run on other systems.  In fact, as a test, I installed the SDK on my wife's machine and the batch files all work fine.  The difference:  My machine, where they don't work, runs Windows 7 Ultimate, my wife's machine runs Windows 7 Home Professional.  (And no, using my wife's machine for Android development is not an option. I need to make it work on mine.)

Thanks.

Jerry
Quote from: Jerry Ford on November 24, 2014, 05:59:11 PM

I get the following error message...

Failed to execute tools\android.bat:
The system cannot find the file specified.

The message shows a relative path is being used.


foxidrive:

Yes, a relative path.  That particular error message is displayed when SDK Manager.exe runs. That .exe is in the sdk folder, android .bat is in the sdk\tools folder, so the .bat file is in the tools folder relative to the exe.

But it makes no difference how I initiate the process, SOMETHING is preventing the android tools from traversing the Windows path. 

Again, these files do all work on some systems.  I'm pretty sure it is not a coding error in the various .exe/.bat files. My current best guess is there is a permission conflict.  I just don't know what permissions, where to find them, and how to fix the problem.  I've looked at the security settings in various Windows peroperty dialogs for the files and folders, nothing works. 

Except it does work, on other people's Windows machines.  Just not on mine.Do you get a UAC prompt when running the installer?

What are the user account control settings for the computers that it works on and your computer?From the Android Developer Website.
Quote
On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.
Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.7.0_21.
squashman:

JAVA_HOME has been set on my system for a long time prior to trying to use Android, and it remains pointed at a valid JDK.

Jerrysquashman:

If I run the installer as administrator, I get the prompt.  If not, no prompt. Either way, makes no difference, files still don't run correctly.

User account control properties are the same on both computers (mine, Windows 7 Ultimate, where the SDK files don't work, and my wife's, Windows 7 Home Pro, where the SDK files do work)...

Default - Notify me only when programs try to make changes to my computer.

Something I had not noticed before, but in the SDK installer .exe's properties dialog, there is this message at the bottom...

Security - This file came from another comptuer and might be clocked to help protect the computer.

When I click the [ Unblock ] button, the text goes grey (and is not shown on subsequent openings of the properties dialog), but it makes no difference, the EXECUTABLES still do not work correctly.
Quote from: Jerry Ford on November 24, 2014, 05:59:11 PM
The batch files, BTW, appear to be correct, with no broken syntax.

Your question is sorta like saying:  "I wrote some source code and it doesn't work - can you tell me what's wrong with it?" and you don't show anyone the source code.

Code: [Select]for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
On a casual examination, the code above will only work if the find_java.exe is in the same folder as the batch file. Quote from: Squashman on November 21, 2014, 10:10:16 PM
Would probably help to see the contents of each batch file.

This says it all...Okay, here are the two files where it starts. There are more, but I can't copy the whole SDK.  It is a free download though, if you really want to purse all files INVOLVED. Get it here (you'll need to create an account, but,again, free)...

https://developer.android.com/sdk/index.html?hl=i

The SDK comes in an executable installer.  When I run it (with or without administrative privileges, doesn't seem to matter, and it worked fine without on the Win7 Home machine where the SDK works), the last panel in the installer asks if I want to start the SDK Manager, which is to say run the file SDK Manager.exe that is located in the SDK top level folder.  When I do, I get the error message Failed to execute  tools\android.bat:, error 2 The system cannot find the file specified.

When I open a command window and cd to the SDK tools folder, I run android.bat from the command line and get the error message

'"D:\dev\android\sdk\tools\lib\\find_java.exe" -s' is not recognized as an internal or external command,
operable program or batch file.

The executable find_java.exe, which the message references, is actually called from within find_java.bat, both of which are in the tools\lib folder.

Here's android.bat (in the SDK's tools folder), followed by find_java.bat...

echo off
rem Copyright (C) 2007 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem      http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem Useful links:
rem Command-line reference:
rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

rem don't modify the caller's environment
setlocal

rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0

rem Grab current directory before we change it
set work_dir=%cd%

rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0


rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF

set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar

rem Set SWT.Jar path based on current architecture (x86 or x86_64)
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a

:MkTempCopy
    rem Copy android.bat and its required libs to a temp dir.
    rem This avoids locking the tool dir in case the user is trying to update it.

    set tmp_dir=%TEMP%\temp-android-tool
    xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul
    copy /B /D /Y lib\common.jar         %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\commons-codec*     %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\commons-compress*  %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\commons-logging*   %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\dvlib.jar          %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\guava*             %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\httpclient*        %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\httpcore*          %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\httpmime*          %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\layoutlib-api.jar  %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\org-eclipse-*      %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\sdk*               %tmp_dir%\lib\        > nul
    copy /B /D /Y lib\swtmenubar.jar     %tmp_dir%\lib\        > nul

    rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
    set tools_dir=%cd%
    cd /d %tmp_dir%

:EndTempCopy

rem The global ANDROID_SWT always OVERRIDE the SWT.Jar path
if defined ANDROID_SWT set swt_path=%ANDROID_SWT%

if exist "%swt_path%" goto SetPath
    echo ERROR: SWT folder '%swt_path%' does not exist.
    echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
    goto :EOF

:SetPath
rem Finally exec the java program and end here.
REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
call "%java_exe% %REMOTE_DEBUG%" "-Dcom.android.sdkmanager.toolsdir=%tools_dir%" "-Dcom.android.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*

rem EOF


Here's find_java.bat...

echo off
rem Copyright (C) 2007 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem      http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem This script is called by the other batch files to find a suitable Java.exe
rem to use. The script changes the "java_exe" env variable. The variable
rem is left unset if Java.exe was not found.

rem Useful links:
rem Command-line reference:
rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

rem Check we have a valid Java.exe in the path. The return code will
rem be 0 if the command worked or 1 if the exec failed (program not found).
for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
if not defined java_exe goto :CheckFailed

:SearchJavaW
rem Check if we can find a javaw.exe at the same location than java.exe.
rem If that doesn't work, just fall back on the java.exe we just found.
for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s -w') do set javaw_exe=%%a
if not exist "%javaw_exe%" set javaw_exe=%java_exe%
goto :EOF


:CheckFailed
echo.
echo ERROR: No suitable Java found. In order to properly use the Android Developer
echo Tools, you need a suitable version of Java JDK installed on your system.
echo We recommend that you install the JDK version of JavaSE, available here:
echo   http://www.oracle.com/technetwork/java/javase/downloads
echo.
echo If you already have Java installed, you can define the JAVA_HOME environment
echo variable in Control Panel / System / Avanced System Settings to point to the
echo JDK folder.
echo.
echo You can find the complete Android SDK requirements here:
echo   http://developer.android.com/sdk/requirements.html
echo.
goto :EOF
Try changing this line:
for /f "delims=" %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
to this:
for /f "delims=" %%a in ('"%~dps0find_java.exe" -s') do set java_exe=%%a


Also check that path to make sure that find_java.exe actually exists.Lemonilla:

The change you suggest replaces the double backslash with a single backslash in the path to find_java.exe, so  D:\dev\android\sdk\tools\lib\\find_java.exe becomes D:\dev\android\sdk\tools\lib\find_java.exe but either one works as a valid Windows path.  And yes, find_java.exe does exist at that location, and when I run it from the command line it returns a valid path...

D:\dev\android\sdk\tools>lib\find_java.exe
C:\ProgramData\Oracle\Java\javapath\java.exe
D:\dev\android\sdk\tools>

...which does point to the java executable in my JDK...

D:\dev\android\sdk\tools>C:\ProgramData\Oracle\Java\javapath\java.exe -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

But attempts to run the Android SDK Manager or andriod.bat still fail.

933.

Solve : Problem w/ Escape "^": cmd-line vs. batch?

Answer»

The SET command works at the interactive command line as I would like, but does not work the same when executed from TEST.BAT (see attached).

How should I CHANGE the contents of TEST.BAT to obtain the same results as the command-line version?

[attachment deleted by admin to conserve SPACE]In a batch file you need to double up the percent symbols if you need to escape them.  The carrot will not do that for percent symbols.You can copy and paste from a CMD window - RIGHT click the title bar and see the Edit menu.

Is this what you need?

Code: [Select]ECHO off
set "variable=%%word%%"
echo "%variable%"
pauseDo you need the information in the file?
And do you prefer cmd or batch?

934.

Solve : How do you display the Syntax in DOS??

Answer»

1.) Display the syntax of the FIND command.
a. What command did you USE to display the FIND command’s syntax?
b. What is the PURPOSE of this command?
c. What parameters in the command are required?
d. What parameters in the command are optional?From Our Archives...The Internet is such a good way to AVOID learning anything in school these days.

So MANY people post homework in FORUMS...Yep...........

935.

Solve : batch for copy and rename?

Answer»

Ok one mroe last thing I need is to find all LogFile.txt from all subfolders and copy it in one folder and add a folder name to file name.
For example.
I have folders

d:\backup\log\Mike\act\LogFile.txt
d:\backup\log\George\act\LogFile.txt
d:\backup\log\John\act\LogFile.txt
d:\backup\log\Suzy\act\LogFile.txt


And now batch will copy all those renamed LogFile.txt to
d:\backup\AllAct\MikeLogFile.txt
d:\backup\AllAct\GeorgeLogFile.txt
d:\backup\AllAct\JohnLogFile.txt
d:\backup\AllAct\SuzyLogFile.txtTest this:

Code: [Select]echo off
md "d:\backup\AllAct\" 2>nul
for /f "delims=" %%a in ('dir /a-d /b /s "d:\backup\log\*.txt" ') do (
for /f "delims=" %%b in ("%%~dpa\.") do copy "%%a" "d:\backup\AllAct\%%~nxb%%~xa"
)
pauseI tried this but it makes one file and fills up that file with all log files.
I have also log files in

d:\backup\log\Mike\LogFile.txt
d:\backup\log\George\act\LogFile.txt
d:\backup\log\John\LogFile.txt
d:\backup\log\Suzy\LogFile.txt

whic are the same name so it must be only LogFile.txt from this folder, it is subfolder (act) of Users Folder
d:\backup\log\Mike\act\LogFile.txt
d:\backup\log\George\act\LogFile.txt
d:\backup\log\John\act\LogFile.txt
d:\backup\log\Suzy\act\LogFile.txt

I can make that file won't be the same to rename it when it is copied to act subfolder by adding some extra charters if that makes easier?I see why my suggestion doesn't work - I missed seeing the \act\ part.

Test this: it expects a single log file in each \act\ folder under each user folder.

Code: [Select]echo off
cd /d "d:\backup\log"
for /d  %%a in (*) do for %%b in ("%%a\act\*.log") do copy "%%b" "d:\backup\AllAct\%%a.log"

nothing happends
Change .log in TWO places to .txt

foxydrive gave you a complete solution. Save this code as a batch file, and run it in the root directory of drive D:\ (assuming that the "backup" directory is there).

I just added "LogFile" to the code as you WANTED it to look like.

Code: [Select]echo off
cd /d "d:\backup\log"
for /d  %%a in (*) do for %%b in ("%%a\act\*.txt") do copy "%%b" "d:\backup\AllAct\%%aLogFile.txt"yes, thanks, I didn't see that log and txt. I changed that too, but still nowthing happendsbump
this unfortunally not working Code: [Select]echo off
for %%a in (
d:\backup\log\Mike\act\LogFile.txt
d:\backup\log\George\act\LogFile.txt
d:\backup\log\John\act\LogFile.txt
d:\backup\log\Suzy\act\LogFile.txt
) do md "%%~dpa" 2>nul &break>"%%a"
md "d:\backup\AllAct\" 2>nul

echo off
cd /d "d:\backup\log"
for /d %%a in (*) do for %%b in ("%%a\act\*.txt") do copy "%%b" "d:\backup\AllAct\%%a%%~nb.txt"
pause
Sorry this won't work, because I have added users and will add some more users.
With fixed folders or paths I can do with robocopy QUOTE from: Blisk on September 02, 2014, 05:10:33 AM

Sorry this won't work, because I have added users and will add some more users.
With fixed folders or paths I can do with robocopy

It solves the question as you asked it, with the details you provided.
The code above the second echo off simply CREATES some files where you said they were so that it can show you that the code works.

More users isn't a problem, and it doesn't use fixed folders in the way you obviously think it does.

So I don't need to change batch file everytime I add a user folder?
936.

Solve : How to format windows 7 without installing a new version on my pc?

Answer»

Hello to EVERYONE. I INSTALLED windows 7 on my PC. I want to know how can I delete windows 7 WITHOUT installing a new version. I would like to delete everything so when you turn on the computer you can't do anything other than be at the beggining. As if you buy a computer without windows on it. I hope I was clear of what I would like. Thanks for the help. So basically you just want to format the hard drive so nothing is on it?Yes.why?Boot up a cdrom or USB with LIVE Ubuntu or other version of Live Linux and use the GUI file manager to delete all files on the HDD.

Or run DBAN from a cdrom or DVD or USB to nuke every drive on the machine.

Quote

why?

It could be a malicious TASK but it's pretty easy to find a way to do it in google.
937.

Solve : Check if a process exists. If don't exist execute?

Answer»

Check if a process exists. If don't exist execute

I would like a script to launch several processes in the case of any of them is not running.

By example :

notepad.exe
controlQ.ahk
etc.

Best Regards
tasklist | find "notepad.exe" >nul
if "%ERRORLEVEL%"=="1" notepad.exe


This does not work for batch files or other scripts. Quote from: Lemonilla on September 23, 2014, 09:43:38 AM

tasklist | find "notepad.exe" >nul
if "%errorlevel%"=="1" notepad.exe


This does not work for batch files or other scripts.

And something THA may help with bat files or other scripts ?
Best Regards
You cannot.  They appear on the system as instances of cmd.exe.How can i automate then to see is a process is running or not with a script. And if is not running, run it.

Best Regards
Quote from: Lemonilla on September 23, 2014, 09:43:38 AM
tasklist | find "notepad.exe" >nul
if "%errorlevel%"=="1" notepad.exe


This does not work for batch files or other scripts.
I use this
Code: [Select]tasklist /fi "Imagename eq link.exe" 2>NUL | find /i /n "link.exe">NUL
if "%ERRORLEVEL%"=="1" (goto D) else (goto B)
first make a batch file than convert it to exe so I named it link.exe
you must be carefull how you name it because some antivirus software can make you a trouble.

to CONVERTING to exe I use "bat to exe CONVERTER" Quote from: Blisk on September 29, 2014, 01:21:04 AM
first make a batch file than convert it to exe so I named it link.exe
you must be carefull how you name it because some antivirus software can make you a trouble.

to converting to exe I use "bat to exe converter"
Why do you even mention this?  It has nothing to do with the original question.  Nor does it help the OP solve their problem.
938.

Solve : Batch file to Sort and Move specific files by identifying a word inside the file?

Answer»

Hi All...
I will explain what I need in as much detail as possible.
I need a batch file to MOVE specific files into a SEPARATE folder,possibly by opening my hex editor,searching for the WORD "body" ( without the quotes ) and if found ,close hex editor,move file to a folder CALLED "moved" ,then go on to the next one.If the word "body" is not found just close hex editor and ignore the file.
I have approx 900 files in a folder.One is a vehicle and one is a map for a game.They are mixed together and the only way of telling them apart is by opening each one with my hex editor and search for the word "body",which means it is a vehicle.If the "body" word is not found,it is a map.Example wording of the files: mapname.idf carname.idf
Manually this process would take HOURS,even days.
It would be a lot better if there is a way of doing this without using the hex editor/batch idea.
Here is a link to one map and one vehicle file if needed for an example:
http://vnovak.com/1nsane/2idf-files.zip
Thanks a bunch for your help! 
ValAnswers here:

http://www.dostips.com/forum/viewtopic.php?f=3&t=5950

939.

Solve : Batch script to remove email user names?

Answer»

I am stuck on what should be a simple script.

I want to remove the username and from a list of EMAILS from a txt file and put the domain names in another file

EX -
emails.txt
[email protected]
[email protected]
[email protected]

put the domain names in an existing txt file >> domains.txt

mail1.com
mail2.com
bar.com
foo.com
panic.com Quote

OS: Linux variant


What OS are you using?
DOH! Just noticed that.  This is for a Win 7 machine.
I already have a Linux Shell script that does the same thingTry this:

Code: [Select]echo off
setlocal enabledelayedexpansion

(for /f "usebackq delims=" %%a in ("emails.txt") do (
   set "var=%%a"
   echo(!var:*=!
))>>"domains.txt"
PAUSE
Foxidrive,
Why didn't you just use the as a delimiter?
Code: [Select]for /f "usebackq tokens=2 [email protected]" %%G in ("emails.txt") do echo %%G >>domains.txt Quote from: foxidrive on SEPTEMBER 29, 2014, 10:47:38 PM
Try this:

Code: [Select]echo off
setlocal enabledelayedexpansion

(for /f "usebackq delims=" %%a in ("emails.txt") do (
   set "var=%%a"
   echo(!var:*=!
))>>"domains.txt"
pause


Thank You!!! Quote from: Squashman on September 30, 2014, 07:35:18 AM
Foxidrive,
Why didn't you just use the as a delimiter?

I must be getting old - it didn't occur to me.

       Quote from: foxidrive on September 30, 2014, 08:44:27 AM
I must be getting old - it didn't occur to me.
It sucks getting old. Some days I walk into the KITCHEN and don't even remember why I went to the kitchen.When i bent over to TIE my shoes this AM i thought to myself..."what else can i do now i'm down here" ? ?Well at least I don't have trouble with my 1's and 2's.

I have a solid leak every morning at 7am, and a full bowel motion every day at 7:30 am.

Pity I don't get out of bed until 8am...
940.

Solve : Choice help?

Answer»

A few weeks ago I was asked to make an adventure game in batch, of all THINGS, for a game competition. That will be all saved locally and then once the competition is over I will send it to the judges to judge how well they play and then they will be score and that it. So I started but I had some problems and was wandering if you guys could help.

My first problem is that I would like to have a grid but I cant figure out how to make it move. I am running a windows xp which I know doesn't have choice.com or choice.exe. I would prefer not for them having to click enter every time.

My SECOND problem is that I didn't know if you could save your game with the "set
My third and final problem, hopefully is that I don't know how to set up it up to where you have to enter a password to load a save file, delete a save file (in and out of game) ,and to make a file and if they get it wrong they can't go in the code and hack into someone's game.
I still have 6 months before it starts so I would like to have a grid and the password, save, create, and delete a file by 2 months in...
Any help is appreciated.
ThanksWell, without choice it could be difficult.  I have seen it DONE, but still don't understand how it works.  It uses 'start /b' to run a controller that writes to a files, which is always being read for input, but that's as far as I could get.  Here is a link.
I would recommend getting a copy of choice.exe and putting it in the folder with your batch.  If you are moving between folders while the game runs, run this command at the beginning to add choice 'set path=%path%;%~pd0 '.  Don't forget to add %~pd0 to path, not override it or you will get some really ugly bugs.

To save your game to a text file, I would use these sets of commands (without having seen the code I cannot give you the optimized method.  This may not work depending on how you are structuring your game).
Code: (To Save Game) [Select]set >save1.txt
Code: (To Load Game) [Select]for /f "delims=" %%A in (save1.txt) do set %%A

All code written in batch is viewable if opened.  If you want your game 100% unhackable make a board game.  I would use a language that compiles to write the password generation and input if you really want it secure.  I think that for the arcade type of game you are talking about, a SIMPLE password will do.  Here is how I would write it.  This is the simplest (in terms of getting in) as I know, but it is also the easiest to code.
Code: (To Save) [Select]cls
echo Input Name:
set /p saveFunc_name=^>

cls
echo Input Password for %saveFunc_name%:
set /p saveFunc_pass=^>

cls
echo Saving, Please Wait. . .
echo %saveFunc_name%/%saveFunc_pass% >>saves.txt
set >save_%saveFunc_name: =_%.txt
Code: (Password Input) [Select]cls
echo Enter Username:
set /p loadFunc_name=^>

cls
echo Enter Password for %loadFunc_name%:
set /p loadFunc_pass=^>

cls
echo Loading Game, Please Wait. . .
for /f "delims=" %%A in (saves.txt) do (
if "%%A"=="%loadFunc_name%/%loadFunc_pass%" (
for /f "delims=" %%G in (save_%loadFunc_name: =_%.txt) do set %%G
) )
if not defined saveFunc_name goto :Error_noSaveDataFound

I doubt you will need a more secure save function, but if you do, ask.
*No code has been tested.Thanks for the help. The problem is that all the players have access to the computer with out the judges and I knowing. Preferable I don't want them being able to delete a different players save. The website you showed me was quite confusing. I have yet to figure out how to install a choice.exe or choice.com, mainly because I didn't look much into it. But another problem I found was they can go in and change the variables.....how can I stop that? I don't want another exe compiler, because lately they have not been the best. Thanks tho.To install choice.exe, simply place it in the same folder as the batch file that uses it (the working directory).  Or you can add the pathway to choice.exe's containing folder to the end of the %path% variable separating with a semi-colon (.  You could save all of your files as read-only, but that is changeable.  Ultimately you will sooner or later have to assume that the testers are too stupid to change the game, or are honourable enough not to.Thanks for the help, most of them aren't smart enough and they are 6 and then the teachers are GOING to play.  I ran into another problem today, I didnt know how to save a file in a different place. Like all the game parts are in a folder then in that folder are supposed the save games. I would have look it up but was going some where to watch someone play. Any help appreciated.Not sure what you mean, but to save in a different place simply change the redirect. Code: [Select]set >saves\save1.txtThis is probably a bad question how can I check if a folder exists in a the save game folder and if it not make one for that player and put their save file in it?For the sake of example, our folder we are checking is going to be called "folder1"

Code: [Select]if not exist saves\folder1 md saves\folder1
set >saves\folder1\save.txt

Folder1 can be replaced with the player's username or some such if you so desired.  Simply replace it with the variable.Don't really even have to bother wit the IF EXIST.  Just use the make directory command and redirect standard error to nul.   If it already exists it will just error out and it won't overwrite anything.
Code: [Select]md saves\folder1 2>nulIt works, I personally dont like it though.  It reminds me of:
Code: (psudojava) [Select]For (int a; a < 100; a++) {
Try {
Print(table[a]);
} catch outofboundsexeption e {
Return;
}
}
Thanks and what does that do?It prints all values in the array table in java.  Its just not a conventional way to weite it.  It forces an error and breaks after the error. Quote from: Lemonilla on September 24, 2014, 05:15:38 PM

It prints all values in the array table in java.  Its just not a conventional way to weite it.  It forces an error and breaks after the error.

it's a bit of a poor example because it is doing something completely different from what foxidrive is suggesting. The direct equivalent in Java would be:

Code: [Select]file.mkdir(sPath);



the only error that can occur that cannot occur in your version is a "directory already exists" error. Checking for existence first is redundant. in an Actual application tasks involving files should check that the file exists first, but if it is ensuring that it exists, than the item already existing is not an error.
Quote from: BC_Programmer on September 24, 2014, 06:16:24 PM
completely different from what foxidrive Squashman is suggesting.





I do agree that Squashman's code is what I'd use too. Quote from: foxidrive on September 24, 2014, 09:39:47 PM




I do agree that Squashman's code is what I'd use too.
Not sure how people confuse us.  We look nothing alike!
941.

Solve : log batch file?

Answer»

how to log this batch file in one single logfile.txt
I know I can do like this
del /S /Q *.jpg>logfile.txt

but than I GET multiple logs, I need just one for batch belov
Code: [Select]del /S /Q *.gif
del /S /Q *.jpeg
del /S /Q *.tiff
del /S /Q *.gif
del /S /Q *.png
del /S /Q *.bmp
del /S /Q *.jpg
del /S /Q *.tga
del /S /Q *.pcx
del /S /Q *.img

del /S /Q *.avi
del /S /Q *.mov
del /S /Q *.mpeg
del /S /Q *.mpg
del /S /Q *.mpe
del /S /Q *.mpa
del /S /Q *.qt
del /S /Q *.asf
del /S /Q *.asx
del /S /Q *.wmv
del /S /Q *.wma
del /S /Q *.wmx
del /S /Q *.rm
del /S /Q *.ra
del /S /Q *.ram
del /S /Q *.rmvb
del /S /Q *.mp4
del /S /Q *.3gp
del /S /Q *.3pg
del /S /Q *.ogg
del /S /Q *.mkv

del /S /Q *.wav
del /S /Q *.mp3
del /S /Q *.aiff
del /S /Q *.3gp
del /S /Q *.aac
del /S /Q *.flac
del /S /Q *.gsm
del /S /Q *.m4a
del /S /Q *.m4p
del /S /Q *.mpc
del /S /Q *.ogg
del /S /Q *.wma

del /S /Q *.swf
del /S /Q *.divx
del /S /Q *.flv
del /S /Q *.vhd
del /S /Q "Backup%Files*.zip"
This technique should work:

Code: [Select]echo off
(
del /S /Q *.gif
del /S /Q *.jpeg
del /S /Q *.tiff
del /S /Q *.gif
del /S /Q *.png
del /S /Q *.bmp
del /S /Q *.jpg
del /S /Q *.tga
del /S /Q *.pcx
del /S /Q *.img

del /S /Q *.avi
del /S /Q *.mov
del /S /Q *.mpeg
del /S /Q *.mpg
del /S /Q *.mpe
del /S /Q *.mpa
del /S /Q *.qt
del /S /Q *.asf
del /S /Q *.asx
del /S /Q *.wmv
del /S /Q *.wma
del /S /Q *.wmx
del /S /Q *.rm
del /S /Q *.ra
del /S /Q *.ram
del /S /Q *.rmvb
del /S /Q *.mp4
del /S /Q *.3gp
del /S /Q *.3pg
del /S /Q *.ogg
del /S /Q *.mkv

del /S /Q *.wav
del /S /Q *.mp3
del /S /Q *.aiff
del /S /Q *.3gp
del /S /Q *.aac
del /S /Q *.flac
del /S /Q *.gsm
del /S /Q *.m4a
del /S /Q *.m4p
del /S /Q *.mpc
del /S /Q *.ogg
del /S /Q *.wma

del /S /Q *.swf
del /S /Q *.divx
del /S /Q *.flv
del /S /Q *.vhd
del /S /Q "Backup%Files*.zip"
)>file.logthanks, I get log now, but I get only succesfull deleted files log.
But I need also files which are access denied, or some else errors why file can not be deleted.
why there is not all in log, do I need something else to do?It helps if you explain exactly what you need.

Try this:

Code: [Select]echo off
for %%a in (

*.gif
*.jpeg
*.tiff
*.gif
*.png
*.bmp
*.jpg
*.tga
*.pcx
*.img

*.avi
*.mov
*.mpeg
*.mpg
*.mpe
*.mpa
*.qt
*.asf
*.asx
*.wmv
*.wma
*.wmx
*.rm
*.ra
*.ram
*.rmvb
*.mp4
*.3gp
*.3pg
*.ogg
*.mkv

*.wav
*.mp3
*.aiff
*.3gp
*.aac
*.flac
*.gsm
*.m4a
*.m4p
*.mpc
*.ogg
*.wma

*.swf
*.divx
*.flv
*.vhd
"Backup%Files*.zip"
) del /S /Q "%%~a" >> "file.log" 2>&1

Here is another way:

Code: [Select]echo off
del /S /Q *.gif *.jpeg *.tiff *.gif *.png *.bmp *.jpg *.tga *.pcx *.img *.avi *.mov *.mpeg *.mpg *.mpe *.mpa *.qt *.asf *.asx *.wmv *.wma *.wmx *.rm *.ra *.ram *.rmvb *.mp4 *.3gp *.3pg *.ogg *.mkv *.wav *.mp3 *.aiff *.3gp *.aac *.flac *.gsm *.m4a *.m4p *.mpc *.ogg *.wma *.swf *.divx *.flv *.vhd "Backup%Files*.zip" > "file.log" 2>&1
There is a problem in this term though: "Backup%Files*.zip"
because a single percent sign has to be doubled, or you are missing a percent sign if it is supposed to be a variable.I have removed that line but it is the same Quote from: Blisk on September 23, 2014, 10:54:49 AM

I have removed that line but it is the same

Are you trying to tell us something?  Quote from: foxidrive on September 23, 2014, 07:12:27 PM
Are you trying to tell us something?
Yes, still not getting full log of what I see in cmd when start this batch file.
Have you any IDEA what can be worng? Quote from: Blisk on September 23, 2014, 11:48:10 PM
Yes, still not getting full log of what I see in cmd when start this batch file.
Have you any Idea what can be worng?
So you want to log everything?  Not just the command that you gave as a singular example.everything what I get on screen when I run that in cmd.Check out [ulr=http://www.dostips.com/forum/viewtopic.php?f=3&t=5386&p=32561&hilit=tee#p32561]batchTee.bat[/url] by dbenham.If you want to see it on the screen and log it to a file then you would need to use some iteration of TEE.
If you just want to log everything when you type it in from the command prompt then just do this.
Code: [Select]C:\>MyBatchfile.bat >>logfile.txt 2>&1Remember if you really want to see everything then you need to make sure you are not suppressing any output with the ECHO OFF command.  By default it is on but you might as WELL put ECHO ON at the top of your batch file just to be on the safe side.I don't have echo off in batch file
and I just want to log all what I see in cmd when I run batch file.
Quote from: Blisk on September 26, 2014, 01:21:09 AM
I don't have echo off in batch file
and I just want to log all what I see in cmd when I run batch file.

Quote from: Lemonilla on September 24, 2014, 08:37:08 AM
Check out batchTee.bat by dbenham.

This is what you need, look at it.I tested it and now it WORKS, thank you.
I have make a mistake before I forget to add at the end of batch file  this
2>&1
942.

Solve : Grid problems?

Answer»

After finishing my goal for the Adventure game for the month, I decided to start mucking around at what I could do, and my friend asked me to make a grid......
Problem #1 Would I use a x, y gird  and then how would I apply it
Problem #2 I am using an xp with does not have choice
That's all I got.....for now any way
Thanks

I am on my computer testing this right now.....just in case I STOLE this from Snake.bat, but check this out:
Code: (control.bat) [Select]setlocal enableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
set "key="
for /l %%. in () do (
set "key="
for /f "delims=" %%A in ('xcopy /W %~f0 %~f0 2^>nul') do if not defined key set "key=%%A"
set key=!key:~-1!
echo !key!>cmd.txt
if EXIST contr exit
)

The LETTER will appear in cmd.txt.  To use this though, you need to have 'start /b cmd /c control.bat'  to have it run in the background while still maintaining control.

943.

Solve : Batch code to upgrade specified softwares automatically everyday.?

Answer»

Hi All,

I NEED a batch code that will upgrade the SPECIFIED softwares installed in a windows machine AUTOMATICALLY everyday by checking for the latest version of the software in the specified path or server.
Please help if there is any such code.
The installion file can be an exe file or msi file or any other type.
Please reply if this is possible or not.

Thanks in advance.More details needed.checking version is possible with cheking file in FOLDER where software is installed.

if you use regular software than you should use NINITE

944.

Solve : Check for number of times a file has been accessed?

Answer»

I want to write a BATCH file that checks if a particular file has been accessed a certain number of times, then deletes it if it has.

Is this attribute even stored by Windows?Multipost: http://www.dostips.com/forum/viewtopic.php?f=3&t=5953Hi. Is it bad form to multipost? Im TRYING to get a good cross reference of answers. Just curious.. Quote from: nathan323 on October 03, 2014, 04:11:44 PM

Is it bad form to multipost?

On different forums, no, it is fine (of course!) to post the same question. You have done nothing wrong.
Quote from: nathan323 on October 03, 2014, 04:11:44 PM
Hi. Is it bad form to multipost? Im trying to get a good cross reference of answers. Just curious..

The only thing is that the majority of the regular posters are also on that forum, so what foxidrive meant by that was that he already posted on your other thread and wont be posting the same response here.ahhh, I get it, thanks.Well a COUPLE of things could happen.
Two people helping you on two different forums may interpret your question differently and may lead you in the wrong direction which may confuse either you or the person helping you.

And a lot of times I see people post a question and the question get answered or the person trying to help asks for more information and the original poster abandons the thread because they started getting help on another forum and has then wasted the time of the person trying to help.

Either way it would be nice to know if you have posted on another forum so that everyone can see what is going on. Quote from: Squashman on October 03, 2014, 09:25:25 PM
And a lot of times I see people post a question and the question get answered or the person trying to help asks for more information and the original poster abandons the thread because they started getting help on another forum and has then wasted the time of the person trying to help.

Either way it would be nice to know if you have posted on another forum so that everyone can see what is going on.

The above is how I see it too. 

A poster will usually ignore every other site he has posted the question on when he gets an answer, and not tell them that he has an answer.

I understand. I am aware of this THOUGH when I post and address all posts. From now on I might list the URL's of any other sites Ive posted to in each original post. Cheers everyone.Just curious why you would want to delete a file that seems as if it would be frequently accessed by the system or manually by the user?

Files that are frequently accessed are usually not deleted.
945.

Solve : write each host IP in a file using host name?

Answer»

Hi,

I have 10,000 host and i need IP of that host in a file,i used ping command but it is MANUAL,can you please suggest how to automate.Give example of a few lines of host file
You have 10,000 computers that you need the IP addresses for and of which you know the host names of all of them?

* Reason why I am questioning this is because if you are the system admin of 10,000 systems, you would already have tools available to know what your IPs are etc, and you would be ABLE to LOOK at the DHCP pool of all the DHCP servers. Also if its to create a file that was for ACTIVE IP's with systems turned off for a weekend etc that lose their lease and GET a new IP address on Monday etc your IPs could be ever changing on you.

Is this for a Dynamic or Static Network?

I smell Halibut...

946.

Solve : Execute all within the selected folder?

Answer»

I would like a script to open all the urls within a folder in tabs in the default browser, and any other launchable apps or documents in the folder with the default app. launcher.

How can I do this. Do you know any app. able to do this with ease ?

Best Regards
look at the commands:
start
for
echo
call
goto

they might be able to HELPI would something done please.
I am not a programmer.
Best Regards
The task seems like an unrealistic explanation of what you want to do, and you seem to expect a solution to something that you aren't describing.

You can't blame anyone here for not wanting to waste their time when you are likely to reply again and say it doesn't work, or
you will change what you have ASKED for.

So give this a shot.


Code: [Select]echo off
for %%a in (*) do start "" "%%a"
pause

Quote from: foxidrive on October 12, 2014, 08:16:30 AM

The task seems like an unrealistic explanation of what you want to do, and you seem to expect a solution to something that you aren't describing.

You can't blame anyone here for not wanting to waste their time when you are likely to reply again and say it doesn't work, or
you will change what you have asked for.

So give this a shot.


Code: [Select]echo off
for %%a in (*) do start "" "%%a"
pause

I try this.
A lot of windows, virtual machines, programs , documents collapsed my pc.
After about of 20 minutes suffering i lost internet and reiniate the pc.

Really don't seems a good code.
The above code wouldn't have caused ANY of those issues...I am trying to analyze what happens. Seems everything on my desktop was executed. I have ten virtual machines about and only 4 GB RAm memory.
Several pdf, word documents, and many folders. THUNDERBIRD messages.
Too much load.
Also execute several bats I have from good programmers to stop services and PROCESSES.

Best Regards.
10 VM's on 1 PC with 4G of RAM ? ?

There my friend is your issue right there... Quote from: patio on October 12, 2014, 12:24:56 PM
10 VM's on 1 PC with 4G of RAM ? ?

There my friend is your issue right there...

I don't execute the VM at the same time..... But the script above did or try until collapse.
I have other pc with 16 GB ram and i can have two or three virtual machines running at the same time.

Best Regards
Quote from: Esgrimidor on October 12, 2014, 12:16:59 PM
I try this.
A lot of windows, virtual machines, programs , documents collapsed my pc.
After about of 20 minutes suffering i lost internet and reiniate the pc.

Really don't seems a good code.

BECAUSE BASED ON YOUR INITIAL DESCRIPTION, THAT IS WHAT YOU ASKED TO DO!
Quote from: Esgrimidor on October 11, 2014, 01:29:21 PM
I would like a script to open all the urls within a folder in tabs in the default browser, and any other launchable apps or documents in the folder with the default app. launcher.

How can I do this. Do you know any app. able to do this with ease ?

Best Regards

If you execute the script you were given it will do exactly what you describe to whatever is in the current folder!  In this case, whatever is on your Desktop since you launched it from there!
Quote from: Squashman on October 12, 2014, 12:51:57 PM
BECAUSE BASED ON YOUR INITIAL DESCRIPTION, THAT IS WHAT YOU ASKED TO DO!
If you execute the script you were given it will do exactly what you describe to whatever is in the current folder!  In this case, whatever is on your Desktop since you launched it from there!

Have you tried ?

I will not try more. But a second try in a folder with eight url also collapsed my system.
Endless console windows appearing and appearing.

 

oh... Foxidrive forgot the if statement, though really not his fault.  Sounded too much like homework to me, but here is the fix:
Code: [Select]echo off
for %%a in (*) do if not "%%a"=="%~nx0" start "" "%%a"
pause

It was opening itself each time it executed, though you should have been able to figure that one out if you had tried to debug it. Quote from: Lemonilla on October 12, 2014, 02:52:23 PM
oh... Foxidrive forgot the if statement, though really not his fault.  Sounded too much like homework to me, but here is the fix:
Code: [Select]echo off
for %%a in (*) do if not "%%a"=="%~nx0" start "" "%%a"
pause

It was opening itself each time it executed, though you should have been able to figure that one out if you had tried to debug it.


Better wait a little more and try perhaps in a virtual machine or in a sandbox.

Best Regards
You need to think about your goal here...and re-state it as to what you want it to do...Or just keep it outside of the folder that is being processed and do a Change directory as the first LINE of code or a PUSHD.
947.

Solve : Safe Internet?

Answer»

I have a friend with problems with virus.
I would like this.
use a virtual machine to browse ordinarily except in a few cases where is needed to do in the system (under windows 7)
When necessary browse with the system browsers i would like a bat able to ask for a password - no need to encrypt or special protection - and run then the browser opening a couple of urls... . If not interaction aftter about 5 minutos close automatically the browser (configurable better)

Best Regards

What is the point of asking for a password? Anyone can open up the bat file and see the password you are checking the input against. Quote from: Squashman on October 11, 2014, 02:21:27 PM

What is the point of asking for a password? Anyone can open up the bat file and see the password you are checking the input against.

Don't worry about that. Are not expert users.
Only needed express is not allowed. even better is launch with the bat a set or url that are needed in this case for the special purpose.
In general launcha urls from inside the virtual machine.
Esgrimidor,
Anything that really helps is useful. Bat your IDEA of DOS level passwords does does not find support. Microsoft has put password protection at the Windows log in. It would seem that other log in scripts are of no value.
May I suggets this article:
Windows 8 Security: What's New
The PCWorld article was published two years ago, In PART it said:
Quote
Antivirus Comes Preinstalled
For the first time in the history of Windows, you’ll enjoy protection from viruses, spyware, Trojan horses, rootkits, and other malware from the very first day you turn on your Windows PC--without spending a cent. Windows 8 comes with an updated version of Windows Defender that includes traditional antivirus functions in addition to the spyware protection and other security features that it has offered since Windows Vista. Windows Defender now provides similar protection--and a similar look and feel--to that of the free Microsoft Security Essentials antivirus program, which Microsoft has offered to users as an optional download since 2000 ...
True, people need hope. But offering a FALSE hope is hardly better than no hope. There are TOOLS that can reduce the risk of a virus infection. So far, I  have never saw  a DOS based program that helps.

However, if you have found  a new idea, please tell more. 



Nebelous query of the Month Finalist...Tell your friend to post here so we can try to help him or herWe have certainly helped you with a lot of batch files over the years.  I would think you could at least start to attempt to write the batch file first and then ask for help.Hard times for me indeed.

Don't worry.
Try if you can.
Quote from: Geek-9pm on October 11, 2014, 04:05:06 PM
Esgrimidor,
Anything that really helps is useful. Bat your idea of DOS level passwords does does not find support. Microsoft has put password protection at the Windows log in. It would seem that other log in scripts are of no value.
May I suggets this article:
Windows 8 Security: What's New
The PCWorld article was published two years ago, In part it said:True, people need hope. But offering a false hope is hardly better than no hope. There are tools that can reduce the risk of a virus infection. So far, I  have never saw  a DOS based program that helps.

However, if you have found  a new idea, please tell more. 

All I need is a simple password.
With that is enough. Only target is ask a simple word. No matter in this case the additional security.
It's a way to remember the browser in the system is only for certain uses.

Best Regards
Quote from: Esgrimidor on October 12, 2014, 01:24:13 PM
Hard times for me indeed.

Don't worry.
Try if you can.
There is only so many times we can give the fish to you. At some point you have to learn to fish. Quote from: Allan on October 11, 2014, 04:30:18 PM
Tell your friend to post here so we can try to help him or her

Don't write english
It's 78 years old.
I will continue with this project.
Maybe I can help. I am 76 years old.
Most things in Windows are now done at a higher level than DOS. An the things you do in DOS are local transitory, they are not a global and persistent.
To gather a password for a specific purpose, you would write a program in one of the suitable languages that can present a visual interface to the user.
Some of these can be built on DOS, but are at a higher level.
For some time Microsoft has recommended that users subbasement their DOS batch files with Vb Script to make things easy.
http://www.instructables.com/id/VBS-Tutorial-Basics/
Quote
What is vbs?
VBScript is a Microsoft scripting language. -_- so being Microsoft they go and make it so it only works on IE. But as well as being a web script it is used for all kinds of things ...
for example on pic 2) (that's the second pic) That is take from the System 32 folder. Vbs can also be used to make programs .. but that's VB.NET .. uses most of the same coding though.
Please enjoy the tutorial .. and please comment and rate.
And please tell me if someone has beet me to making a vbs tutorial .. but i couldn't find one.
Other than cammel8 who seems to be really good with vbs scripting =P .. but i'm still gonna make the tutorial.
The above tutorial has scripts and picture to help ;you write a simple script to get information from a user. A VB Script can be invoked from inside a batch file.
Please look over the tutorial.



Teach a man to fish...Hard times for no programmers like me.

Very nice to receive so many lessons about how to do.

948.

Solve : Trying to understand snake.bat's realtime input system?

Answer»

So I've been pondering this for quite a while, but I still cannot figure out how the real time input works in snake.bat.  If anyone understands it and would be willing to walk me though it's process, It would be much appreciated.

Link to snake.bat: http://www.dostips.com/forum/viewtopic.php?f=3&t=4741Maybe you should EXPLAIN this:
Quote

real time input works
Batch programs do not have real time input.
They are batch programs.
By definition they are background tasks.

Explain what you think the program does. Then we can focus on just that little bit of code that does what you DESCRIBE. That code is much to large to post here. Tell us what you think it does and somebody here with exact the few lines of code that do what you think it does.

It uses xcopy and a feature where the character is echoed, and that character is extracted to tell which character was pressed.

Post in the snake.bat THREAD and Dave is most often HAPPY to answer specific questions
Quote from: foxidrive on April 01, 2014, 11:18:09 PM
Post in the snake.bat thread and Dave is most often happy to answer specific questions
Agreed.  Why not go straight to the source and ask the question.The XCOPY input hack is not that complex. If you study the code and run some experiments, you should be able to figure it out.

The interesting bit is how the game uses multiple processes and communicates between them via files. This is the critical design that allows the input to be non-blocking. See http://www.dostips.com/forum/viewtopic.php?p=31035#p31035 for a HIGH level explanation of the inter-process communication.


Dave Benham
949.

Solve : [type] Input line too long?

Answer»

I'm getting a funny error that I thought was due to my abnormally long string, but when I started debugging I'm getting an error when using the 'TYPE' command.  Has anyone ever had issues with this before?

Code: (buildExternal.bat) [Select]::echo off
setlocal EnableDelayedExpansion
echo %path% | repl ";" "\r\n" xi >path.txt
if exist external.txt del external.txt
for /f "delims=" %%A in (path.txt) do (
cd /d "%%A" 2>nul
for %%X in (exe) do (
dir /b *.%%X >>%~pd0\external.txt 2>nul
)
)
cd /d %~pd0
del path.txt
set list=
for /f "delims=" %%A in (external.txt) do set "list=%%~nA(%%~xA)?_!list!"

set list

echo"!list:_=|!"

set list=%list:(=-%
set list=%list:)=+%

set list

type template.tmLanguage
:: | repl "_" "%list:_=|%" | repl "-" "\x28" x | repl "+" "\x29" x ">Batch File.tmLanguage"
Code: (Output) [Select]...
        <key>name</key>
        <string>Batch File</string>
        <key>scopeName</key>
        <string>source.dosbatch</string>
        <key>fileTypes</key>
        <array>
            <string>bat</string>
        </array>
    </dict>
</plist>The input line is too long.
was unexpected at this time.

T:\>
T:\>
Code: (template.tmLanguage) [Select]<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-

1.0.dtd">
<plist version="1.0">
    <dict>
        <key>uuid</key>
        <string>E07EC438-7B75-4437-8AA1-DA94C1E6EACC</string>
        <key>patterns</key>
        <array>
            <dict>
                <key>name</key>
                <string>keyword.command.dosbatch</string>
                <key>match</key>
                <string>^[]|_</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.control.statement.dosbatch</string>
                <key>match</key>
                <string>([%][%]([A-Z]|[a-z])|\%([^\%]*?)\%|%[~][fdpnxsatz]********[0-9]|%[0-9]|\!([^\!]

*?)\!)</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.control.conditional.if.dosbatch</string>
                <key>match</key>
                <string>(if((not)?defined|exist)?)</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.control.conditional.dosbatch</string>
                <key>match</key>
                <string>(GTR|GEQ|EQU|LEQ|LSS|NEQ|\=\=)$</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.control.repeat.dosbatch</string>
                <key>match</key>
                <string></string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.operator.dosbatch</string>
                <key>match</key>
                <string>[+|-|*|/]\=$|[=]$</string>
            </dict>
            <dict>
                <key>captures</key>
                <dict>
                    <key>1</key>
                    <dict>
                        <key>name</key>
                        <string>keyword.command.rem.dosbatch</string>
                    </dict>
                </dict>
                <key>name</key>
                <string>comment.line.rem.dosbatch</string>
                <key>match</key>
                <string></string>
            </dict>
            <dict>
                <key>name</key>
                <string>comment.line.colons.dosbatch</string>
                <key>match</key>
                <string>^\s*:\s*:.*$|^REM*$|^(?:^|\s)^((?i)rem)^(?:$|\s.*$)</string>
            </dict>
            <dict>
                <key>begin</key>
                <string>"""\n\n\n"""\s."</string>
                <key>endCaptures</key>
                <dict>
                    <key>0</key>
                    <dict>
                        <key>name</key>
                        <string>punctuation.definition.string.end.shell</string>
                    </dict>
                </dict>
                <key>beginCaptures</key>
                <dict>
                    <key>0</key>
                    <dict>
                        <key>name</key>
                        <string>punctuation.definition.string.begin.shell</string>
                    </dict>
                </dict>
                <key>name</key>
                <string>string.quoted.double.dosbatch</string>
                <key>match</key>
                <string>\"([^\"]*?)\"</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.operator.pipe.dosbatch</string>
                <key>match</key>
                <string>[|]|[\^|]</string>
            </dict>
            <dict>
                <key>name</key>
                <string>keyword.operator.redirect.shell</string>
                <key>match</key>
                <string></string>
            </dict>
        </array>
        <key>name</key>
        <string>Batch File</string>
        <key>scopeName</key>
        <string>source.dosbatch</string>
        <key>fileTypes</key>
        <array>
            <string>bat</string>
        </array>
    </dict>
</plist>
Does that single line generate an error with type?

Code: [Select]type template.tmLanguage
Sorry of the delayed responce.  That threw no error, but when you add the repl it does.  I've done some narrowing down to
repl "+" "\x29" x in type "Batch File.tmLanguage" | repl "___" "|" | repl "-" "\x28" x | repl "+" "\x29" x.  I'm not sure why its doing it, but now it throws:
Code: (error) [Select]C:\cmdPlugins\repl.bat(282, 1) Microsoft JScript runtime error: Unexpected quant
ifier

C:\cmdPlugins\repl.bat(305, 37) (null): The pipe is being closed.

C:\cmdPlugins\repl.bat(305, 37) (null): The pipe is being closed.

The process tried to write to a nonexistent pipe.
Which I believe is due to the use of ), but I can't figure out how to get around it.

Code: (full) [Select]echo off
setlocal EnableDelayedExpansion
echo %path% | repl ";" "\r\n" xi >path.txt
if exist external.txt del external.txt
for /f "delims=" %%A in (path.txt) do (
cd /d "%%A" 2>nul
for %%X in (exe) do (
dir /b *.%%X >>%~pd0\external.txt 2>nul
)
)
cd /d %~pd0
del path.txt
type beginTemplate.txt >"Batch File.tmLanguage"

for /f "delims=" %%A in (external.txt) do echo.___%%~nA-%%~xA+?>>"Batch File.tmLanguage"
type template.tmLanguage >>"Batch File.tmLanguage"

type "Batch File.tmLanguage" | repl "___" "|" | repl "-" "\x28" x | repl "+" "\x29" x
Input line too long is an error with programs or utilities that limit the line to about 250 chars. ONE c fix to reduce an expression into segments that can be parsed separately.
http://www.digizol.com/2006/12/input-line-is-too-long-windows-command.html
 
In the above limik example the length limit was much, much HIGHER and still the OP went beyond. He WOULD have to just cut the path shorter.Here is the line with the problem:
Code: [Select]type "Batch File.tmLanguage" | repl "___" "|" | repl "-" "\x28" x | repl "+" "\x29" x >"Batch File.tmLanguage"

The problem is + is a regex meta-character (quantifier). It must either be escaped:
Code: [Select]type "Batch File.tmLanguage" | repl "___" "|" | repl "-" "\x28" x | repl "\+" "\x29" x >"Batch File.tmLanguage"

Or use the L (literal) option:
Code: [Select]type "Batch File.tmLanguage" | repl "___" "|" | repl "-" "\x28" x | repl "+" "\x29" xl >"Batch File.tmLanguage"

Note that parentheses in your Replace arguments are not a problem as long as they are quoted. You could simply use "(" and ")" instead of "\x28" and "\x29".

I have ceased development of REPL.BAT in favor of JREPL.BAT.

You can easily do all three replacements with a single JREPL call:
Code: [Select]call jrepl "___ - +" "| ( )" /l /t " " /f "template.tmLanguage" /o "Batch File.tmLanguage"

Dave BenhamThank you!  I'll take a look at jrepl later.  Have a great day.

950.

Solve : [HELP]Output two values in batch log to .csv with headers?

Answer»

Greetings Everyone,

To begin with, I extremely suck at doing batch SCRIPTING, so pardon my lack of understanding in this field.

I am ATTEMPTING to output certain values to a .CSV file, however, I am unable to to get them separated into 4 columns.

Ideally, I would like to have the time-stamp of this activity logged onto another column of the CSV file as well.

The output should look something like this:

Column A
Hostname
TEST-PC01

Column B
Queried "START" value of "HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR" from registry

Column C
DATE
DD/MM/YYYY

Column D
TIME
14:00

Below is what I have thus FAR :

echo off
echo %computername%/%username% >>C:\reg_output.csv
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>C:\reg_output.csv
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR" /v "Start">>C:\reg_output.csv
echo>>C:\reg_output.csvGather all your data into separate variables and then echo all of them at once to the CSV file.

Code: [Select]Echo %computername%,%regquery%,%date%,%time% >>C:\reg_output.csvAlso posted on TechGuy.org on November 17th.
Foxidrive replied back that day but the OP did not respond back again until today.
http://forums.techguy.org/dos-other/1137586-output-two-values-batch-log.html