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.

7751.

Solve : Ms Dos command to know in which drive the operating system is installed?

Answer»

Hi everybody, I am chaitanya. I need some help regarding the operating system installation path. There is no rule that the operating system must be installed in 'c' drive only. So I need a command to know in which drive the operating system is installed.
Thank you all in advance.Your title says "MS-DOS command". Well, MS-DOS is always installed on drive C. if, however, you meant a Microsoft Windows console command, then for Windows NT family OSs the system variable %SystemDrive% contains the letter of the drive on which the currently running operating system is installed. It MAY be the same on W95/98/ME.

Type SET at the prompt to see all current system variables.
Thank you Salmon for your quick reply, but this doesn't solve my problem. I want to know the drive of the current operating system. I am preparing a batch file to automate a process in my project. As a part of the project I have to place some files in particular directories daily, and those directories are in the operating system. Some people can have their operating system installed in d drive also. So I need a command to get that one.

Hope this explains you my problem. Please help me with this. Thank you in advance.You asked how to find which "drive" the operating system is installed on. A Windows system can have up to 26 drive letters. I just told you that the environment variable %SystemDrive% contains the drive letter (and its following colon) of the current operating system. What part of that did you not understand?


Thank you Salmon for helping meQuote from: krishnaanu on December 11, 2009, 04:08:39 AM

Sir %SystemDrive% is not working. My operating system is Windows XP Service Pack 3

So is mine. How are you using %systemdrive% ? Do you know what a variable is ? And how to use one in a batch script?
Sorry sir, I am new to batch scripting, there is some confusion. Any how thank you a lot for your interest in solving my problem.Quote from: krishnaanu on December 11, 2009, 04:13:59 AM
Sorry sir, I am new to batch scripting, there is some confusion. Any how thank you a lot for your interest in solving my problem.

echo %SystemDrive%

START>RUN> [type] CMD

U VIL knoe at the dos windowHow does that answer the question?
It is real easy people. On any version of Windows, open the command prompt (or DOS prompt for you legacy users) and type "VER". Quote from: saboya on December 13, 2009, 06:37:59 AM
It is real easy people. On any version of Windows, open the command prompt (or DOS prompt for you legacy users) and type "VER".


7752.

Solve : display text as stars (password)?

Answer»

Quote from: Geek-9pm on December 05, 2009, 03:14:18 PM

Logical error, password was not defined. Otherwise, it works if password was already defined in the system earlier.

password is not a variable, there is nothing to define. password is a literal. Setting the password to password was perhaps a POOR choice although it seemed inspired at the time.

I made a few changes for the critics among you: (but the password is still password)

Code: [SELECT]@echo off
setlocal
echo hP1X500P[PZBBBfh#b##[emailprotected]`$fPf]f3/f1/5++u5>hide.com

:retry
set /p userid=Enter UserId:
set /p pass=Enter password: < nul
for /f "tokens=*" %%i in ('hide.com') do set pass=%%i
if /i .%pass%==.password goto next
cls
echo TRY again. You are not logged in!
goto retry

:next
echo. & echo You are logged in!
del hide.com
endlocal



Salmon is right, anybody serious about security would never use a batch file to authenticate a password. Hide.com is actually an assembled debug SCRIPT which shuts off echoing on the command line, but at some point the password entered has to be compared to the actual password and this is where anybody that can read batch code can learn the password.Sidewinder,
You are right!
Where can I find the source code for hide.com ?

Quote from: Geek-9pm on December 05, 2009, 06:08:26 PM
Where can I find the source code for hide.com ?

Code: [Select]
Your Message here


I decided to take the source code down. The assembled code is in the batch file, so someone imaginative should be able to produce the source code. Good luck.
Is there a command or value too, like if your password is 3 times incorrect wait 1 day?Quote from: pds on December 13, 2009, 04:53:20 AM
Is there a command or value too, like if your password is 3 times incorrect wait 1 day?

what are you trying to do actually? manually hand crafting password control with batch?? If you want to do the above, you have to set policiesMS does not recommend using batch to manage passwords.
If you really need it, you will have to learn to read
programs in C++ and study the work of others.
Quote
MS-CHAP Password Management API
Purpose
The MS-CHAP Password Management API makes it possible to use MS-CHAP to change user passwords. Windows programmers can use this API to create applications to change the passwords of networked users on remote workstations.
http://msdn.microsoft.com/en-us/library/ms697873(VS.85).aspx
i also do
7753.

Solve : run code if folder(s) exist?

Answer»

i am USING the following code to clean up IE, but SOMETIMES the code does not run properly. i would like to pass the code through a if exists CHECK, then run the code:

FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Cookies\*.*" >> C:\BackUpHistory\Report.txt
FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\Temp\*.*" >> C:\BackUpHistory\Report.txt
FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\History\*.*" >> C:\BackUpHistory\Report.txt
FOR /D %%G IN ("C:\Documents and Settings\*.*") DO DEL/S/Q/F "%%G\Local Settings\Temporary Internet Files\*.*" >> C:\BackUpHistory\Report.txt

the best that i can FIGURE out is the code stops working when it comes to a user's profile where the appropriate folder does not exist.
if the proflile or user name jat does not have any of the folders, all of the profiles before Jat are cleaned, but after Jat, nothing gets cleaned. i wold like to pass each of the 4 lines of code throught an if exist then ...

any help would be appreciated,

jat
You need the if command.
Or here.Here:

If exist FOLDERNAME (
commands
commands
)

7754.

Solve : send all ur succesfull scripts?

Answer»

this script is method to ping to a pc
Code: [Select]
@echo on
cls
ping 192.168.0.1
pause
ftp
pause
open 192.168.0.1
play 192.168.0.1
pause

<>note
so you can change my script copyright by http//www.192.168.0.7.M0DC3T.atrib?.cmd.qua/.ms-dosport-pds.jp Huh Code: [Select]@echo off
cls
title -=Ξmarix b version pdsΞ=-
color 0a
:loop
echo %random%%random%random
echo %random
echo %random%%random%
goto loop
copyright by pds
Seems like we have a child posting scripts that don't do anything useful.
i'm adult and i've some usefull scriptsI don't think that one you posted above is very useful. Please do not post silly or frivolous scripts.
Is it possible to....copyright a command prompt script?

-.-Quote from: Carbon Dudeoxide on November 25, 2009, 04:58:35 AM

Is it possible to....copyright a command prompt script?

-.-
Copyrighting is a long and expensive process. No one WOULD do it for a batch script.

No offence, but the only scripts I made that were that bad just opened it self over and over. ok i these a good one
Code: [Select]cls
@echo off
title pds password
if EXIST Control Panel.
{21EC2020-3AEA-1069-A2DD-08002B30309D}
goto unlock
if NOT EXIST PRIVATE goo mdlocker
:CONFIRM
echo Are you sure you want to lock thr folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==N goto END
if %cho%==n goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Private "Control Panel.
{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ATTRIB +H +S "Control Panel.
{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto END
:UNLOCK
echo to unlock foder
set/p "pass=>"
if NOT %pass%== 12345 goto FAIL
attrib -h -s "Control Panel.
{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Conrtol Panel
{21EC2020-3AEA-1069-A2DD-08002B30309D}"
Private
echo FOLDER uNLOCKED SUCCESSFULLY
GOTO END
:FAIL
ECHO INVALID PASSWORD
GOTO END
:MDLOCKER
MD Private
ECHO PRIVATE CREATED SUCCESSFULLY
GOTO END
:END
i hope you change your MIND
for change your password change 123345 into what you wantI can copy and paste too!

http://balaarjunan.wordpress.com/2007/06/28/folder-lock-without-any-software/but i've use this script 9 years ago everybody know this and this has copyright by [emailprotected]Pds, I wrote that script 10 years ago. I copyrighted it. You can't use it! It's Mine! MY OWN! MY PRECIOUS!

I give up.Quote from: pds on November 25, 2009, 05:14:39 AM
but i've use this script 9 years ago everybody know this

Who's 'Everybody'?Quote from: Carbon Dudeoxide on November 25, 2009, 05:38:51 AM
Who's 'Everybody'?

All the VOICES in his mindi swear it on myself i write this script i have a aliB
7755.

Solve : Remove Last Token From String?

Answer»

Quote from: foxidrive on JANUARY 01, 2013, 04:07:21 AM

In this instance is there an issue where there are data tokens with spaces in them?

Edit: I tested it and it works with a space


Cross posted with your edit

C:\>cscript //nologo Striptoken.vbs "Big man,LITTLE dog,red car,blue sky at noon,cheese and biscuits" "," 1
Big man,little dog,red car,blue sky at noon

With the VBS split method you can have multiple chars as delims so this is possible

C:\>cscript //nologo Striptoken.vbs "a++b++c++d" "++" 1
a++b++c

I WONDER about quotes in data tokens...
Quote from: foxidrive on January 01, 2013, 04:07:21 AM
Edit2: I figured out how it works - nice general purpose routine there.

Thank you for the kind words - as you can see, for many quick hack THINGS VBScript is so handy. I like making things general purpose if I can - I try to avoid hard coded "magic number" type stuff.

7756.

Solve : Graphical Formatting in DOS?

Answer»

So, this is really a question of "do you know a resource." I want to learn a little more for graphical formatting in DOS. I know "color" and that's it. LOL! I'd like to know how it is that your can various colors on-screen at the same time, using various ASCII design chars and all that other fun stuff.

Also, I have seen it where there's an actual text field. How does that work. I'd like to put a little something together possibly, but this is SOOO antiquated I couldn't find anything that helped with Google alone... so yeah.So the only graphical things that are built into batch are color, echo off, echo., and 0>nul set /p=.

color changes all text and background. there are a couple of work arounds to c change colors involving
findstr that i will post tomarrow when i have access to my notes.

echo off stops the displaying of the command before it is executed.

echo. makes a blank line.

0>nul set /p= will WRITE without ending the line.
eg: cout >> "hello world"
vs. cout >>"hello world \n"

(if my c++ hasn't failed me yet.)Here is a routine by carlos on dostips.com

Code: [Select]@Echo Off
Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
Pause >Nul
Exit /B

:Color
:: v21
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
If Not Exist `.7 (
Echo(|(Pause >Nul &Findstr "^" >`)
Set /P "=." >>` <Nul
For /F "delims=;" %%# In (
'"Prompt $H;&For %%_ In (_) Do Rem"') Do (
Set /P "=%%#%%#%%#" <Nul >`.3
Set /P "=%%#%%#%%#%%#%%#" <Nul >`.5
Set /P "=%%#%%#%%#%%#%%#%%#%%#" <Nul >`.7))
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ EOL^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Goto :Eof
Goto :__Color
@echo off
color 07
mode 80, 58
setlocal disableDelayedExpansion
set q=^"
echo(
call :c 04 " "&call :c 40 " " /n
call :c 04 " "&call :c 40 " #"&call :c 40 " "&call :c 40 "# " /n
call :c 04 " "&call :c 40 " # # " /n
call :c 04 " "&call :c 40 "### # # ###" /n
call :c 04 " "&call :c 40 "## # # ##" /n
call :c 04 " "&call :c 40 "## ##################### ##" /n
call :c 04 " "&call :c 40 "## # # # # ##" /n
call :c 04 " "&call :c 40 "# # # # # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 60 "###"&call :c 40 "# #"&call :c 60 "###"&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# "&call :c 60 "#### "&call :c 40 "# #"&call :c 60 " ####"&call :c 40 " #" /n
call :c 04 " "&call :c 40 "# "&call :c 60 "#### "&call :c 40 "###################"&call :c 60 " ####"&call :c 40 " #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 "# #"&call :c 40 " ########### "&call :c 60 "# #"&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " # #"&call :c 40 " # # "&call :c 60 "# # "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " # #"&call :c 40 " # # "&call :c 60 "# # "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " # #"&call :c 40 " # # "&call :c 60 "# # "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " # #"&call :c 40 " # # "&call :c 60 "# # "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "## #"&call :c 60 " # #"&call :c 40 " # # "&call :c 60 "# # "&call :c 40 "# ##" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # #"&call :c 40 "# #"&call :c 60 "# # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # #"&call :c 40 "# #"&call :c 60 "# # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # #"&call :c 40 "## ##"&call :c 60 "# # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # "&call :c 40 "#######"&call :c 60 " # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " "&call :c 6f "##"&call :c 60 " "&call :c 6f "##"&call :c 60 " "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " "&call :c 6f "#"&call :c fb "##"&call :c 6f "###"&call :c 60 " "&call :c 6f "###"&call :c fb "##"&call :c 6f "#"&call :c 60 " "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " "&call :c 6f "#"&call :c fb "# ###"&call :c 6f "#####"&call :c 60 " "&call :c 6f "#####"&call :c fb "### #"&call :c 6f "#"&call :c 60 " "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "###"&call :c 60 " "&call :c 6f "#"&call :c fb "# #####"&call :c 6f "#####"&call :c 60 " "&call :c 6f "#####"&call :c fb "##### #"&call :c 6f "#"&call :c 60 " "&call :c 40 "###" /n
call :c 04 " "&call :c 40 "#"&call :c 60 " #"&call :c 6f "#"&call :c fb "# #####"&call :c 6f "#"&call :c 60 " "&call :c 6f "#"&call :c fb "##### #"&call :c 6f "#"&call :c 60 "# "&call :c 40 "#" /n
call :c 04 " "&call :c 40 "#"&call :c 60 " #"&call :c 6f "#"&call :c fb "# #"&call :c 60 "#######"&call :c fb "# #"&call :c 6f "#"&call :c 60 "# "&call :c 40 "#" /n
call :c 04 " "&call :c 40 "#"&call :c 60 "# # "&call :c 6f "#"&call :c fb "###### #"&call :c 60 "#######"&call :c fb "# ######"&call :c 6f "#"&call :c 60 " # #"&call :c 40 "#" /n
call :c 04 " "&call :c 40 "#"&call :c 60 "# # "&call :c 6f "######"&call :c fb "#########"&call :c 6f "#"&call :c 60 " "&call :c 6f "#"&call :c fb "#########"&call :c 6f "######"&call :c 60 " # #"&call :c 40 "#" /n
call :c 04 " "&call :c 40 "# "&call :c 60 "# # "&call :c 6f "#########"&call :c 60 " "&call :c 6f "#########"&call :c 60 " # #"&call :c 40 " #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 "# # # #"&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # "&call :c 04 " "&call :c 60 "# # # #"&call :c 04 " "&call :c 40 " # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 "## # # ##"&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # "&call :c 04 " "&call :c 60 " # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# # #"&call :c 60 " # ## ## # "&call :c 40 "# # #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " ## # # ## "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " # "&call :c 40 "###"&call :c 60 " # "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# #"&call :c 60 " "&call :c 40 "###### ######"&call :c 60 " "&call :c 40 "# #" /n
call :c 04 " "&call :c 40 "# ## # # ## #" /n
call :c 04 " "&call :c 40 "# ############# #" /n
call :c 04 " "&call :c 40 "# ## ## #" /n
call :c 04 " "&call :c 40 "# # # #" /n
call :c 04 " "&call :c 40 "#####################"


ping -n 99 localhost >NUL

:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b

:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^

^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
)
)
if /i "%~3"=="/n" echo(
popd
exit /b


:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b


:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b

Fro reference:
http://en.wikipedia.org/wiki/ANSI.SYS
many older DOS programs use ANSII as a foundation for color PRESENTATIONS of text.
Quote

Once LOADED, ANSI.SYS enabled code sequences that changed the colors of the cursor and characters on the screen, or enabled software programs to move the cursor up or down lines, enabled blinking text, and similar text graphics features. Using this driver, text could be displayed in 16 different colors ("foreground" colors), with 8 optional background colors. It also allowed for the changing of the video mode from standard 80x25 text mode to a number of different graphics modes (for EXAMPLE, 320x200, 640x200, 40-column text mode) depending on which video graphics card was installed.
7757.

Solve : Split output to display & log file?

Answer»

Searching all over for a way to split output to display & log file when running batch file.

An example without listing my lengthy batch file is the following:

Code: [Select]echo off
cls
xcopy c:\Data\*.* g:\*.* /s/d/y>>xCopy_Log.txt
echo. Backup Complete
pause
echo on
The above will pass what normally would be displayed to the user to the xCopy_Log.txt file and the display to the user would be not echo'd with info until the xcopy routine is completed in which point you would see

Quote

Backup Complete

Press any key to CONTINUE..
and it would exit.

Not sure if splitting an output is POSSIBLE in batch or not. Was thinking that if the output cant be split that one could display the log using say a program in C++ to display x-Many lines from the log at a time or scroll through what has already been COPIED on the display after the copying has ended such as

Code: [Select]echo off
cls
xcopy c:\Data\*.* g:\*.* /s/d/y>>xCopy_Log.txt
Display_xCopy_Log.exe
echo. Backup Complete
pause
echo on
To me it seems as their has to be an easier way to go about this to display real-time echo'd information + logging it by splitting the output somehow. But this is beyond my batch coding abilities so figured I'd post it here.

*Also to mention that if I was to have to use a C++ program to display the latest xcopy after the actual xcopy has been completed, I'd have to go with > vs >> to avoid lengthy log playbacks of prior xcopy routines logged. The reason for using appending to end >> is because my lengthy batch PROCESS currently appends to the log file.

***UPDATE***

Through different search words in Google I came across a TEE for Windows. But not sure if this is the best solution or not. Seen comments that its buggy under some conditions. http://code.google.com/p/wintee/

Would be nice to be able to do this in just batch, but can be processed in any other code type as well. Starting to think that maybe its beyond what Batch natively can do.A Tee filter is what you need. There are millions of them from the dos era and which don't work in the NT line of windows.

The SFK.EXE (swiss file knife) is free and still updated which has a tee capability - you can try that.

You might however prefer to use Robocopy which can log and write to the screen too.I have this squirreled away too - which could be used. A post by Tom, saved from Usenet.

Code: [Select]' Tee.vbs
set con = createobject("scripting.filesystemobject")_
.opentextfile("con:", 2)
do until wsh.stdin.atendofstream
s = wsh.stdin.readline
wsh.echo s : con.writeline s
loop

'In Win7, if cscript.exe is defined as the default host and the SCRIPT is found in the current directory or is named on the PATH, it can be used directly with a pipe, like so ...

' ping localhost | tee > test.txt

'Otherwise and in XP, the cscript host and script extension must be named explicitly ...

' ping localhost | cscript pathspec\tee.vbs > test.txt

' Tom LavedasTEE is the normal way of doing what you describe in *nix family OS types. There are a number of TEE implementations for Windows. That "wintee" one that you have found is a single-person project, and I personally would recommend one of the more robust open-source efforts such as the ones contained in:

The Unxutils package http://unxutils.sourceforge.net/

The GNUwin32 package http://gnuwin32.sourceforge.net/packages/coreutils.htm




Here's a batch file encompassing the tee filter. I think it appends or creates the log file - another file by Tom Lavedas.

Code: [Select] @echo off
> TFILTER.VBS echo. sLogName="Logfile.log" ' default name
>>TFILTER.VBS echo. if WSH.Arguments.Count^>0 then sLogName=WSH.Arguments(0)
>>TFILTER.VBS echo. with CreateObject("Scripting.FileSystemObject")_
>>TFILTER.VBS echo. .OpenTextFile(sLogName, 8, true)
>>TFILTER.VBS echo. .WriteLine Now
>>TFILTER.VBS echo. Do Until WSH.StdIn.AtEndOfStream
>>TFILTER.VBS echo. str = WSH.StdIn.ReadLine
>>TFILTER.VBS echo. wsh.echo str : .WriteLine str
>>TFILTER.VBS echo. Loop
>>TFILTER.VBS echo. end with ' FSO

(echo === Started ====
echo your commands here
copy *.bat "c:\folder" /y
echo ====text here=== )|cscript //nologo TFILTER.VBS MyLogFile.txt

del TFILTER.VBS


Why not just put it in a FOR loop?

Code: [Select]@echo off
for /f "delims=" %%a in ('xcopy c:\Data\*.* g:\*.* /s/d/y') do echo %%a & echo %%a >> xCopy_Log.txtThanks everyone, going to try out what Foxidrive suggested with vb script and tee, & what Helpmeh suggested which might be a way to do it in batch without tee.
7758.

Solve : Delete file that contains certain text?

Answer»

Hello,
I'm trying to find a script that will search for certain text in a file, and if found, delete it. Something like this, but I can't get it to work for some reason.


@ECHO off
for /F"delims=;" %%a in ('findstr /m /i "alldata" %userprofile%\Cookies\*.txt') do (
@echo %%a
rem del %%a
)
This may help:

Code: [Select]@echo off
for /f "tokens=* delims=" %%i in ('dir /a:-d /b /s %userprofile%\Cookies\*.txt') do (
findstr /m /i "alldata" "%%i"
if not errorlevel 1 rem del %%i
)

If the console output looks OK, remove the rem instruction from the if statement to actually delete the files.

Good luck. Thank you for your reply. Unfortunately, I get a MESSAGE that says: "The system cannot find the PATH specified."Double check that path. On my Win7, c:\%userprofile\Cookies is a junction and points to C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Cookies and the %user%profile%\cookies folder is hidden and flagged as a system folder.

Try hardcoding the cookie path as: C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Cookies

Thank you for the reply. I have to look further into this issue because windows blocks the folder by default. Looks like I have to find another alternative to removing cookies for my jobs website another way without removing the entire cookies. Thank you for your help SideWinder, definetely appreciate the FAST response.

7759.

Solve : FOR /F command with DO SET /A, nested within IF?

Answer»

This is the problematic area of a larger batch file I am writing:

Code: [Select]ECHO 14 >TEMP.txt
FOR /F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%(%%j)
ECHO %CHOOSE%
PAUSE
I get the error "Missing operator." The denominator of the modulus operator is not resolving correctly.

Thanks in advance for any help you may be able to provide.

P.S. Sigh...I answered my own question. The line in question is more correctly:

Code: [Select]FOR /F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%%(%%%j)
Posted FYI anywayThe problem re-occurs when the above (working) sample is further nested in an IF statement as follows:

Code: [Select]SETLOCAL EnableDelayedExpansion
FOR /L %%i in (1,1,10) DO IF %%i LEQ 5 (
ECHO 14 >TEMP.txt
FOR /F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%%(%%%j)
)
ECHO %CHOOSE%
PAUSE

The error displayed is "%(%j) was unexpected at this time."

Changing the problematic line as follows:

Code: [Select]FOR/F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%%(!j)


results in the error "%(!j) was unexpected at this time."

How am I to invoke run-time evaluation for the nested FOR variable %%j?

Again, thanks in advance for any help you may be able to provide.Quote from: John_L. on January 03, 2013, 01:40:23 PM

The problem re-occurs when the above (working) sample is further nested in an IF statement as follows:

Code: [Select]SETLOCAL EnableDelayedExpansion
FOR /L %%i in (1,1,10) DO IF %%i LEQ 5 (
ECHO 14 >TEMP.txt
FOR /F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%%(%%%j)
)
ECHO %CHOOSE%
PAUSE

The error displayed is "%(%j) was unexpected at this time."

Changing the problematic line as follows:

Code: [Select]FOR/F %%j in (TEMP.txt) DO SET /A CHOOSE=(%RANDOM%)%%(!j)


results in the error "%(!j) was unexpected at this time."

How am I to invoke run-time evaluation for the nested FOR variable %%j?

Again, thanks in advance for any help you may be able to provide.
Of COURSE you will get that error. You don't USE an exclamation to expand a token! Delayed Expansion does not work with tokens nor is it needed.

Your code seems very very odd to me. I don't KNOW why you are doing what you are doing. The code is extremely inefficient and doesn't seem to serve a practical purpose.

Could you explain what you are really trying to accomplish? Not really understanding why you are doing what you are doing with a lot of your code. Why echo a number to a text file and then read it back in with a FOR /F loop? Why would you create a loop for 10 and then only execute code if the number is LEQ to 5.

Regardless I think this is what you are trying to do.
Code: [Select]@echo off
SETLOCAL EnableDelayedExpansion
FOR /L %%i in (1,1,10) DO IF %%i LEQ 5 (
ECHO 14 >TEMP.txt
FOR /F %%j in (TEMP.txt) DO SET /A CHOOSE=!RANDOM! %% %%j
echo !CHOOSE!
)
PAUSE
7760.

Solve : Port reset script?

Answer»

Hey guys!

So I'm working on this script even as you're reading this, but there's a simple thing I want it to do, no doubt it can be put in as little as 10 lines of code. I need a script that will reset my LPT1 connection.

Sounds too simple right? Right. I have several different computers many of which use different networked printers over the LPT1 connection. Every now and then (and honestly I haven't figured out, or really tried to figure out, why this happens) the LPT1 port will read "Disconnected" when check using NET USE. Since there are several different computer/printer combinations, I want the script the grab the existing LPT1 name before deleting the connection so that it can be written on the reconnect step.

Most of this is quite easy, but there are a few things I need help with... Something like this is what I'm thinking:

Code: [Select]@echo off
echo.
NET USE LPT2 > NUL && set port=LPT2 && if '%port%'=='' set port=LPT1
echo Resetting %port%
echo.
echo Please Wait...
REM I WOULD NEED THE CURRENT PRINTER SHARE INFO GRABBED HERE
set share=\\Hostname\ShareName
net use %port% /delete > nul
echo Connection %port% deleted...
echo Reconnecting %port% now...
net use %port% %share% && echo Connection Repaired... && pause

anyway... IDK.. I think that's prettier than it needs to be. lolIs it possible to get the current share info for the printer if it is disconnected?

Quote from: foxidrive on October 24, 2013, 04:37:37 AM

Is it possible to get the current share info for the printer if it is disconnected?

Yes. But I think it only stays since it's manually set. I can see that if it were a PnP printer that the data wouldn't be available when it's disconnected. For me, the printer doesn't even need to be connected to the Host computer!! Just shared...

If the LPT1 printer stops working, I usually manually use the NET USE command to see if it's actualled correctly, and it will read out something like:

Code: [Select]X: \\network_file_location\file_folder ...
Y: \\network_file_location\file_folder ...
DISCONNECTED \\Host_computer_name\Printer_share_name

From there I manually run
Code: [Select] NET USE LPT1 /DELETE
NET USE LPT1 \\Host_computer_name\Printer_share_name

And am ALMOST always greeted happily with COMMAND COMPLETED SUCCESSFULLY! On RARE ocassions get a credentials prompt, and even more rare, I'll get a failure or ERROR (usually because of mistyping something).

Anyway, yeah! Pointers on extracting that info ( \\Host_computer_name\Printer_share_name ) would be great!!Have you tried something like this?

Code: [Select]@echo off
for /f "tokens=1*" %%a in ('net use ^|find "DISCONNECTED" ') do (
NET USE LPT1 /DELETE
NET USE LPT1 %%b
)
pause
Quote from: foxidrive on October 25, 2013, 04:58:22 AM
Have you tried something like this?

Code: [Select]@echo off
for /f "tokens=1*" %%a in ('net use ^|find "DISCONNECTED" ') do (
NET USE LPT1 /DELETE
NET USE LPT1 %%b
)
pause

haven't really tried anything yet.

I'll give that a shot and let you know foxi. thanks!I had a similar issue many years ago with LPT1 disappearing etc and I was able to solve it by performing a reset of the spooler SERVICE on the system that was connected to the printer which was on LPT1

NET STOP SPOOLER

NET START SPOOLER

I added to a batch file and gave the users in the office the ability to do this over the network to the system that was acting as a print server/workstation. I used the SC.exe remote service manager tool to call SC \\system_name NET STOP SPOOLER and then SC \\system_name NET START SPOOLER

and this seemed to be the fix. Never found out why the HP 4000 laserjet on this HP Compaq Evo PENTIUM 4 system was having this issue, but this was the bugfix to our problem where the printer was not found because it appeared that LPT1 lost connection with the printer under Windows XP Pro systems and a few older Windows 2000 Pro SP4 systems running on Pentium II and Pentium III CPUs, that also were tied to the printer share on the XP print server / workstation.

This might not be related to your issue, however it sounds like the issue I dealt with 6 years ago. And this was the quick fix to allowing the food store to be able to print their signs and other stuff while manning the service desk waiting for customer questions etc.Quote from: DaveLembke on October 25, 2013, 03:48:44 PM
I had a similar issue many years ago with LPT1 disappearing etc and I was able to solve it by performing a reset of the spooler service on the system that was connected to the printer which was on LPT1

NET STOP SPOOLER

NET START SPOOLER

I added to a batch file and gave the users in the office the ability to do this over the network to the system that was acting as a print server/workstation. I used the SC.exe remote service manager tool to call SC \\system_name NET STOP SPOOLER and then SC \\system_name NET START SPOOLER

and this seemed to be the fix. Never found out why the HP 4000 laserjet on this HP Compaq Evo Pentium 4 system was having this issue, but this was the bugfix to our problem where the printer was not found because it appeared that LPT1 lost connection with the printer under Windows XP Pro systems and a few older Windows 2000 Pro SP4 systems running on Pentium II and Pentium III CPUs, that also were tied to the printer share on the XP print server / workstation.

This might not be related to your issue, however it sounds like the issue I dealt with 6 years ago. And this was the quick fix to allowing the food store to be able to print their signs and other stuff while manning the service desk waiting for customer questions etc.

Thanks Dave I'll try that out too. It's happened to pretty much every computer that has the LPT1 setup on it, and I'm not quite sure why. It's usually not a common problem, but it does seem that some systems have more trouble than others. All the systems are XP Pro SP3 or earlier.


Foxi, I tried this:
Code: [Select]for /f "tokens=1*" %a in ('net use ^| find "LPT1" ') do (
echo %b > test.txt(modified for manual entry rather than batch)

made a text file with:
Quote
LPT1 \\Host_Machine\Share_name

I can't remember off the top of my head how to use the trimming and substitute switches... but I'll prolly get that pretty quick.So... here's the new script:

Code: [Select]

@echo on
Title LPT Printer Reset Utility - KUtils
REM Set base variables
set ComD=net use
set port=LPT1
echo Fetching Printer Share Data...
REM check for LPT2
%ComD% LPT2 && set port=LPT2

for /f "tokens=1*" %%a in ('net use ^| find "%port%" ') do ( set share=%%b)
set share=%share:~10%
set ComR=%ComD% %port% %share%
echo Deleting Connection Data...
%ComD% %port% /DELETE
echo Resetting Connection...
%ComR% && goto SUCCESS
goto FAILURE

:SUCCESS
echo Connection Reset Successfully!
echo.
echo Press any key to exit...
pause > nul
exit

:FAILURE
title ERROR!
echo.
echo There was an error in processing
echo your network printer settings.
echo.
echo If this is the first error of
echo this type, try running the
echo utility again.
echo.
echo Press any key to exit...
pause > nul
exit

pastebin.com/xhbPysNq

Here's the new error I hit. It completed fine with the printer that I was testing on, then I decided to network another printer and test it on a different printer to be sure, you know? Then this occurred... This
Code: [Select] for /f "tokens=1*" %%a in ('net use ^| find "%port%" ') do ( set share=%%b)gave me a value of:
Code: [Select]LPT1 \\Host_Machine\Share_name Microsoft Windows Network

Now of course this messes up my script, because it's not TRYING to run the command
Code: [Select]net use LPT1 \\Host_Machine\Share_name Microsoft Windows Networkwhich is syntactically wrong!

Anyway, I got trimming the front 10 chars down... now how do I trim the last X characters? Or how can I tell it to only grab up to the space? :/

I'm gonna keep fiddling around... but if you feel the need to chime in, don't hesitate.Quote from: kyle_engineer on October 26, 2013, 12:40:12 PM

Code: [Select] for /f "tokens=1*" %%a in ('net use ^| find "%port%" ') do ( set share=%%b)gave me a value of:
Code: [Select]LPT1 \\Host_Machine\Share_name Microsoft Windows Network

Change this Code: [Select]tokens=1,2 and it will split it at the spaces. If the network address will never have a space in it then it will work fine.

Another method is to use this, which will remove that exact text.

Code: [Select]set "share=%share: Microsoft Windows Network=%"
@Foxi, It didn't like either of those... :/ maybe because I'm testing on a Win 7 Ult IDE, and not on XP... but I'm not sure. lol!!

I'll keep fiddling around... but if you have any more ideas, let me know!

Thanks If you are changing the variable in a loop then you need to use delayed expansion and the !variable! syntax.

To get help, you'd need to describe the error messages and tell us what it does, and how it fails.Quote from: foxidrive on October 28, 2013, 03:44:44 PM
If you are changing the variable in a loop then you need to use delayed expansion and the !variable! syntax.

To get help, you'd need to describe the error messages and tell us what it does, and how it fails.

duh. sorry.

Code: [Select]tokens=1,2seems to just break the command. when entered manually it returns no result or error at all. (Obviously I also changed the %% to % for manual use, so that's not the problem either...) Running this in a batch results in
Code: [Select]share=Microsoft Windows Networkmeaning it's clipping off the part that I want and keeping the part I don't want.

using this:
Code: [Select]set share=\\host_machine\share_name Microsoft Windows Network
set share=%share: Microsoft Windows Network%results in %share% now having the value "%share: Microsoft Windows Network%" which is completely off from what I want. I also did this with and without quotes and it didn't make any difference.

Anyway, I did a little looking, but isn't there a way to count from the back forward? I could be mixing that up with string manipulation in VB (or VBS or VBA) but I could of sworn I did that before... :/

So yeah, if you want to toy around with it, the exact string I'm stuck on (with spaces and everything) is:
Quote
\\xxxxxx-xxxxx\xxxxxxx Microsoft Windows Network
some of our network naming may differ... so I'd like it to just use the first space as a delim... Wait! I'll see if I can delim at the space and assign the rest to scrap or something!Here's some code - it uses the suggestion I gave you and proves that it works.

Code: [Select]@echo off
set "string=LPT1 \\Host_Machine\Share_name Microsoft Windows Network"


@echo off
Title LPT Printer Reset Utility - KUtils
REM Set base variables
set ComD=net use
set port=LPT1
echo Fetching Printer Share Data...
REM check for LPT2
rem %ComD% LPT2 && set port=LPT2

rem for /f "tokens=1,2" %%a in ('net use ^| find /i "%port%" ') do (set share=%%b)

for /f "tokens=1,2" %%a in ("%string%") do set "share=%%b"
echo set ComR=%ComD% %port% %share%
echo Deleting Connection Data...
echo %ComD% %port% /DELETE


pauseAlright Foxi, I was able to tweak your code a little to work. Not sure what it was, but I decided that the "tokens=1,2" worked when it was being passed a string rather than a command to process. Not sure if that's actually the case, but hey - it worked. LOL!

Anyway, here's what I got!!

Code: [Select]

@echo off

::Lpt Printer Reconnect Utility
Title Lpt Printer Reset Utility - KUtils
::set base variables
set ComD=net use

:: Capture used port
Echo Checking LPT Port Assignment...
%ComD% lpt2 > nul
if %errorlevel% neq 0 (
set port=LPT1
) else (
set port=LPT2)

echo --- Port is set as %port%
echo.

:: Capture current share name
echo Fetching Share Data...
for /f "tokens=1*" %%a in ('net use ^|find "%port%" ') do (
set oShare=%%b)
for /f "tokens=1,2" %%A in ("%oShare%") do set "Share=%%B"
echo --- Network share name captured is - %Share%
echo.

:: Delete Current Port
echo Removing Existing Port Settings...
%ComD% %port% /delete > nul
if %errorlevel% neq 0 (
echo --- Error Deleting Port! && pause > nul && exit
) else (
echo --- Port Deleted Successfully!)
echo.

:: Recreate Port Connection
echo Rebuilding Port Connection...
%ComD% %port% %share%
if %errorlevel% neq 0 (
echo --- Error Rebuilding Port && pause > nul && exit
) else (
echo --- Port Rebuilt Successfully!)
echo.

:: Report Final Settings
for /f "tokens=1*" %%a in ('net use ^|find "%port%" ') do (
set cShare=%%b)
echo.
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +
echo + CURRENT PORT SETTINGS:
echo + --- %cShare%
echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo.
echo Press any key to exit...
pause > nul
exit

http://pastebin.com/xhbPysNq#

It works perfectly for me. (If you test it and it doesn't seem to work, I did manually retype it, so something could have gone wrong.) If you'd like to make any recommendations to clean anything up a little, just let me know.

And THANKS for all the help!!!
- kyle_engineer
7761.

Solve : typing "a" automatically?

Answer»

need help !!

i have made copy.bat
the script is

@echo off

xcopy c:\test \\192.168.1.200\backup /s/e/v/d

end the problem is, whet it running by click the file, it need to type y or a, because some file is need to replaced. i want to make it automatically. how to make the script, after the script that i wrote..

thanks...

You could try using the pipe:

echo a | xcopy c:\test \\192.168.1.200\backup /s/e/v/d

If possible use the "a" option. You can only use the pipe once PER command.

Good luck. thanks alot for your help..
it works..

i need help for one question anymore

how to make it execute automatically without click the batch file?
and what script i have to add to make this file execute every 100 minnute?

thanks alots

You can use the task scheduler to have the job run once per day, then use the advanced settings to run every 100 minutes within a single day.

You could also improvise by making your batch file recursive and using the ping command with the -w switch.

There is a sleep command distributed with the Windows Resource Kit (big download). Search for it at Resource Kit

Good luck. thanks alots, i have used task scheduler to do that..
and now i have the list folder that i have to copies, the files:
- Akademika
- Arif
- Datasql
- Marketing
- etc

when i run the batch file, it run to copy Akademika first and continue to Arif folder, and when it going to copy Datasql, the batch file stop to copy. because Datasql cannot be copied.
Datasql is used by sqlserver service. So it can't be copied. But I have to copy this folder.
do you have any idea to solve my trouble, beside use batch file?
can you help me how solve this problem.., SORY i hate to distrub u again.
thanks a lots
You can add the /c switch to your XCOPY command. Datasql will not be copied but the switch will prevent your batch file from crapping out.

Another process probably has Datasql locked, you will not be able to copy it until the other process gives up control.

Hope this helps. it works perfect..
thanks a lots dude..

i will SET task schuder time for switchoff the sqlserver, when task scheduler time backup starts..


he.. i'am coming again..

the trouble now, the file is have coppied about 37 Gbyte, and then the xcopy proses is stop, the ALERT message SHOW "insufficient memory"...
what do you think with this problem, backup with xcopy need a big memory to use, is it true?
Check to make sure that none of your files resolve to file names longer than 254 characters. A workaround would be to use ROBOCOPY which is included in the Windows Resource Kit.

If a long file name is causing XCOPY to choke, you can use the /N switch which uses the file short names, but short file names may not be suitable for your situation.

Good luck.

PS. When posting, please include your OS.

7762.

Solve : MS commands?

Answer»

Someone please help. I am having a time trying to download DRIVERS for a scanner. I am getting an error message "16-bit MS-Dos subsystem C:windows\system32\autoexec.nt is not suitable for running MS-Dos and MS windows applications"

I found a resolution to use the expand commands. but when i try i keep getting more error messages saying that PATH is not specified. I don't know the correct way to type the COMMAND.You need to retrieve a good copy of autoexec.nt from the repair directory and install it in the system32 directory.

From the command LINE:

copy c:\windows\repair\autoexec.nt c:\windows\system32

No FUSS, no bother, and no dealing with CD's.

Hope this helps.

7763.

Solve : Batch file to copy only new files - help?

Answer»

This is my batch file :

@ECHO OFF
FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data
pause

This batch always copy all files from f:\data to e:\data but i want to copy only NEW files.
When i first run this batch - copy files, when i once again run, still copy all files from f:\data even e:\data contains this files. Where is bug ? Please help.Quote from: paveu on November 04, 2013, 12:53:18 PM

Where is bug ?

FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data
^^^
|||
there is an error here

FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data

Quote from: Salmon Trout on November 04, 2013, 01:00:38 PM
FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data
^^^
|||
there is an error here

FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data

No. It's correct. When i changed from %a% to %%a i get error.FOR loop variables in a batch file are 2 percent signs followed by a letter from A to Z or from a to z such as %%a %%R etc.

A variable with a percent sign, then a text string and finally another percent signs like %a% or %size% or %name% is an ordinary batch variable.

If you did not have a set a=something statement PREVIOUSLY, then I expect %a% is blank and thus f:\data\%a% expands to f:\data\

so INTHAT case your command becomes

copy f:\data\ e:\data

Probably you have files with spaces in the names?

Quote from: Salmon Trout on November 04, 2013, 01:39:57 PM
FOR loop variables in a batch file are 2 percent signs followed by a letter from A to Z or from a to z such as %%a %%R etc.

A variable with a percent sign, then a text string and finally another percent signs like %a% or %size% or %name% is an ordinary batch variable.

If you did not have a set a=something statement previously, then I expect %a% is blank and thus f:\data\%a% expands to f:\data\

so inthat case your command becomes

copy f:\data\ e:\data

Probably you have files with spaces in the names?

I checked and i have no spaces in the names. Could you write correct batch file in this case please ?Try this (will also handle filenames with spaces)

FOR %%a IN (f:\data\*.*) DO IF NOT EXIST "e:\data\%%~nxa" COPY "f:\data\%%~nxa" e:\data

Quote from: Salmon Trout on November 04, 2013, 02:07:44 PM
Try this (will also handle filenames with spaces)

FOR %%a IN (f:\data\*.*) DO IF NOT EXIST "e:\data\%%~nxa" COPY "f:\data\%%~nxa" e:\data

It's working ! Thank you
7764.

Solve : Batch file to rename files - help?

Answer» HELLO

I need your help. I have a LOT of files in directory c:\temp shown as below :

c:\temp\test1fit.csv
c:\temp\test2fit.csv
c:\temp\test3fit.csv
c:\temp\test4fit.csv
..............................

I want to rename all this files by cut 'fit' in names. I want to get following results :

c:\temp\test1.csv
c:\temp\test2.csv
c:\temp\test3.csv
c:\temp\test4.csv
..............................

I have no idea how i can do this in batch file I have to do in batch file. PLEASE help me. I will be appreciative.This might help. Store the batch file in any directory you want (does not have to be in c:\temp):

Code: [Select]@echo off
setlocal enabledelayedexpansion

pushd c:\temp

for /f %%i in ('dir /b /a-d *.csv') do (
SET newName=%%i
set newName=!newName:fit=!
ren %%i !newName!
)

popd

Good luck. Quote from: Sidewinder on November 04, 2013, 10:18:57 AM
This might help. Store the batch file in any directory you want (does not have to be in c:\temp):
Thank you very much
7765.

Solve : Replace a string in a certain position?

Answer»

Hello forum lovers,

I've searched the forums but could not find a way for this issue..

Can I use a batch file to replace a specific string in a bunch of one-line txt FILES that sits in the same directory?

I'd like to change position 25 (length 6) to today's date (YYMMDD) in each txt file. How do I do it?

If batch won't do - would a vb script fix it? In that CASE I'd like to CALL the vb script from a batch file.

Any help appreciated This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

Put repl.bat in the same folder as the batch file.

Test it with some sample 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 "datestamp=%YY%%MM%%DD%"


for /f "delims=" %%a in (' dir /b /a-d *.txt ') do (
type "%%a"|repl "(.{24})......(.*)" "$1%datestamp%$2" >"%%a.tmp"
move "%%a.tmp" "%%a"
)
Awesome foxidrive!

That fixed it. Thanks for your tireless efforts to help out.

The solution provided by foxidrive works great.

As I go along the learning and experience curve I've found two things I'd like to solve:

1) I'd like to avoid having the batch files in the same folder as the files I want to process. I tried to find a way to solve this but failed. Is there a way to TELL repl.bat to use another folder for input/output?

2) I only want to replace the string where it is not equal to today's date. Assume that I want to process a file today (on Nov 4th). I only want to replace the string to today's date if the date in pos 25 is less than today's date.

Any help appreciated! Place repl.bat anywhere on the PATH STATEMENT and it will work without changing the batch file.

c:\windows and c:\windows\system32 are already on the path and you can add a new folder on the path for your utility files. Like c:\util

type echo %path%
and you will see the contents of the path variable - it is searched from start to finish for the executable you try to launch, after searching the current folder. If the executable is found then away it goes.

As for changing the files - if it's putting in todays date then also changing files with todays date doesn't seem to be an issue

7766.

Solve : naval battle game problem help?

Answer»

I do understand you, problem is, I'm not sure if I can use English in my code (you know, I'm not exchange student or anything, so why should I use it). Anyway, for now more than HALF of code commands is in English.
Translation of rest:

@echo off
echo laivu musis.
echo 2 zaidejai.
echo AR norite pradeti?
echo jei TAIP spauskite, bet kuri klavisa, jei ne ctrl+c.
pause>NULL
// 2nd line: naval battle
// 2 players
// do you wabt to start?
// if so press anything, if not ctrl+c //these are kinda default

echo pasirinkite:
echo T - Pradeti zaidima
echo N - Baigti zaidima

CHOICE/c:TN

//echo pasirinkite == choice:
//T == start game
//N == end game

echo pirmas zaidejas iveda savo 10 laivu. 1 koordinate = 1 laivas
//first player enters his fleet of 10 ships 1coordinate equals 1 ship

prn1 like message1 or msg1

:prn1
echo tokiu koordinaciu but negali, iveskite is naujo.
goto firstplayer

//echo such coordinates does not exist, repeat.
where u can see rem saudymas means shooting, on other echos it just says that either it's hit or missed. I believe other commands are in english already.

Anyway, I think i just need to delete variable if it's hit and next TIME on picking coordinates to output message which would say that i already hit that and it no longer exist. but then still how to check weather there are any variables left?

hope this helps a bit.Quote from: orux on November 03, 2013, 06:02:27 AM

I do understand you, problem is, I'm not sure if I can use English in my code (you know, I'm not exchange student or anything, so why should I use it).

You're posting to a forum that is in English, and asking for free help. I think they are a good reasons.

After it is all done you could graciously post it for others to use, and an English copy would be widely appreciated.I will post English version here once I'm done with it, but I need to finish it first .
7767.

Solve : If Statement Assistance?

Answer»

Help! Can someone tell me why this isn't working, or help me code it so it will?

IF EXIST C:\new.txt(Copy ZZYes.txt S:\IT)ELSE Copy ZZNo.txt S:\IT

The IF statement doesn't do ANYTHING with either BRANCH? My goal is to look for the "new.txt file and if it is PRESENT copy ZZYes to another drive, if not copy ZZno to the same location.

Thank you!
Just a matter of spacing:

Code: [Select]
IF EXIST C:\new.txt (Copy ZZYes.txt S:\IT) ELSE (Copy ZZNo.txt S:\IT)


HOPE this helps.

7768.

Solve : OT: Ocalabob?

Answer» QUOTE from: Ocalabob on July 12, 2013, 06:33:15 PM
@foxidrive
Good job netting that question. I was concerned that Salmon Trout
might get hooked on the OP's thread.

For those that know Ocalabob, who had a DEEP love of batch files.
Bob passed away Nov 2ND 2013 after a brief illness, aged 66.


foxiR.I.P.That's a great shame, very sorry to HEAR that.
R.I.P.
7769.

Solve : Command to start process once process has ended?

Answer»

Hello all,

Thanks for taking the time to LOOK into my problem. I've been messing around with MS-DOS commands but I'm not fully compatible with it yet. What I would like to do is enable an automated batch file where the file monitors for a specified process to end and re-initiate the command to START the process again if it crashes.

Below is my code THUS far:

@echo off
cls
title Crash Prevention
echo Crash Prevention enabled, opening Processor.exe...
:step1
echo (%time%) Processor.exe started.
start /wait C:\Users\Corey\Desktop\cmd\Processor.exe
echo (%time%) Restarting program due to crash.
goto step1

The only problem I have is 'Processor.exe' executes another program to open, and then Processor.exe closes (I can't run the 2nd program, it has to be done in this order). Once it closes, it goes back to :step1 and initializes the same command over and over. What I would like to do is monitor for the 2nd program once it starts and crashes instead of Processor.exe, and re-initiate the full command as seen above if it were happen to crash.

Any THOUGHTS would be greatly appreciated.

Thanks,
CoreyLet me paraphase your question:

You have exe1 that starts exe2 and then exe1 terminates.

You then want to monitor exe2 and restart exe1 if exe2 crashes.

Is that it?Yes that's correct.This should work - if exe2 exits then it will restart exe1.

If exe2 locks up then it will probably remain in the tasklist and nothing will happen. You'd have to detect the exe2 `not responding` to GET around that.

Code: [Select]@echo off
:start
"c:\folder\file1.exe"
:loop
echo waiting for 10 seconds and checking file2
timeout /t 10 /nobreak >nul
tasklist |findstr /i "^file2.exe" >nul || goto :start
goto :loopfoxdrive,

Your method works great!

Many thanks on my end.

7770.

Solve : run batch as background process?

Answer»

Hi...

I'm trying to create batch job to run a COMMAD as background PROCESS.

How to do so?

And how can I grep the hostname locally into the batch FILE?

Please help...You didn't mention your OS. Your results may differ.

Try RUNNING your batch file minimized from the Task Scheduler. Not truly a background process but CLOSE enough for government work. Note: if your batch file creates a console interrupt, a window will appear.

For the Hostname, this may work:

for /f %%a in ('hostname') do echo %%a

The same info is available in the %ComputerName% environment variable.

Hope this helps.

7771.

Solve : reading emails (send data/files between computers [may not be on network])?

Answer»

So earlyer I found a vbs script that could be called from a batch file to send emails. I was wondering if there was a way to have batch call a script/program, that would read emails. In other words, I want a way for two computers to communicate via internet while running batch scripts. I was thinking that I could send the information over EMAIL, and then have the other batch script wait for the email and read it, using the contence of the email as input. Is this possable?

(want to make a multi-player game)But then you would have to come up with a way to distinguish the emails you want to proces. There are cmd line email clients. I would START by playing around with those.

But I think you would be better off using ftp to send text files to read.Is it possible to use ftp without a website/server? I don't want to set up a server (or know how).Sorry for double post, but I do believe I have figured it out. I installed FileZilla (a ftp server) and can now connect to something. I am planning on including this freeware (or a link to it) along with the settings files in the game installation folder. Thanks for the ftp suggestion Squashman, don't think i'd have run into that without you. Have a happy NEW Year!You also have to remember that you need to port foward if you are on a broadband connection behind a router.Quote from: Squashman on January 02, 2013, 02:33:00 PM

You also have to remember that you need to port foward if you are on a broadband connection behind a router.
You lost me there. If you run an FTP server and expect outside users to access it then you need to direct ports 20 and 21 (FTP ports) to the machine that is running the FTP server (its IP address).

This is referred to as forwarding ports to a destination PC, or more commonly 'Port Forwarding' and is found in some routers under 'virtual servers' tab.

So if the PC running the FTP server has an IP address of 192.168.1.5 then in the router, that is feeding the internet to the PC, you have to forward ports 20 and 21 to 192.168.1.5

If you use passive mode FTP transfers then only port 21 needs to be forwarded, but forwarding both will ensure that there are no issues on that front.
7772.

Solve : Run a batch in MS-DOC to kill a service but only if it's in start_pending status?

Answer»

I need to run a BATCH in MS-DOC to KILL a SERVICE, but only if it's in start_pending status.

Thanks I'll help you write a batch file...

The first THING to FIGURE out is if the service is in start_pending status.
Do you know how to do that?

7773.

Solve : Forfiles question?

Answer»

I'm trying to move files based on their AGE and from what I've learned from other posts on this forum but have run into a wall.

In my example I'm wanting to move .mp3 files from a directory to a sub-directory:

FORFILES /M *.mp3 /D -15 /C "CMD /C MOVE @File C:\Music\Temp"

The batch file is in the directory C:\Music, which is where the .mp3 files are located.

I'm doing this on a Windows 8 Pro machine.

Thanks for any assistance!I MAY have answered my own question: This doesn't work on Windows 8. Just tried it on a Win 7 OS and was successful.

I guess I should have taken the notes at their word...

Thanks to anyone who puzzled over this!Forfiles comes with Windows 8 so it should work.

Your command will fail on filenames with long filename elements - try this (UNTESTED):

Code: [Select]FORFILES /M *.mp3 /D -15 /C "CMD /C MOVE 0X2[emailprotected] C:\Music\Temp"Thanks! I'm not SURE why it worked in the original format on Windows 7. I thought it was weird that Windows 8 would take a stop backwards...

Thanks again for your response! I'll try it.

Kevin

7774.

Solve : Loading a DOS program without floppy discs.?

Answer»

I'm interested in installing/using 'DrawPerfect for DOS 1.1' in WinXP/Sp3 because it a has a unique (?) way of drawing circles - namely by selecting the centre and adjusting the radius. WinXP/SP3 copes perfectly well with running the sister program WordPerfect for Dos v5.1, so I expect that DrawPerfect would do so likewise. The DrawPerfect program installed from several Floppy discs. I no longer have the discs, but I had copied the files from them into ONE folder on C:\. If I click on Install.exe, it eventually instructs me to put the first floppy disc into Drive C. I would like guidance on how I can progress from this point, since I have no record of what the contents of disc #1 were, nor how to point the installer to them.Its calling for the disk as part of the anti-piracy control that was programmed into it. We cant aid in cracking software to install no matter how old it is.

Your best bet is to contact the software manufacturer if they still EXIST and see if they have a solution for you, or find it for SALE on ebay etc if any are to be found. Then the fun begins if its on a 5.25" floppy and you are running Windows XP and will need to find a old floppy drive A: B: Cable with the twist that has the modern floppy connection to the motherboard, but the older BLADE connection or get the blade to modern conversion adapter and use a modern floppy cable.Maybe one of these blokes has the answer

http://www.wpuniverse.com/vb/showthread.php?35705-Installing-DOS-program-without-floppy-discs&p=245339

http://www.bleepingcomputer.com/forums/t/512478/loading-a-dos-program-without-floppy-discs/

7775.

Solve : how to count process?

Answer»

Now I have two batch job and primary batch job call secondary batch job and I want to COUNT number of run time of primary batch job No sure what you NEEDED, but this piece of ragged CODE will keep a running count. PLACE it in your primary file.

Code: [Select]
@echo off
if not exist countfile echo 0 &GT; countfile
for /f %%a in (countfile) do (
set /a newcount=%%a+1
)
echo %newcount% > countfile
set newcount=


Hope this helps.

7776.

Solve : XCopy moves no files but debug claims it did?

Answer»

Greetings,

Long time reader, the site and forums has tons of info. Thanks for everything you have all contributed.

Below is a script I wrote to make a backup of a networked location onto my local. The script CREATES a file for today in a location, and then uses that dynamic location to backup the files to.

Code: [Select]@echo off
set today="%DATE:~10,4%-%date:~4,2%-%date:~7,2%\LeadResources"
echo %today%
md "C:\BACKUPS\%today%"
pause
xcopy "P:\XXXXX\XXXX\XXX\XXX" "C:\Backups\%today%" /L /S /I /-Y /EXCLUDE:C:\BatchF~1\Backup~1\LeadBa~1\BackupExclude.txt >> "C:\Batch Files\Temp\BackupResults.txt"
goto :end

The script successfully creates the dated folder and the nested LeadResources folder from the md command, but the xcopy does not move anything over.

Looking at the BackupResults.txt file shows lines such as this:

Code: [Select]...
P:\XXXXX\XXXX\XXX\XX\ZZZZ\ZZZ.xls
P:\XXXXX\XXXX\XXX\XX\ZZZZ\BBBxls
298 File(s)

This output leads me to believe that xcopy is successful in copying the files, but the files are not in the directory.

Any help that can be provided would be very much appreciated, I'm at a loss here.Remove the /L switch from the XCOPY. You have XCOPY RUNNING in WHATIF mode, which simply displays files that would be copied.

Good luck. Well that is just plain embarrassing. I was under my own assumption that /L would just output a list as well as copy them.

Thank you very much.

7777.

Solve : mkconfig ldconfig help?

Answer»

Hello

I'm looking for mkconfig and ldconfig guide?

....how to USE these COMMANDS!

Can you help me?

Thank YOUYOU can try these links:

Idconfig

and

MKCONFIG

Good LUCK.

7778.

Solve : Desktop Shortcuts for Games??

Answer»

Hello to all,

I would like to know if it is possible to create a batch file which will create a Desktop Shortcut and a Start Menu Shortcut for a game I am installing.
The game is Soldier of Fortune 2. I am doing a CD to DVD conversion of the game.
To cut a LONG story short, the DVD asks for CD1 to be inserted near the end of the install, I can cancel the install but choose not to rollback the installation thus leaving the game fully installed except for the Shortcuts I mentioned.
I don’t want to go into the full DVD conversion process, but I will if it’s needed.
What I basically want to do is maybe use a batch file to create shortcuts to the exe file which starts the game. I am ALREADY using a batch file on the DVD to start the install.
I can explain all this in more DETAIL later.
FIRSTLY, I would just like to establish if this is remotely possible?
OS is XP Pro but I would like to think if it is possible that it could work on all OS’s.

Thanks

EDIT: After searching through the hundreds of messages here I have come to the CONCLUSION I am going to need to use a script.
Any help or suggestions are still welcome! I'm not aware of a way to create shortcuts in batch language. This little script will create a shortcut for the desktop:

Code: [Select]
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Notepad.lnk")
oShellLink.TargetPath = "c:\windows\system32\notepad.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "Ctrl+Alt+e"
oShellLink.IconLocation = "notepad.exe, 0"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save


You will need to adjust the parameters to suit your needs. For shortcuts on the start menu check out: The Scripting Guy for some ideas.

Do not mix scripts with batch files (different interpreters) but there is nothing preventing you from calling a script from within a batch file or using the Run method to call a command file from within a script.

Good luck.

7779.

Solve : Printing textfile over network with MS-DOS?

Answer»

I want to print a textfile from ms-dos, USING the print-command, and send it to a PRINTER located on the server.

Have tried various examples like:

print c:\MyFile.txt /NETWORKPATH:lpt1

however nothing seems to work.

Anybody got a clue? Try using the format:

print /d:\\servername\printername filename.ext

Good luck.

I managed.

You WRITE:

....net send lpt: \\SERVER_NAME\PRINTER_NAME

....{ENTER}....

....and then:

..........net send MyTextFile.txt lpt1:

...{ENTER}....

Don't FORGET to kill the printer connection with:

.....net send lpt1: /d

or it will also be killed when you log off.

Happy Me!I say:

net use lpt1: \\SERVER_NAME\PRINTER_NAME

{ENTER}

and then:

....print mytextFile.txt {ENTER}

Kill the connection with:

.....net use lpt1: /d

Happy Me!

7780.

Solve : Batch file to print a file through ms-dos?

Answer»

Batch file to PRINT a file through ms-dos by any printer CONNECTED to ssystem EITHER parallel or LOCAL or LPT

7781.

Solve : Handling files and folders with spaces?

Answer»

I allways get stuck with this!
In Windows I sometimes need to copy/move folders or files that have spaces in them i.e., My Documents.

I can manage this by using " " around the complete file or folder spec. But if I need to CD to a folder which has a space in the name I get stuck.

cd "My Documents" doesn't work.

Can anyone remind me and help me out?

Thanks
NigelYou need to use a full path name otherwise CD is relative to the directory you are currenly logged into.

cd "\My Documents"

HOPE this helps. Thanks SW,

That doesn't SEEM to work for me, sorry if I missunderstand.
I get PARAMETER format not correct - "\My

I am sitting in the folder with the My Documents folder in it.

Can you advise further? Does that work for you?

Thanks
Nigel
P.S. Thanks for the very quick response.try putting the \ before the "
cd\"my documents"Thanks again.
Someone else has pointed up PERHAPS the fundemental flaw in my working here.
I usually run 'command' to get a DOS window up, but if I run 'cmd' instead I can enter folders with spaces in the names and it works (WITHOUT parenthesis).

I think I am sorted.

Thanks for your help

Nigel

7782.

Solve : How to get part of the string from parameter?

Answer»

How to get part of the string from parameter?

I run a batch file which requried parameter like
abc.cmd query\check\test
In my abc.com i would like to create a directory like c:\query\check.
What will be command You didn't mention your OS, but this will work on some of them:

Code: [Select]
set dir=%1
md c:\%dir:~0,11%


I wish to run this command in Win 2000, Win 2003 and Win XP.

I had try the command but is not what been expected. .

With your code, let said I save it as test.cmd.

I run your command like below:

test.cmd abc\cde\XYZ

it create the abc, cde and xyz folder.

What I wish to get is

abc and cde folder only as xyz is my filename.

thank you.The response to your first post (which works by the WAY) was specific to the situation you PRESENTED. Now, not only have the delimiters changed but so have the lengths of the arguments.

Type set /? or for /? at any command prompt to see what your options are.

Using batch files with WIN2000, 2003, and XP is so 20TH century. Check out Script for more generic solutions.

Hope this helps. is there any substring, left, right, reverse or position function in dos? None whatsever. Did you check out your options with set /? and for /?. I apologize for my last post, it should have had a link to the Script Center where you can find tools and solutions for your needs.

Good luck.

7783.

Solve : create folder with yesterday's date?

Answer»

I want to CREATE a FOLDER with yesterday's date as the name of the folder. I am able to create folder with current date (24-08-2005) as the name of the folder.
I want to do this in Dos prompt.
See your other post for a RESPONSE. PLEASE do not DOUBLE post. Thank you.

7784.

Solve : To create a dir with yesterday's date?

Answer»

Hi,

I hv to back-up some files on daily basis. This requires creating a dir in yesterday's date and copying the files in this dir.

Since I want to AUTOMATE this process, a bat file file is required.

Any HELP will be highly appreciated

Thanks in Advance.

Regards
PrabsQuote

Since I want to automate this process, a bat file file is required.


Wrong. A command file is not required. What is required is a Windows Script that can handle date functions. While it is true that you can use the set instruction to perform rudimentry arithmetic, what do you plan on calculating when today's date is Mar 1, Aug 1, or Oct 1? or actually on any first day of the month? Unless you are prepared to write a boatload of IF statments, BATCH language is a waste of time.

Check out the Scripting Guys for better results.

Good LUCK.
7785.

Solve : Find occurences of programs in the DOS path?

Answer»

Does anyone know of a MS or 3rd party utility that will look at the DOS path, then search all entries in that path for occurrences of a program file, including folders on network drives.

For example, say my path is C:\;F:\UTILS and I am looking for an exe called EXPLORER.EXE, and EXPLORER.EXE lives in both of those folders, and also lives in C:\JUNK. Is there a utility that would locate EXPLORER.EXE in C:\ and F:\UTILS, but ignore the occurrence of EXPLORER.EXE in C:\JUNK, since that is not in my path?

Thanks,
Curt
This fall into the Stupid DOS Tricks category:

Code: [Select]
@echo off
if .%2==. for /f "tokens=1-26 delims=;" %%a in ("%path%") do (set pgm=%1 & call %0 %%a %%b %%c %%d %%e %%f %%g %%H %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z)

:loop
if .%1==. goto end
if exist %1\%pgm% echo Program %pgm% found in: %1
shift
goto loop

:end
set pgm=


Only checks FIRST 26 directories on PATH. Pass the file you're looking for as the first command line parameter.

Thanks Sidewinder... for a "stupid DOS trick", that's one smart little bat file!
The only problem is when the entire path contains a space (like Program Files), your bat file parses out each word as a separate folder to search.

I put double quotes around each of the variables to look like "%%a" "%%b", etc, and it works to keep the string together, except that for some reason the "if exist" line always tests positive therefore thinking it found a file called "" and displaying the message Program xxxxx.xxx found in "". It kind of works, but doesn't quite know how to test for the null string WITHIN double quotes.

Thanks again!
It was too much of a challenge for my one living brain cell to remember the alphabet again. This might be somewhat more readable:

Code: [Select]
@echo off
set var=%path%

:loop
if "%var%"=="" goto :next
for /f "tokens=1* delims=;" %%i in ("%var%") do (
set var=%%j
echo %%i>>Temp
)
goto loop

:next
for /f "delims=;" %%a in (Temp) do (
if exist "%%a\%1" echo Program %1 located in: %%a
)
DEL Temp
set var=


This solution cries out for a script where you can apply the KISS method (don't ask). Next time please mention your OS.

I'm using XP SP2.

Your latest bat file is slick. But for some reason (maybe because I use XP), I have to check for a space instead of a null:

Changed if "%var%"=="" goto :next
To if "%var%"==" " goto :next

for the IF to ever pass. Works GREAT. Thanks!

7786.

Solve : How to answer "y" in a batch file?

Answer»

I'm writing a short BATCH file and drawing a BLANK. I'm going to encrypt a file with GnuPG but as I encrypt it, it'll ask me a question and it wants a yes or no answer. Is there a way I can code this in my batch file?Possibly. Use a pipe.

echo Y | GnuPG parametersNope, it didn't work.

Is there another way I can accomplish this with some other sort of script?

I want to run a COMMAND, and then I want the script to be able to answer yes and hit enter. I would like this all scripted.Didn't work how? If you are expected to respond "Yes" not "Y" to the prompt, simply pipe the word "Yes"

echo Yes | GnuPG parameters

Othwerwise, I found some howto's at:

HTTP://www.gnupg.org/(en)/documentation/howtos.html

Hope this helps. write y in for EXAMPLE file.txt.

GnuPG parameters
that should work.

7787.

Solve : Controlling Ports through DOS?

Answer»

Does some one KNOW how to directly send data (Hex) to a port in PC through a DOS command? I did it once but forgot.Maybe you mean DEBUG?

ULI

7788.

Solve : directory wont switch?

Answer»

hi

i'm using xp pro and when i try to SWITCH drive from the command line - (its set as a default network drive F:) to the c: it bounces straight back to the f:

WHATS causing this ?

cheers

chris Is there any ERROR MESSAGES that come up like "The SYSTEM cannot find the drive specified" or anything like that?

[glb]Gizmo73[/glb]In windows xp, to change the drive you are in you type the drive letter and a semi-colon, you do not use the cd command. For example, if you are in c:\ to get to drive f you would type ' f:' Hope that helps.bingo. thanks.

7789.

Solve : Merging files?

Answer»

Hi,

Is it possible to do the following things :

I'd like merge from a directory the CONTENT of all file with same EXTENSION (e.g .txt) in an output file but I would like also merge the file name with the content of file on the same line.

e.g:

file 1 : file1.txt (content : 'Content of file 1')
file 2 : file2.txt (content : 'Content of file 2')
file .....

and the output file need to be like this

output file.txt :
file1Content of file 1
file2Content of file 2
file.......

Thanks for your help

Mio66
SURE, it's possible, but DOUBT if it can be ACHIEVED with scripting. Sounds more like a job for a self written prog!copy con may be doneCopy con?? Example please

7790.

Solve : Change current directory?

Answer»

Please can somebody tell me how to CHANGE the "current
directory" of ms-dos I`m using windows XP. Thanks.Go here HTTP://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_o.mspx]

&AMP; click on Command-line reference A-Z then C then SCROLL to Chdir

Good LUCK

7791.

Solve : automating file transfer?

Answer»

hi


i wish to do the following. i'm running win2k on an NT server

i have a file that I have to copy to 7 different directories on a regular basis. The file which i have to copy changes each time i'm supplied with a new one. I therefore wish to SET upan automated routine that will take the file which i'm supplied with and import it into each of the 7 direcories, can anyone suggest how i'd do this ?

Is this achievable using dos ?

cheers

chrisHow bout this: Create a batch file CALLED COPY7.BAT that CONTAINS these commands:

@echo off
copy %1 \loc1\*.*
copy %1 \loc2\*.*
copy %1 \loc3\*.*
copy %1 \loc4\*.*
copy %1 \loc5\*.*
copy %1 \loc6\*.*
copy %1 \loc7\*.*


If you want to copy a file called COPYME.TXT to those 7 locations, just issue the command COPY7 COPYME.TXT.
The \*.* at the end of each COPY line assures that if you specify a non-existent folder, that you'll receive the message "The SYSTEM cannot find the path specified", as you should. If you do not include the \*.* and the folder loc1, loc2, etc do not exist, you'll get seven files named loc1, loc2, etc that each contain the contents of COPYME.TXT.
cheers curt, works perfectly

7792.

Solve : net send options?

Answer»

Have a small network using Win 200 server and Win XP on the workstations. Have a .bat file on the server that sends a message to users, using the "net send" command, to STAY out of system. Then another .bat with a "net send" command telling everyone to get back in.

Question is this - both "net send" commands display a small window on each workstation with the chosen message, in the same location. Is it possible to ALTER the position that the message displays or can you CHANGE the size of the window.

I need to make the two MESSAGES different so that users can notice each better.

7793.

Solve : answer yes to a registry change in bat file?

Answer»

I did run a search and saw the post by Sidewinder but I added yes to the batch file but it didn't work.

I have a batch file that copies a bunch of files to a computer for a hot swap. A couple files need to be run to make the computer ABLE to run the data acqusition program. The lines I have in the batch file that I am wondering about are:

C:\Pitram\DualScreen.reg ECHO Yes
C:\Pitram\Transfer.reg echo Yes

I'm pretty new to all of this batch file stuff. So I don't know if I am even using the right syntax/format. All I want it to do is run those reg files and answer yes, otherwise the dispatcher will have to click yes on the windows that will pop up. Which isn't a big deal but it would be nice to have the batch file do it for them.

Any comments are appreciated!

Thanks

PeteNot all programs are written to accept parameters from the command line.

You could try using the pipe:

echo Yes | C:\Pitram\DualScreen.reg
echo Yes | C:\Pitram\Transfer.reg

Beware that not all programs will accept info from the pipe, but it's worth a try.

Good luck. Thanks Sidewinder for the help but it didn't work.

Is there a command that works like hitting enter?

Thanks!

PeteIs it necessary to type Yes and No all spelled out or are we talking about Y and N?

When sending info thru the pipe, it's necessary to echo exactly what is expected.

FYI: echo. will send an enter key with no data

Hope this helps. hello,

i am also new to these batch stuff and i was also searching for the same thing.

the echo Yes | C:\Pitram\DualScreen.reg does not work.

but is it possible to just create a new registry from the batch file its self.

so that there is no need to create a .reg file.

pleas help YES FINALLY....

i found a way to create a REGISTERY without using the *.reg file.

the syntex is like this:
reg add HKLM\(path) /v (Key Name) /t (key type) /d (the VALUE )

HKLM : HKEY_LOCAL_MACHINE
HKCU: HKEY_CURRENT_USER
ETC
i wanted to create a reg key for counter-strike. so that i dont have to enter the serial key of the GAME when i install the game.

my command will be like this

reg add hkcu\software\valve\half-life\settings /v valvekey /t reg_sz /d 5RP2E-EPH3K-BR3LG-KMGTE-FN8PY

if you still have any questions then type the following in command prompt
reg/?

7794.

Solve : Copying with Dos?

Answer»

Is there any way to copy from DOS so that when the DESTINATION is full it will not fail but will ask for a second disk to be inserted? I tried

xcopy c:\*.* d:\backup /S

thanks

SPlease ADVISE what your OS is and what kind of drive is D:?

7795.

Solve : non(?)-msdos commands?

Answer»

there seems to be some DOS(?) commands which are not dos (or are they?), like

netstat
arp
tracert
ftp
etc...

the pattern here is that these commands are related to the web, but I'm wondering why these commands don't SHOW up in the regular dos COMMAND lists, and how many other such non(?)-dos commands are there?

Quote

why these commands don't show up in the regular dos command lists


What command lists are you referring to? Commands are not specific to DOS but to the shell program and the technology provided by each Windows VERSION. Some of the newer commands have no meaning in older versions of Windows (commands relating to Active Directory for instance). Note: the shell program is different for Win9x machines and NT machines.

What OS are you referring to? Hi,

I run win98se.
I went to a few sites which specialize in dos, and looked up their lists of dos commands.

I have, on occasion, used commands like ping, tracert and netstat, and I couldn't find these commands in the dos command lists that I have seen recently.

My cable connection sometimes "dies", and I have to reboot windows to get it going again.
So I've been looking around for a command I could run in the Run utility to re-connect instead of having to reboot.

Is there such a command?
Check out Win98 Commands. Scroll down to Chapter 7. If you have questions on how to run any command, type commandname /? at a prompt.

Need more info about your network. When the connection "dies" what do the LIGHTS on the modem or hub or router or switch look like? Sometimes just unplugging the device, waiting 30 seconds, then repowering will take care of this. This works more often than not. You shouldn't have to boot the PC. Not sure about Win98, but if you have a connection icon in the system tray, right click and choose the repair option.

Thanks for the help

I will investigate what you suggest.

7796.

Solve : FOR Command Help?

Answer»

The CODE I write is as below

set n=1
set /A n =n + 2
echo %n%
FOR %%c in (E:\Temp\Temp_Bat\testvec\*.*) DO (
echo %%c
@ECHO off
set /A n =n + 1
echo %n%
)
pause

The value of n is updated to 3 before the for loop.
But, I want the value of n should be incremented by 1 at each time inside the for loop. But Its not happening.

How can I do this?If you move the echo %n% statement past the CLOSE paren of the FOR, you will see that it does in fact work.

I can't explain it but if you find an explanation, please post it. Should make for some interesting reading. To make this work correctly we must force the variable %var% to be evaluated during each iteration, using the CALL :subroutine mechanism:

syntax-FOR-List of numbers
FOR /L %%parameter IN (start,step,end) DO command

******************************

echo off
cls
set xx=1
set var=0
for /L %%s in (1,1,10) do (
call :sub1
)
GOTO :end

:sub1
set /a var=var+xx
echo %var%
goto :eof

:end
echo "OK"


The same will work with files

syntax-FOR-File contents
FOR /F ["options"] %%parameter IN (filenameset) DO commandHi,
I want to display the folder content along with the incrementing the varaible.
For exmp
FOR %%c in (E:\Temp\Temp_Bat\testvec\*.*) DO (
/* If testvec contains 3 text files SAY 1.txt,2.txt,3.txt and n=3 before the loop

output should be

1.txt n=4
2.txt n=5
3.txt n=6

*/

the loop should execute for 3 times along with the varaibles should be increment ed 1 @ each time.

Can u plz will help in this regard

Thanx in advance


7797.

Solve : select a file with command for?

Answer»

hello watcher

i don't know what code i need to use here, hopely you guys can help me.
i got this code and i not realy understand the "for" command
so hopely somebody can help me

code i already got:
Quote

dir %userprofile%\Downloads /O:-D /B>%appdata%\.minecraft\accounts\downloads.txt
for /f "Delims=1" %%e in (%appdata%\.minecraft\accounts\downloads.txt) do (

set mineshafter_loc=%%e

)

the problem is, i did something frong at line 2
the downloads.txt file looks like this at my pc

Quote
craftbukkit-1.4.5-R1.0 (3).jar
SBTA_PCDRV1_WIN8_LD_1_01_0001.exe
technic-launcher-0.5.4.8.zip
TechnicLauncher.exe
Technic Launcher (1).jar
Minecraft Tekkit.rar
craftbukkit-1.4.5-R1.0 (1).jar
craftbukkit-1.4.5-R1.0.jar
Kapitel 4 Gesundheit.docx
minecraft (2).jar
Minecraft_Server (6).exe
minecraft (1).jar
Minecraft_Server (5).exe
NEDH3Dstudiewijzer periode 2 2012-2013.doc
Speedtest_TuneUpUtilities2013_nl-NL (1).exe
Agressie in de sport nederlands (2).docx
FI8903W.04W.05W-11.35.2.46 (1).zip
FI8903W.04W.05W-11.35.2.46.zip
FI8903W.04W.05W-11.25.2.46.zip
FI9820W-3.2.6.1.1-20120807.zip
Agressie in de sport nederlands (1).docx
IPCamSetup.exe
IP Camera Tool Mac MJPEG.zip
LB Photo Realism x256 8.0.0.zip
FI8903-04-fw11.15.1.42.zip
2[1].4.8.9.bin
foscam.zip
FI8904W_firm_11_15_1_46.zip
FI8903-04w-fw11.15.1.46.zip
FI8903-04-fw11.15.2.17.zip
Agressie in de sport nederlands.docx
another title (1).docx
H-app-33.1.1.35.bin
H-app-32.0.0.30.bin
F-app-7.5.3.46.bin
F-app-7.5.3.46_ATZ.bin
another title.docx
BP 1.1.0 Patch only.rar
SkypeSetup.exe
SkypeSetupFull.exe
Ethos LP-ep214.zip
solutions 3 H3 woorden A en B (1).xls
solutions 3 H3 woorden A en B.xls
Speedtest_TuneUpUtilities2013_nl-NL.exe
World!.rar
HOLY *censored*.png
2012-11-30_09.37.23.png
Ideeen Survival.txt
PS_AIO_02_USW_Full_Win_WW_130_140.exe
WoT_internet_install_eu.exe
WoT_internet_install_na.exe
worldedit-5.4.5.zip
craftbukkit-1.4.5-R0.2.jar
Terraria v.1.1.2.rar
Minecraft_Server (4).exe
kering project sketchup.skp
WP_000619.jpg
oCd-pack-14-by-disco.zip
PS3-64.zip
DS3 Tool.lnk
Minecraft_Server (3).exe
Progress Bar Code.txt
master.bat
vcredist_x86 (1).exe
vcredist_x86.exe
commandblocksigns (1).py
commandblocksigns.py
2012117_trainingsschema_officieel 2012-2013.xlsx
SethBling's Redstone Challenge Level 20 Lukelumia800.zip
sethbling_s_redstone_challenge.zip
CS6-AMTLIB-32-bit.rar
show_ads.js
Ghost.jar
InvTweaks-1.44-1.4.2.zip
ModLoader.zip
Stunzle v1.6 by Zinic.rar
ENG klas3 leesdos.doc
Book report year 3.doc
lastlogin (6) (1)
lastlogin (6)
lastlogin (5)
lastlogin (4)
lastlogin (3)
lastlogin (2)
lastlogin (1)
lastlogin (7)
lastlogin
Minecraft codes Generator.exe
CMD Accounts.zip
20100824mmp410nl.pdf
solutions 3 H2 woorden.xls
solutions 3 H2 woorden.oh4
craftbukkit-1.4.2-R0.2.jar
Essentials-2.9.4.zip
craftbukkit-1.4.2-R0.1.jar
worldedit-5.4.3.zip
craftbukkit-1.3.2-R3.0.jar
TooManyItems2012_10_28_1.4.2.zip
Minecraft_Server (2).exe
Kapitel 2 Total technisch.docx
Dropbox 1.4.20.exe
Minecraft_Server (1).exe
SimpleGameExtra.zip
The Walls 2 - PvP Survival - v1.00.zip
Minecraft_Server.exe
registrybooster (1).exe
registrybooster.exe
FlashDevelop-4.0.0-Beta2.exe
wallpaper_windows-7_animaatjes-36.jpg
wallpaper_windows-7_animaatjes-32.jpg
wallpaper_windows-7_animaatjes-30.jpg
ashbal-windows-7-wallpaper.jpg
world5.zip
A Puzzle for logan_ABC.doc
A Puzzle for logan.doc
PasswordProtect.jar
DOSBox0.74-win32-installer.exe
SteamInstall.msi
PasswordSafe.jar
world1.zip
world10.zip
sysbord151.zip
technic-launcher.jar
SinglePlayerCommands-MC1.3.2_V4.1.jar
Tut Rig For Download.c4d
Sentry 1.0.2.zip
Premium Minecraft Account Generator.rar
Minecraft.exe
Technic Launcher.jar
PanoramaKit v2.3.2.zip
MC 1.3.2 - Smart Moving 10.0.zip
jre-7u6-windows-x64 (2).exe
Mineshafter-proxy (1).jar
JavaSetup7u6.exe
jre-7u6-windows-x64 (1).exe
jre-7u6-windows-x64.exe
Checkpoints.zip
videoconverter_free.exe
jre-7u5-windows-x64.exe
Templates.properties
radmin34nl
radmin34nl.zip
mysql-connector-net-6.2.3 (2).zip
wiredcms.zip
ilost_catalogfix.zip
uberdb.sql
uberServer - Meth0d and iJakey.rar
R63_Remixed_Pack_rar.exe
dotNetFx40_Full_setup.exe
vcs_web.exe
xampp-win32-1.7.7-VC9-installer.exe
mysql-connector-net-6.2.3 (1).zip
mysql-connector-net-6.2.3.zip
TeamSpeak3-Client-win64-3.0.6.exe
NoLagg_v1.82.zip
vlc-2.0.1-win32.exe
NationaleVacaturebank_nl - sollicitatie vacature - Claimbehandelaar AOV.eml
cv Marianne Smitsloo.doc
cv Marianne.doc
craftbukkit-1.2.3-R0.1.jar
Mineshafter-proxy.jar
jre-6u31-windows-x64.exe
admin forcer.exe.eb9mskf.partial
DivXInstaller (1).exe
Mineshafter-proxy.exe
CNET_TechTracker_2_1_0_69_Setup.exe
imgconvert.exe
AdobeDownloadAssistant.exe
free_flash-intro-templates_y4yplyr7vonm1lar.zip
DivXInstaller.exe
SolveigMM_HyperCam_3_3_1111_16.exe
ImageIconConverter.exe
minecraft_modified.jar
minecraft.jar
RE_ Verzuimcoach _ casemanager _part-time_full-time.zip
GoogleSketchUpWNL.exe
blender-2.60a-release-windows32.exe
Blend_Trial_en.exe
FreeMouseAutoClickerSetup.exe
SolveigMM_HyperCam_3_3_1109_27.exe
Google_Gadget_NL.gadget
Teletekst.gadget
FlvPlayerSetup.exe
Spaans H1 moeilijk.mp3
wrts (2).mp3
Gente Joven HSt 1. ¶õ.9[1]. Nos vemos en el chat
HC2Setup.exe
jre-6u26-windows-i586-iftw.exe

i only want to copy the first file out this list in my batch file

hopely you guys can ride a code that works good
-lukeCode: [Select]@echo off
for /f "delims=" %%e in ( ' type "%appdata%\.minecraft\accounts\downloads.txt" ' ) do (
copy /b "%%e" "e:\target folder\"
goto :done
)
:doneJust for learning experience: 'set /p VARIABLE =So (using foxidrive's copy example) we can use:
Code: [Select]@echo off

REM This is where we gather the first line, setting it equal to the variable %a% (found right before the "=")
set /p a=<"%appdata%\.minecraft\accounts\downloads.txt"

REM Here we copy the file (I believe it has to be in the current directory [%appdata%\.minecraft\accounts\]) to target folder and or drive
copy /b "%a%" "e:\target folder\"

REM This is to pause the script when complete. Depending on the versions of windows you are using, it may do this automatically.
REM I know that Windows 7 closes the window almost instantly before ending, whereas Windows XP will wait.
pause>nul

REM If you are using Windows XP and you wish to have the file close when finished, end your script with the 'exit' command.



The 'for /f' command (the one used in your script) allows cmd to INTERPRET, line by line, a string of text, text file, or a command output. So say we wish to grab the last modification date on a folder (listed on the far left when using 'dir'). We could use 'for /f' to separate the output into chunks.
Code: [Select]for /f "tokens=1,5 delims= " %%A in ('dir') do (
if "%%B"=="DIRECTORY NAME" set lastModified=%%A
)
What this basically tells cmd, is that it wants to check the output of 'dir', and read it line by line. Because 'dir' formats it's information:
DATE TIME PM NAME
DATE TIME AM NAME
we can use "delims= " to separate the lines at each space. The other thing inside the quotation marks is "Tokens=1,5". This tells cmd to only look at the first and fifth segment (after the line is separated by spaces). This will get us only the date and name. The 'if' statement is thrown in to further sift through the results. It checks if the 2nd used token (#5) is the same as the desired directory, and if so sets the veritable %lastModified% to the first used token (#1).

This can be used with any command (enclosed in single quotes), string (enclosed in double quotes), or text file (is not enclosed). though it always reads only 1 line.

I hope this helps you understand 'for' a little better. It can be somewhat confusing at times.


EDIT: Be warned that the 'for /f' example only works if there are no spaces in the folder names.Thank you very much for the code foxidrive, the finaly code i used is:

Quote
@echo off
for /f "delims=" %%e in ( ' type "%appdata%\.minecraft\accounts\downloads.txt" ' ) do (
set test=%%e
goto :done
)
:done
echo %test%
pause

and thank you Lemonilla,
i understand it a little bit more

bye and thank you
7798.

Solve : Use command prompt to convert a batch of WP files to MSWord?

Answer»

My goal is to try and convert a large number of files in WORD PERFECT X5 to MSWORD files.

I would like have either a macro that will do this that i can RUN IN WORD PERFECT (I NEED it to run in WP)
OR
I would prefer to have a command prompt that can be set up so i can start a recursive batch SYSTEM that will do the word perfect conversion to word for me...

My files will be on my C:/ and the converted ones will also stay in the same place...Can anyone help me with this???

I have a MSWord 2010 macro THATD can run in a new module in a word file that does this perfectly, my problem is that i NEED it to run in Word perfect, i have attached that macro to see if anyone can manipulate it for me to work in perfect!
Or as i said help me with a command prompt.


Sub ConvertWPtoDoc()
'
' ConvertWPtoDoc Macro
'
Dim zSourceDir As String
Dim zDestDir As String
Dim zFileToCvt As String
Dim vFileName As Variant

'*** You need to provide info in each of the following 3 lines!!!
zSourceDir = "T:\WordPerfect_Files" 'Path to the WordPerfect files
zDestDir = "T:\Word Files" 'Path where convertd files are stored
zFileToCvt = Dir(zSourceDir & "\*.wpd") 'Get 1st Filename

Do While zFileToCvt <> ""

Documents.OPEN _
FileName:=CHR(34) & zSourceDir & "\" & zFileToCvt & Chr(34), _
ConfirmConversions:=False, ReadOnly:=True

vFileName = Split(zFileToCvt) 'Strip file type

ActiveDocument.SaveAs2 _
FileName:=Chr(34) & zDestDir & "\" & vFileName(0) & ".doc" & Chr(34), _
FileFormat:=wdFormatDocument, SaveNativePictureFormat:=True

ActiveDocument.Close SaveChanges:=False

zFileToCvt = Dir() 'Get Next Filename

Loop

End Sub

From Corel WordPerfect Office X5 Reviewer's Guide PDF file:

Quote

WordPerfect® Office Conversion Utility:
The WordPerfect® Office Conversion Utility
makes it easy to convert batches of any
document type that WordPerfect X5 can
open. For example, users can convert an
entire folder structure of Microsoft Word
documents to WordPerfect.
7799.

Solve : help---i am ms dos ignorant.?

Answer»

I have the zobot viruses and i believe it has infected my a drive and possibly my d drive. I run windows xp, and i am not sure how to get it into ms-dos mode or safe mode in order to run the norton antivirus emergency diskettes. Any help would be very much appreciated.I'm not familiar with Norton products, but to get into Safe Mode with all Windows O/S's, you can press the 'Function 8' or 'F8' KEY when your computer is first starting up, usually right after the BIOS screen. Just keep pressing F8 every second (time measurement, that is, 1 time per second) about 10 times & you'll get a boot menu, from which you use your up/down arrows to select 'Safe Mode', then press enter, press it again if you have to. You will go to a screen that tells you're in Safe Mode.

I use a Win98 bootdisk (floppy) to get into DOS.If you have a virues then why do you need DOS? If you put the floppy in it should run it, but I wouldn;t use emergency rescue disk because of one VIRUS unless it damage windows some how. I would just run scan clean it all up or use McAfee stinger program to get rid of it. If it is still there then google the name of the virus someone who have time to KILL will tell you how to remove it from MS-DOS in boot modeThe reason I need dos is because the computer shuts down after 1 MINUTE every time you log in. There is no time to do anything. It will not boot from A or D drive because this virus has infected those drives. Somehow I need to get around it.Well on startup if you have a startup disk. http://www.bootdisk.com you get get into MS-DOS that way. If you know how to run the floppy from there then it should be FINE. Your floppy should start automatically on startup. Check your boot sequence it should say A:/ first so it should run floppy first

7800.

Solve : Cannot open a file?

Answer»

Hi does anyone know how to get around this error:

A temporary file NEEDED for the installation could not be created or could not be written to??More info required.i downloaded nfs UNDERGROUND 2 from a p2p client and when i TRY to open it command prompt comes up for a second then dissapears. So i right CLICKED on it and selected run as... clicked OK and that error message come upI would be very suspicious of that activity
http://www.pandasoftware.com/activescan/
http://www.microsoft.com/athome/security/spyware/software/default.mspxok i type in nfs cd1 in the command prompt and i get:

program too big to fit in memory.