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.

4751.

Solve : update command prompt?

Answer»

I want to know if you can update command PROMPT and if you can how to do so.

T , ' ,
H , O O ,
A , ' , ,' ,
N , ' ' ' ' ',
K ,
Y
O
Ui looked google and microsoft.com
but no luck

all i can recommend is windows updatesThank you update command prompt?Quote from: BC_Programmer on June 08, 2009, 05:24:30 PM

update command prompt?
Exactly what I was going to ask. How/why are you doing this? What could this possibly accomplish? What possible additions would you add to the command prompt? Can you accomplish this without modifying the prompt?Quote from: batchmaster60 on June 08, 2009, 04:16:11 PM
I want to know if you can update command prompt and if you can how to do so.
if what you mean is you want to see more features and CAPABILITIES of cmd.exe, then no, i suggest you use a good programming/scripting language. Otherwise, i don't really think M$ would update. Or else you can switch to powershell...considered and "update" to me...
C:\>prompt /?
Changes the cmd.exe command prompt.

PROMPT [text]

text Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

$A & (Ampersand)
$B | (pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (greater-than sign)
$H Backspace (erases previous character)
$L < (less-than sign)
$N Current drive
$P Current drive and path
$Q = (equal sign)
$S (space)
$T Current time
$V Windows XP version number
$_ Carriage return and linefeed
$$ $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

$+ zero or more plus sign (+) characters depending upon the
depth of the PUSHD directory STACK, one character for each
level pushed.

$M Displays the remote name associated with the current drive
letter or the empty string if current drive is not a network
drive.

C:\>prompt $$

$prompt $T$G

21:15:18.56>prompt $P$G

C:\>thank you
for all of your HELP
4752.

Solve : Hidden Directory?

Answer»

I'm trying to remove a folder, and whenever I try to from windows everything crashes. Its not a system folder so I'm guessing a virus is inside and is trying to protect itself, because of this I'm now trying to use the dos prompt to remove it. When I type "rd messenger" it tells me that the folder isn't empty so it can't, having looked inside and not seen anything I'm guessing that a hidden folder is the problem. Does anyone know how I can remove a hidden folder without knowing its name? I've tried "attrib -h -s /s" on the advice of a friend but it doesn't work for some reason...What is the full path to the folder, how did it get created, and what does it contain?
If you don't want to get an antivirus then...
To delete a folder like this, you have to use DOS. (obviously)
You can try getting permission to open the folder, or give yourself Admin access. Right click the folder and goto properties, then go to sharing. You might be able to give yourself access by changing your permissions.
If you can't do that, then try deleting it with the command rmdir C:\whatever\directory /S /Q
If this doesn't work you can try going into safe mode, by PRESSING F8 at startup. You will see a _ blinking and that's when you get to that. Then you can try deleting with windows explorer, or DOS.
If that doesn't work you can try renaming the folder and deleting it. With the command rename c:\messenger differentname.
If that still doesn't work you can try moving the file with move c:\windows\temp\*.* c:\temp
Again if that doesn't work, omg... that's a *censored* folder...
You may try going into windows explorer and click tools > folder options > then show hidden files and folders. Then uncheck hide system files and folders. Now see if you can see any files in there or use
cd C:\messenger
dir
Then see if you can see any folders and trying to delete them like that.
Messenger (if your talking about msn messenger) is the DEFAULT msn messenger that you can delete.

Even another way to delete something like this...
For a desperate measure, you can try to use a Linux Live CD. Knoppix should work, and it should be able to delete that pesky folder.

good luckc:\documents and settings\robert\local settings\application data\microsoft\messenger

It was probably created by MSN, and inside it is one empty folder that won't delete itself. The other empty folder is my email addy, if that matters.


Second post:
I have F-Prot, but it closes every time it reaches that folder
I'm using the command prompt because I've found no way of getting into the proper dos, I'm running XP so I'm not even sure if dos is on the computer.
I've tried the "rd" command, its told me the folder wasn't empty so it couldn't do it.
F8 at startup brings me to a list of options, I've tried them and they just open in "windows safe mode". Its like windows except it annoys me. The virus still messes around in it so I've not tried very much in it.
I've renamed it, tried everything, and changed its name back. It didn't change anything.

I'll try your other IDEAS, except linux. I don't know anything about it and don't have any DISKS for it so I'll probably format the computer before I try it.

EDIT:
I moved it, changed the tools\show hidden files and folders, and then deleted the hidden folders (including a folder called "rhc55sj0ecer"). Thanks for all the help what happens if you

1. click the Start button
2. Click "Run"
3. Type cmd in the box & press enter
4. At the prompt, type

cd /d "c:\documents and settings\robert\local settings\application data\microsoft\messenger"

5. type attrib -h -r -s /s *.* and press Enter

6. type Dir and press Enter


I did try attrib -h -r -s /s *.* earlier, it didn't do anything though QUOTE from: owfio on August 17, 2008, 04:00:35 AM

I did try attrib -h -r -s /s *.* earlier, it didn't do anything though

You did not include the *.* in your earlier post.
Good point, I'll try that next time I have trouble. Thanks again for all the help There is most likely a virus in that folder. Quote from: qinghao on August 17, 2008, 03:48:34 PM
There is most likely a virus in that folder.
Or it doesn't exist........
4753.

Solve : Cut a text file after N specific strings found?

Answer»

Hi,
I have a big text file and I would like to cut it into 2, 3, 4, ... (x) files, depending how big it is.

I open the SOURCE file and I begin COPYING to the destination file (which has the same name with a digit at its end). When I find the search string I begin counting.
At the Nth string found I should create a new file and begin copying to it.

Below is the code I have but I can't detect the searched string.

Thanks for your help.

:: NAME : SplitInNFiles.BAT
:: USAGE: SplitInNFiles [device:][pathname]filename
@echo off & setlocal EnableDelayedExpansion

:: Check for the paramètre
set param=%*
if not defined param (
echo.
echo. Usage: split [device:][pathname]filename
goto :EOF
)

:: check if the file exist
set param=%param:"=%
if not exist "%param%" (
echo.
echo. File "%param%" not found
goto :EOF
)

:: EXTRACT the file name and its extension
for %%j in ("%param%") do (
set name=%%~dpnj
set ext=%%~xj
)

:: COUNT in how MANY files it should be cut
set nbTransac=700
set strSearched=String to look for

for /F %%j in ('type "%param%" ^| find /C /I "%strSearched%"') do set lgTrouve=%%j
set /A nbFichier = (%lgTrouve% / %nbTransac%)+1
echo %lgTrouve%
echo %nbFichier%

:: Verify if cut is necessary
set i=0
if %nbFichier% EQU 1 (
Goto :EOF
) ELSE (
:: Start spliting
set i=1
set N=1
type nul > "%name%_!i!%ext%"

for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
echo.%%k>> "%name%_!i!%ext%"
Set subStr=%%k:~0,12%%

rem GIVES ME AN ERROR! if %SubStr% EQU %strSearched% set /A N=%N%+1

:: Reset counts
if !N! gtr %nbTransac% (
set /A i=%i%+1
type nul > "%name%_!i!%ext%"
Set N=1
)
)

REM "delete original file"
)

:EOF
no need to reinvent the wheel....you can download GNU split utility (from coreutils) (see my sig for link). there are also plenty of tools capable of doing such task. just have to search for it.

4754.

Solve : search for files with special (names size and modified date)?

Answer»

wow ! at last i done it. i am now one step closer to the target

Quote

@echo off
setLocal EnableDelayedExpansion

for %%a in ("java2.exe") do set var1=%%~Za
for %%a in ("new install.exe") do set var2=%%~Za

if %var1% equ 275238 (
if %var2% equ 12543140 goto checktime

)

in above script you can now put lots of files and program will check their size (i put 2 files)
but now i need a pattern for compare and CHECKING files date with my values
any help or idea?
thanks use %%~tAsorry dear devcom
i forgot to tell you i tried your codes yesterday but maybe it's me that has problem not codes !!
i tried this

for /f "tokens=*" %%A in ('dir /b /A-D *.exe') do (
echo %%A %%~zA %%~tA
)
now i have this report in CMD window

Quote
java2.exe 275238 02/03/2008 11:50 AM

now what? how should i put these codes inside program?

i tried this (i removed file's size this time to find out what's the problem)

Quote
@echo off
setLocal EnableDelayedExpansion

for %%a in ("java2.exe") do set var1=%%~tA

if %var1% equ 02/03/2008 11:50 AM goto next
if %var1% NEQ 02/03/2008 11:50 AM echo>error.txt
)

i added red line to see which line has picked by program and always red line is selected !!
what's the correct pattern for putting file's date?

i even tried all below codes
Quote
02/03/2008 11:50
or
02/03/2008
or
2008/03/02

what's wrong?you need to add QOUTES on var and string you want to match becouse cmd thinks that 11:50 and AM are some commands so:

Code: [Select]if "%var1%" NEQ "02/03/2008 11:50 AM" echo>error.txt
that will work

i prefer only date so:
Code: [Select]for %%a in ("java2.exe") do set time1=%%~tA

REM GET DATE ONLY
for /f "tokens=1 delims= " %%a in ('echo %time1%') do set date1=%%a

if "%date1%" NEQ "02/03/2008" echo>error.txtwrong !!
hi dear devcom and THANK you very much for your cooperation
well your last codes did not work i don't know why ! i used following codes

Quote
for %%a in ("java2.exe") do set time1=%%~tA

REM GET DATE ONLY
for /f "tokens=1 delims= " %%a in ('echo %time1%') do set date1=%%a

if "%date1%" NEQ "02/03/2008" echo>error.txt

but i think there is something wrong . it always creates error.txt why?
i think NEQ means=not EQUAL . right? and equ= equal
so why it always create error.txt ? my values are not wrong. i even changed "02/03/2008" to anything example "02/04/2006"
and it still create error.txt so it will always searching for wrong values not correct values !! i replaced NEQ with equ and it did not worked. i mean this time did not create any txt so do you have any idea?
by the way in CMD report i see 02/03/2008 but java2.exe properties shows 2008/03/02 which one is correct?
4755.

Solve : Batch Multiple files for process?

Answer»

Well i have a lot of video's on my pc and i made a simple .bat encoder for them.
im not at my computer a lot so is there a way i can queu up a load of files without copy+paste the same script a load of times and editing.

I use
set VID=1.mkv

then call that file when it encodes.

is there a way i can like sequence a load of files?
so after 1 encodes it FINISHES then starts again on 2, and so on
like
set VID=1,2,3,4,5 .mkv

and when it does 2nd file
set end=Encoded-1.mkv
to rename the file to "Encoded-1.mkv,Encoded-2.mkv,Encoded-3.mkv" etc~

this would be great to get my encodes done while im away.so you want to load a group of files in sequence?, or you want to load a group of files in sequence and inbetween switching to the next file, you want it to run throught a section of commands?
what would be best is the ability to encode and entire folder.

here is some of my script

Code: [Select]set VID=1-INPUT.mkv
set avs=512x384Profile.avs
set end=Final-ENCODE-01-OUTPUT.mkv
x264.exe 1st pass
x264.exe 2nd pass


thats the simple version.
is there anyway to make this encode one file after another or do a folder then output to another folder?well, you could try dumping the files you wish to run your batch file encode on into a processing folder and then do something like this to loop through all the files in there. (This example works on all DVR-MS files in a folder)

Code: [Select]FOR %%G IN (*.dvr-ms) DO (
REM You can set an environemt variable to the
REM filename being looped through each time like so...
SET FILE=%%G
SET FILE
REM Or you can just pass in a couple of parameters
REM which you can access in your encodemystuff
REM routine using %1 and %2 to reference them,
REM where %1 is the filename and %2 is the
REM EXTENSION with the leading dot.
call:encodemystuff "%%~nG" "%%~xG"
)

:encodemystuff
your bat goes here...
echo %1
echo %2
echo %FILE%


Now if you want to get really tricky, apparently you can rename your .bat to .cmd, and then in Windows GUI you can simply drag the files onto your .cmd for them to be processed. ALAS, I haven't quite figured out how to do that yet!!

i understood 0% of that. im really a complete novice sorry.

any better explaination?Well still no noobie help.

my script is PRETTY complicated

it extracts video, encodes and then encodes 2x audio channels and finally puts them all together into 1 file.

is there a way to have 2 FOLDERS named: Input and Output
and it would change the input name for the file and the output so it's the same name when it's done? and would loop untill all the "Input" folder has been completed and output folder is full of encoded.

if you can understand me, because i dont think i do myself

4756.

Solve : suppress an error message..???

Answer»

if there is no disk in dir a:\ and i do "start a:" in cmd-batch, is there anyway to suppress the "Windows - No Disk" Error message that pops up..??Code: [Select]if exist a:\ start a:didn't WORK...
the "Windows - No Disk" Error message still pops up..??
Try this

Code: [Select]dir a: 2>nulwhat if i want to use this code
TYPE "C:\1.TXT" > "A:\1.TXT"
but there is no disk in drive A:\
And the "Windows - No Disk" Error message still pops up..
Is there anyway to suppress it now..??did you manage to hide the message with

dir a: 2>nul ?

if the ANSWER is yes, try this


dir a:>nul 2>nul && TYPE "C:\1.TXT" > "A:\1.TXT"

Why are you using type instead of copy?


yes the message did not show with dir a: 2>nul
but i dont want to use the DIR command BECUASE if no files exist in A:\ then your code
dir a:>nul 2>nul && TYPE "C:\1.TXT" > "A:\1.TXT"
will not work propperly...!!!

is there anyway to suppress the error message using this "If Exist A:\ TYPE "C:\1.TXT" > "A:\1.TXT"Quote from: gumbaz on October 13, 2008, 12:15:18 PM

yes the message did not show with dir a: 2>nul
but i dont want to use the DIR command becuase if no files exist in A:\ then your code
dir a:>nul 2>nul && TYPE "C:\1.TXT" > "A:\1.TXT"
will not work propperly...!!!

Have you tried it?

if a formatted floppy is in the drive then a: exists then dir a: will work the output goes to nul so you don't see it and the && test is passed and the type "C:\1.txt" will happen. (unless the floppy has the write protect switch in the protect position)

if a: does not exist then dir a: will not work and the && test is failed and the type C:\1.txt will not happen

Maybe you don't know what && means?

And why don't you answer about why you are using TYPE instead of COPY?
yes i tried it..
like i said though if there are no files or folders in A:\ Dir A: will fail
i tried on my usb drive E: your code dir E:>nul 2>nul && TYPE "C:\1.TXT" > "E:\1.TXT"
there were no files or folders on the drive so Dir E: failed and so did the rest of the code..

i use TYPE instead of COPY becuz i don't want to use any external copy.exe

like i say earlier...
is there anyway to use this >nul FEATURE in this code
"If Exist A:\ TYPE "C:\1.TXT" > "A:\1.TXT"Quote from: gumbaz on October 13, 2008, 01:17:58 PM
i use TYPE instead of COPY becuz i don't want to use any external copy.exe

There is no copy.exe in Windows. Where did you get that idea? Copy is an internal command just as type is.

Quote
like i say earlier...
is there anyway to use this >nul feature in this code
"If Exist A:\ TYPE "C:\1.TXT" > "A:\1.TXT"

Try this

XCOPY A:\Is_Ready.Test > NUL
IF NOT ERRORLEVEL 4 ECHO Drive is ready.
4757.

Solve : Permanently shutdown "wmiprvse.exe"?

Answer»

Hello again!

I am trying to shutdown a process called "wmiprvse.exe". When i NOTICED it started i made a BAT to shutdown the process, but it start again after a few seconds.

This is what i have.
Code: [Select]taskkill /f /IM wmiprvse.exe /T
Any ideas?This is one of those services you DO NOT want to disable...This is something i would like to disable.

http://www.neuber.com/taskmanager/process/wmiprvse.exe.html
interesting...
but maybe not shutdown completely.
just put it on startupHave it your way.
When certain Windows functions no longer work at least you'll KNOW the cause...second thought:
run a scan with an antivus

avg free
Code: [Select]http://free.avg.com/
run the scan for the "bad" wmipvse.exe
Code: [Select]http://www.neuber.com/taskmanager/index.html

if your going by the comments on that page it might be useful to know that half of the people aren't referring to wmiprvse but rather to a trojan infected copy of it. (or simply a malware program of the same name)yea, thats why i posted the "second thought"
and to run the scan, etcWell, i am certain its not a virus. It is just something i would like to not have run. We are trying to limit are students as much as possible here. They can be fairly malicious.well if you are not certain, i advise you to leave it alone

has there been any problems?instead of killing the process, actually stop the services, in the services snap-in (services.msc)

there are three involving WMI. just take note that this will render some log-on scripts useless and also possibly introduce other issues with management of the PCs and network.Just a question here in response to the fact that this is to keep students at bay..... You can use Group Policy and Lower User Privileges to keep the system safe without butchering services. Is the service shutdown only being used because it is the easiest vs GP or Permission changes?

I also agree that it shouldnt be disabled unless absolutely has to be.

Does your computers and network have protection to avoid thumb drive hacksaw attacks or bootable CDs etc and other bootable media that can ignore any system configurations. Most students these days will likely used the Pen drive / thumb drive hacksaw to take unauthorized control of computers with heightened credentials and hacking tools to read unencrypted traffic etc or plant junk or flip registry keys giving themselves administrative access to the local system. If they have access to a USB Port and/or a CD or DVD Rom and the computer(s) are not supervised while they are at them attacks like this will happen.

I remember me and my FRIENDS upset that some school computers wouldnt play games and we modified them to allow for games to be played etc back in 1992 through bootable floppy disks to boot our flavor of DOS and do whatever we wanted. Setting the computers back was a quick CTRL + ALT + DELETE and reboot and no one knew any better of our activities. Kids will be creative and will find a way if given AVAILABLE access to ports and drives.

The best system I seen yet was at the last college I attended that had PXE Booting over the network and running a Terminal Session of operating system of choice XP or Vista at boot prompt. System state was all at the server side and the local computers were acting as dummy terminals with a simple batch and PXE Boot instruction.

This setup had nothing locally that was able to be hacked and towers were all under lock and key with long cables feeding out to the display, keyboard, and mouse. It was suggested that to save your work you e-mail it to yourself for use at home or save it in your personal folder that was server side. In addition to this setup each time you logged off and back on again it wa a fresh new desktop, nothing was saved. So even if sometime tried to install or get infected it was wiped clean on reboot or shutdown.Unfortunately we cannot disable the USB port and/or CD-ROMs. They need them for home work and school work. The IT department at our location was recently replaced so we are just getting familiar with how things were setup. They didn't document things very well. As for the group policy question. Due to only have 1 DC for a staff and a student network, we have not been given access to create or modify GPOs. Our home office location takes care of that.Sorry, I may have been sleeping at the back of the class, but I fail to see the connection between limiting students and disabling wmipvse.exe.

Regards
Alan.
For USB Ports I would suggest editing BIOS of systems with password protection and disable booting through USB, this way the USB will operate, but cant boot hacksaws etc.

Then to hide the CD Rom Boot set it to the lowest of the order of initialization at boot Hard Drive Before CD-Rom so that the Hard Drive Kicks in and it never gets to the CD-Drive as a boot device.

Just be sure to set the password to something not easy to FIGURE out, but also not to lose it. Only way to get back in if you forget the BIOS password is to open the case and press a CMOS button to clear BIOS back to default. Students who are given access to these computers and if the computers are not supervised and cases available to be opened can also reset this button inside the case and get into the BIOS. Most students would not go this far as to opening the case. Some builds come with case locks to prevent intrusion to the inside of a computer requiring a key to unlock to be able to remove panels etc.

Good luck running the IT Department for your School

4758.

Solve : To encrypt or to make a exe type file of a batch file that no one may modify it?

Answer»

Sir,
I have CREATED a batch file having number of commands in it. But my problem is that any of my students modify it. and to correct it, I copy its content from .txt files placed any other place in computer.
I want to make it encrypted or exe type file of which contents are not in readabel format.
Can I make it. If yes, Please help me

Yours' sincerely
Lohani
[emailprotected]

email addy removed to prevent SPAM.Well you can have a series of batch files each being executed by another, and all of them located in different folders. EG.

Bat1.bat:
Your script here.

Bat2.bat
Start bat1.bat


And finally the last one will be the one your students run. They would have to be persistant to follow that around. you could simply re-examine their access RIGHTS- GIVE them read access but not write access, for example.Set the batch file to have read-only and system attributes. The system attribute prevents them from removing the read only status as system or hidden stati must be removed first. Quote from: Helpmeh on September 09, 2009, 01:44:05 PM

Set the batch file to have read-only and system attributes. The system attribute prevents them from removing the read only status as system or hidden stati must be removed first.

not file attributes, security attributes.

The file owner- them - can remove write access to the file to the "Everyone" group.Ohh. Right! I KNEW that lol!
4759.

Solve : restore partition?

Answer»

I don't know if this is the right forum to post this, but it seemed LIKE the best fit...

I've got a laptop (1 HDD, 2 partitions) that I would like to create a "restore partition" on (like Toshiba provides on their laptops).

The idea is to have one partition with the image file (along with ghost, and some kind of OS like DOS) and the other with Windows. I want to be able to boot into the "restore partition" and restore the Windows partition.

How do I do this?
-darrylYOU CAN USE norton ghost for this issue i THINK this will help u in ur problamQuote from: atulsingh001 on August 14, 2008, 06:37:38 AM

YOU CAN USE norton ghost for this issue i think this will help u in ur problam

I think he already KNOWS that

Use partitioning software to shrink the 2ND partition, then create a new FAT32 partition in the space made available, then boot with a DOS floppy or pen drive and run Ghost to make an image of your system partition in that partition.

In my opinion, you would be better off using an external hard drive to store the Ghost image, as if anything goes wrong with the disk, your recovery partition will be hosed too.
I used to use the Ghost to backup patiton when it's in good conditions,
and restore it when the system did not perform so well.

I think the way of he use the image file and my way are almost the same
4760.

Solve : Batch file to read date & time of text file & compare with Current?

Answer»

Dear,
How do i create batch file to read date & time of text file & compare with Current date & time to findout the difference between time & date.
Procedure required,
1) Read todays data & current time
2) Read contents of txt file which are date & time
3) compare step 1 with step 2
4) if difference is greater than 8 hrs kill the process called xyz.

please help me to solve.
thanx in advanceif you can USE vbscript,
for 1) to 3) , you can see here for some examples... USING Date (eg DateAdd,Datediff) functions from vbscript.
for 4), you can see here

Sorry but i am not much FAMILIAR with VB scripts.
can we do the same by using batch file only.Quote from: Yogesh123 on September 09, 2009, 04:21:25 AM

Sorry but i am not much familiar with VB scripts.
can we do the same by using batch file only.
if you are asking for a batch solution here, it shows you are not familiar with batch either. what makes you hesitate to learn about vbscript then? you are also expected to put in your own effort in the first PLACE.
4761.

Solve : Batch File Missing Files with xcopy?

Answer»

Hello,

I've made a BATCH file to copy some files/folders from one PC to another, but it's stopping unexpectedely in the middle of the process.

Here's the code:

---

@echo off
echo Hello, Welcome to your Backup WIZARD!
:escolha
echo Choose your OPTION:
echo 1 - LAN
echo 2 - VPN
set /p x=
if "%x%"=="1" goto lan
if "%x%"=="2" goto vpn
cls
echo This option doesn't exist.
goto escolha

:lan
xcopy C:\"Documents and Settings" \\Ibmservidor\Folder /S
goto end

:vpn
xcopy C:\"Documents and Settings" \\[VPN IP]\Folder /S
goto end

:end

--

Do you guys know what could cause this problem and/or how could I fix it?

Thanks!
Domingos

---

EDIT: I put a "pause"at the end of the code. It's not really stopping unexpectedly, it's just not coping everything: a folder with 250 MB was completely COPIED with 215MB.If it encounters an error at some stage it will display the error message and then exit. If you run it from cmd it should come back to cmd when the error occurs and you can read off the error message.

FBHun. It's not really an *error*, as I said in the edit line in the first post.

Sorry for the confusion =/ !What's it leaving out? presumably you know that the /s switch means it's not going to copy empty files...?

4762.

Solve : Auto defrag BAT file when fragmentation is above 5%?

Answer»

Is there a way to parse the -a switch response of DEFRAG to determine the level of fragmentation and if it is above a certain amount start DEFRAG c:.Yes. Parsing is easy

Code: [Select]@echo off
set vol=c:
for /f "tokens=1-9 delims=%% " %%A in ('defrag %vol% -a ^| find "Fragmented"') do set /a fraglevel=%%I
echo Volume %vol% is %fraglevel% percent fragmented
IF %fraglevel% GTR %whatever% defrag -blah blah blah
Thanks Dias - that worked. I don't do this for living so I can get into tro ;Duble very easily. Dias,

Would you please, explain briefly the code for me?

for /f "tokens=1-9
Why 1-9?

delims=%%
Why %%?

" %%A in ('defrag %vol% -a ^| find "Fragmented"')What is difference between using only "|" vs. "^|"?

do set /a fraglevel=%%I
Where does %%I come from? (can it be any other character or
it has to be "I"?

Thanks,
Geza

Quote from: Geza on August 16, 2008, 11:43:42 PM

Would you please, explain briefly the code for me?

I will do so briefly, but really you need to to study the "tokens=" and "delims=" features in FOR /F.

Type FOR /? at the prompt. Also search the web for guidance.

Quote
for /f "tokens=1-9 Why 1-9?

Because by selecting spaces and percent signs as token delimiters the defragmentation percentage figure is the 9th token in the output line of defrag which contains the figures, (the line which contains the word Fragmented which is selected by Find.exe)


A B C D E F G H I
1 2 3 4 5 6 7 8 9
25.49 GB Total, 10.25 GB (40%) Free, 6% Fragmented (13% file fragmentation)


"Tokens=1-9" FOLLOWED by "%%A in" means "set up 1 explicit loop variable (%%A) and 8 implicit ones (%%B to %%I)"

Quote
delims=%% Why %%?

Because to echo a single percent SIGN in a batch file you have to type %%

Quote
What is difference between using only "|" vs. "^|"?

Just using | in that place would result in a message "| was not expected at this time." The pipe character | needs to be escaped with a caret.

Quote
Where does %%I come from? (can it be any other character or it has to be "I"?

It has to be I. See my chart of tokens above. I chose %%A to be my first token, and I require to extract the 9th token, and I is the 9th LETTER of the Roman alphabet.


Dias,

Thank you for the explanation, it was very clear.
I LEARNED a lot more from it than by just typing "For /?" which is a typical Microsoft help, it does gives you an ANSWER but by itself it is useless.

Thanks!
Geza
4763.

Solve : Route Add?

Answer»

I am trying to GET connected to a clients FTP site.

I am being blocked by our router I had a route addess added but I cant remember what I did the first time.
Here is what I have been adding.

Route ADD 192.168.0.1 mask 255.255.255.255 192.168.0.3 metric 10 if 1

I also need to make it persistent was I can get it through. Any ideas on what the PICNIC is?For not I have figured it out. I out the destination to 0.0.0.0 as WELL as the mask and the GATEWAY to my default. That actually doesnt open up the route to just the external I need but to all the traffic through that router, so I will still need to figure it out but temporily I am operationl.

4764.

Solve : Backups batch file help.?

Answer»

I have a BATCH file that I used to zip Virtual machines up with (for backup).

I used to use the line below successfully for the other version:
for /F "usebackq tokens=1" %%i in (`cmd /c "vzcfgt get %1 GUID"`) do (
set vid=%%i)


The vzcfgt command returned a folder name. (This is for a virtuozzo server)

C:\>vzcfgt get 101 GUID
{4B6944CA-73D3-4E3B-80BA-215374548822}


That command no longer returns the folder name. I need to use vzbackup list %1 now.

C:\>vzbackup list 101
listing...

VPS 101
backup ID
66a9c707-8bdf-42e0-8cf0-2ab3777e7839/20080804202501
66a9c707-8bdf-42e0-8cf0-2ab3777e7839/20080805183923

My problem is that I don't know how to read just the first 'x' characters of the INPUT from the command. I've tried different THINGS that I've found on this site.

This is what I have right now:

for /F "usebackq tokens=1" %%i in (`cmd /c "vzbackup list %1"`) do (
set vid=%%i:~0,25)


Any help would be GREATLY appreciated.This might work:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /F "usebackq tokens=1" %%i in (`cmd /c "vzbackup list %1"`) do (
set vid=%%i
set vid=!vid:~0,25!
)

4765.

Solve : How can you place a variable within a variable in batch file programming??

Answer»

I have been trying to create a batch file which outputs text followed by a respective number value, to a text document. My problem is that in order to do so, I need to place the variable %value% (in example below) within another variable.

I have been tearing my hair out - so any help would be greatly appreciated!

Note: the following example is not the exact task I am trying achieve but is a SIMPLIFIED example of the task, and I would probably prefer to limit the programs used, to batch programming and VBS script.

@echo off
set /a value=0
:start
set /a value=%value% + 1
set /p time%value%="When do you wish to begin your task?"
echo %time%value%% >> "Time Schedule.txt"
cls
choice /m "Do you wish to input another task?"
cls
if ERRORLEVEL 2 goto end
goto start
:end

Thanks in advance call echo %%time%value%%%Try not to use the TIME variable as it always changes. Set it as something like TME and use that variable instead. Quote from: Helpmeh on August 29, 2009, 05:03:09 AM

Try not to use the TIME variable as it always changes.

Please explain in the context of the posted script.

ThanksTry not to use %time% (the time variable) very often, as it always changes depending on the SYSTEM time.
Try this script and see what I mean. Time contains: hours (in 24hr format), minutes, seconds and milliseconds.

@echo off
echo %time%
ping localhost -n 1 > nul
echo %time%
pause > nulSure the System environment variable is changing every millisecond but what about Time set in the Command shell or Local environments?

A script running in either of those environments sets VARIABLES only for those environments not for the system so if Time is set in either environment the system environment variable remains unaffected and the variables set in Cmd and Local environments are fixed until changed within those environments or until the script finishes or until Endlocal is processed.

Try this:
Code: [Select]@echo off
cls

echo Echoing the time variable...
echo System environment time=%time%
echo.

echo Setting Time in Cmd shell environment to abcdefg...
set time=abcdefg
echo Echoing the time variable...
echo Cmd environment time=%time%
echo.

setlocal
echo Setting time in Local environment to qwerty...
set time=qwerty
echo Echoing the time variable...
echo Local environment time=%time%
echo.

echo Accessing System time from the Local environment...
set time=
echo Echoing the time variable...
echo New System environment time accessed from the Local environment=%time%
endlocal
echo.

echo Returning to Cmd time...
echo Echoing the time variable...
echo CMD environment time is still set to=%time%

Echo.
echo Returning to System time...
set time=
echo Echoing the time variable...
echo System environment %time%
Thanks guys - problem solved!

Particularly to 'Prince_' and i also learnt something from 'Helpmeh'

I wasn't looking for any WAY to set the actual computer time, just a way to use a variable with the name time in it (resolved by using 'tme' instead).
It was just a matter of placing an extra grouping of '%'s around the variable

ie
not echo %tme%value%%

but instead echo %%tme%value%%%

Thanks to everyone that replied
-Danielsrry. just found out it hadn't actually answered my problem but I found a great website that had already solved the problem:

http://www.codeproject.com/KB/winsdk/Batch_File_Bubble_Sort.aspx

Thanks for all ur help !
4766.

Solve : Is GOTO illegal in a FOR LOOP - i.e. FOR %%X (*.*) DO ( loop code )?

Answer»

My TEST.CMD file shares a folder with ToBAK.CMD.

The code appended below fails, it produces
Quote

- 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK
- 12 - 2 - ToBAK.cmd - %Y - %~nY
Press any key to continue . . .

By simply changing "SET MAX=2" to "SET MAX=1", the "GOTO L2" does not execute and I get the "correct" result :-
Quote
- 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK
- 13 - 1 - test.cmd - test.cmd - test
Press any key to continue . . .

My Conclusions :- execution of "GOTO L2" results in
a) Total loss of the value of %%Y the second time around;
b) Subsequent failure of the FOR (*.*) loop to process the second file.

Code: [Select]@ECHO OFF
setlocal enabledelayedexpansion
SET MAX=2
SET N=11
FOR %%Y in (*.*) DO (
SET Z=%%Y
SET /A N+=1
set P=0
:L2
SET /A P+=1
ECHO - !N! - !P! - !Z! - %%Y - %%~nY
IF !P! LSS !MAX! GOTO L2
)
pause

N.B. The above code illustrates the peculiarity I am fighting.
The real code I attempting has the same basic form with the exception that instead of a harmless "ECHO %%Y" etc. I am trying to do more DANGEROUS things involving the creation of new sub-folders and relocating precious archives into the new structure.

I am now thinking I can replace the 4 LINES of ":L2 ... GOTO LOOP L2" code with a single line "CALL :LOOP2" and that can have the secondary iteration code.

Any advice will be appreciated, but much as I want to finish my present project, I wish now to learn about this peculiarity, and anything I have done wrong, and how to avoid this sort of problem in future.

Regards
Alan
You could try and do something like the following:

Code: [Select]FOR /f "usebackq" %%Y in (*.*) do (
SET Z=%%A& SET /A N+=1& SET P=0 & CALL :L2 %%A
)

:L2
Thanks

I have made a start upon using CALL :LOOP2 whilst awaiting further feedback.

I am hoping for an explanation of why GOTO trashes a FOR LOOP so I will know what to avoid in future.

Incidentally, I recognised "usebackq" and ran "FOR /?" to find out more
- I still have not got to grips with it.
I did alter my code to
FOR /f "usebackq" %%Y in (*.*) DO (
and all I got was
Quote
The system cannot find the file *.*.
Press any key to continue . . .

Regards
Alan
what information are you trying to set in the variable Z? Right now this will run against any files in the current directory for the batch file. if you are trying to pull data from a specific file you will need to replace (*.*) with the file location that has the information you are looking for. I never wanted Z in the first place.

The only reason I used "SET Z=%%Y" was because I observed that %%Y became undefined when GOTO L2 was executed,
therefore before it lost its value I used "SET Z=%%Y" to see if Z was more permanent.
I found that where GOTO killed %%Y, it did no damage to !Z!

I thought I had a perfect solution by using !Z! wherever I had used %%Y.
BUT THEN I added a second file in the folder and found that GOTO L2 not only killed the value of %%Y, it also caused "FOR %%Y ..." to forget where it was, and the subsequent file(s) never got processed.

The two lines of output were
- 12 - 1 - ToBAK.cmd - ToBAK.cmd - ToBAK
- 12 - 2 - ToBAK.cmd - %Y - %~nY
The second line shows that !Z! is still defined as "ToBAK.cmd"
but %%Y and %%~nY have become undefined and useless.

The eventual purpose of my project is to take a folder with disc partition image files such as
I:\Backups\2009_03_31_19_06_40_198D.TIB
I:\Backups\2009_04_05_18_49_38_184D.TIB
I:\Backups\2009_06_06_14_00_32_370D.TIB
Then for each such file create a companion folder such as
I:\Backups\2009_03_31_19_06_40_198D
Each of these companion folders will hold sub-folders such as
I:\Backups\2009_03_31_19_06_40_198D\2
I:\Backups\2009_03_31_19_06_40_198D\3
I:\Backups\2009_03_31_19_06_40_198D\4
Then "incremental" files such as
I:\Backups\2009_03_31_19_06_40_198D2.TIB
I:\Backups\2009_03_31_19_06_40_198D3.TIB
I:\Backups\2009_03_31_19_06_40_198D4.TIB
will be moved to
I:\Backups\2009_03_31_19_06_40_198D\2\2009_03_31_19_06_40_198D2.TIB
I:\Backups\2009_03_31_19_06_40_198D\3\2009_03_31_19_06_40_198D3.TIB
I:\Backups\2009_03_31_19_06_40_198D\4\2009_03_31_19_06_40_198D4.TIB

Regards
Alan
ok I think i understand what you are looking for let me see if I can get it working for you. Thanks, but I have the original code fixed as below.

The final implementation is coming along NICELY,
but I am taking it slow with lots of debug,
because my post above has glossed over many intricacies.

All I really need now is an explanation of what rule(s) I violated by using a GOTO within a FOR loop.

I appreciate that GOTO is not a nice WAY to break out of a loop
but I was staying inside the loop and cannot see why that gives disastrous results.

Code: [Select]@ECHO OFF
setlocal enabledelayedexpansion
SET MAX=3
SET N=11
FOR %%Y in (T*.*) DO (
SET Z=%%Y
SET /A N+=1
set P=0
CALL :L2 %%Y
)
pause
EXIT /B

:L2
SET /A P+=1
ECHO - !N! - !P! - !Z! - %1 - %~n1
IF !P! LSS !MAX! GOTO L2

Regards
Alan
4767.

Solve : Realms of *censored* version G?

Answer»

Updated Realms of *censored*,

http://realmsofhell.tk/


you can move back to main menu now
i added a BANK, i added a teleporter
bank works for multiple people, the MAP function DOESNT work everywhere

all three CONTINENTS are something like this

% % %
* * * *********** % - home
* * * % % % * - path
* * * * * * T ********** k - Kingdom
* * * K -* T - Teleport room/ bank room
* * * * * * * * * *well you made few mistakes:
* we have thread for apps/games
* you complied your game so someone may dont trust you and we cannot see code
* there are several error durning using the game
(this is my opinion)

but ANYWAY i think its a good code/game
4768.

Solve : Need help with..?

Answer»

I have a batch file and it waits for the user to write what to do,
but I want it to echo something if the user didn't respond after 10 seconds.

This is what I have so far:

Code: [Select]@echo off
title EXAMPLE
:firstcommand
echo WAITING for command:
set /p command1=
if /I %command1%==go echo thanks.
pause >nul
If it is possible please post an example Code: [Select]@echo off
title Text Wait
:NCA
cls
echo The Command resets after 10 seconds.
echo.
CHOICE /C:12 /N /T:2,10 Enter Command? 1 for yes. 2 for no.
if %errorlevel% equ 1 GOTO EC
if %errorlevel% equ 2 Goto NCB

:EC
cls
echo.Command?
set /p cmnd=
if /I '%cmnd%'=='test' (
cls
echo This works!
pause
exit
)
rem Enter rest of code here.
rem Make sure there is an exit or goto
rem that keeps the batch program from going
rem to the NCB label.


:NCB
cls
Echo A command wasn't entered.
pause
goto NCA
try this, this uses the choice command(you'll have to download the NT version of it and place it in your System32 folder) it waits 10 seconds and then echo's that a command wasnt entered.

hope this works for you
,NickWorked great! your welcome

4769.

Solve : clear print queue on a remote server?

Answer»

Hi everyone, I hope someone can help me out. I've got an older server running Windows Server 2003, and not very well. The print queue gets clogged up on a daily basis from teachers printing the same document over and over instead of waiting for it to come out. I have a simple batch file set up to stop the print spooler, delete the offending FILES, and restart the spooler. However, I have to log into the server each time. I'd like to put a batch file on my desktop to remotely delete the files. Below is the script I am using, can anyone help with modifying it to be able to do what I want?

@echo off

net stop spooler
del /f e:\spool\printers\*.*
net start spoolerI never realized it was so simple to delete files from the print spooler. Can you not map the server drive E: to your machine.

Code: [Select]@echo off
net use z: \\computername\share
net stop spooler
del /f z:\spool\printers\*.*
net start spooler
net use z: /delete

Note: the computername and sharename are references to the server. Type net use /? at the command prompt for full details.





I'll try it out. I'm not big on scripting, that's why I come to these forums No dice. I get an error about "The PROCESS can not access the file because it is being used by another file."
the script then restarts the spooler and deletes the drive. Any idea why this is HAPPENING? I am able to use my original script while logged into the server with no issues. Here is the script I am running, FOLLOWED by my original script on the server:

@echo off

net use z: \\servername\spool (I moved the queue to another LOGICAL drive to save space on C:\, and made "spool" a shared folder)
net stop spooler
del /f z:\printers\*.*
net start spooler
net use z: /delete

pause (so I could read the msgs before the window closed.)


OLD script on server:
@echo off
rem old spooler
rem del /F %SYSTEMROOT%\system32\spool\PRINTERS\*.*

4770.

Solve : Combining DBF files?

Answer»

I have 1508 DBF files that need to be combined into ONE FILE. Each file contains different data but all have the same column names. Is it possible to combine them using a dos command?
Thanks!
There are lots of different types of DBF file, but you have not TOLD us which database program these files came from. If they came from Foxpro, you could try a Foxpro program such as the following

This is not a batch file

Code: [Select]Select one database as your main file, which all records of the OTHERS will be appended into. Place all of the other ones into their own directory. This directory should hold only those other databases, no other files.

USE mainfile
SET DEFAULT TO <pathAndDirectory>
=ADIR(laDBFs,'*.dbf')
FOR lnDBFcnt = 1 TO ALEN(laDBFs,1)
lcDBFname = laDBFs[lnDBFcnt,1]
APPEND FROM &lcDBFname
ENDFOR
RETURN

4771.

Solve : Stack Overflow?

Answer»

Hello,Hope someone can help me,i just got a Old 486 Ibm thinkpad Labtop computer from a yeard sale the other DAY,it had windows 95 on it."i notaced it would sometimes stop with a stack overflow message when i would start the comeputer and boot windows 95". well anyway it was a trashy install so i just thought i would reinstall windows 95. so being it dont have any cdrom drive,no usb ports,i had too use floppy disk(s).Well anyway now i wiped the old windows 95 now i cant reinstall windows 95. I Keep getting a stack overflow message,telling me to increase stack settings in config.sys.Well it dont make any sense as there are not any dos apps booting up.autoexec.bat is blank! "The install files are already on the hard drive!so i need SOMONE to tell me what could be worng.it dosent matter if i boot up to a Fresh bootdisk,i always get a stack overflow message.Could somedody Please help?
Its my first labtop.LOL very old i know.but just something to play with.it just dont make any sense. ""i Tryed Increaseing stacks settings by PUTTING a setting in config.sys" it dident help...

Specs..

IBM Think Pad 360CE

Type /MODEL 2620-90F
S/N 78-FVK11

Processor 486 DX2

Memory 20MB
I have looked on IBM's website and googeled it but could not find any info on this computer as it is too old!
funny i did FINDOUT that the computer was made in 94 yet the bios date is 96....
hmm, I have a thinkpad 755CDV, very similar.


try this.

Since you have another PC to work with.

take one of your fresh boot floppies. create "config.sys" on it, as follows:

Code: [Select]STACKS=64,512
FILES=60
BUFFERS=40

try booting the laptop with the floppy.

you might find more insight on the issue here:

http://support.microsoft.com/kb/145799

Thanks for responding...No luck,i tryed what you said ,but after i booted up and i just typed " dir " same thing i got ......"A internal stack overflow has caused this session to be halted.Change the stacks setting in your config.sys file and then try agian."
So now i cant even Reinstall windows. It just dont make any sense.....Any ideas...?
could be a hardware issue, maybe even a motherboard failure.Well ,Maybe...because theres no other logical thing that would be makeing it do it...
i rebooted agian and it said the same thing about 3 sec after it got to the dos prompt...i dident type anything...ummm...not logical.....i wish i could find the manual for it on line......Well, my laptop is similar, it recently STARTED a similar symptom, except instead of a stack overflow, it constantly says "Divide by zero".

It all started after it's battery started leaking. does your laptop have a battery? perhaps try removing it, and running from AC only, if possible.

4772.

Solve : Updating the file based on the location using a batch file?

Answer»

Hi,

I am very naive to "batch file programming"

Basically i want to achieve, the following

I want to update a list of file names (along with extension) at a
particular position in a text file., using a batch file.

For instance,

If the current directory has "a.c and b.c" files, and there is a text file named "code.txt", which
has the following pattern

SOURCES= \
..\a.c \
..\b.c \

If i run the batch file, i would like to search for string SOURCES in the code.x, update the file names (with *.c) at the desired LOCATION as specified above

Please help me in providing information, any example code or any other link which gives information in achieving the same

Many thanks in advance,

Regards, tspso what is the final output of your code.txt look like? describe PROPERLY what you want...what do you mean by update the file names with ".c" is it you want to update your files in your directory?? or the contents of code.txt?If the format of code.txt is what you showed, then this should work.

@for /f "tokens=1-2 delims= " %%a in ('type code.txt') do REN %%a %%b

That should work as long as there are no spaces in the files' paths. I'm not 100% sure the second file (the name what it will be renamed to) requires a full path, but it won't hurt if it does.@helpmeh , the current directory already has a.c and b.c and the code.txt presented also has that....so i am not sure if OP's has described his REQUIREMENT properly.Hello,

Thanks for reply, and Sorry for not bringing the clarity at first shot !

The scenario is:
- A directory there are 2 files (a.c and b.c) - C source code files and a text file has " code.txt " file.
- Typically the code.txt could look like the following initially

< SOME TEXT - LIKE DEFINES >

SOURCES=

< SOME PATH - DETAILS >

- My objective is to find all the .c files residing in the current directory and place it in " code.txt" file
Considering the above scenario,

I need to create a batch file, which reads all the .c files and updates the code.txt file, such that after execution of the batch file, the code.txt file would look like:

< ADDITIONAL CODE - SOME TEXT - LIKE DEFINES >

SOURCES= \
..\a.c \
..\b.c \


< ADDITIONAL CODE - SOME PATH - DETAILS >

My objective is to create a batch file , which does the above !

Do let me know if in case am not clear

Regards, tsp

Hi All,

Or a simipler version of my requirement would be to

replace the output of

dir /b *.c command

in file code.txt under

SOURCES=/


Thank you,

Regards, tsp

4773.

Solve : Run an existing .bat & .vbs script from a .bat or .vbs?

Answer»

Hi

I would like to be able to call/RUN a existing .bat & .vbs file from a new .bat or .vbs. hoping this would include a POP up message to confirm the action has been completed.

I can add message to .vbs script ok MsgBox ("complete"), vbInformation, "Updated"

At the moment I have to run 2 scripts (.bat & .vbs) but I want to be able to call both and run both of these.

Thanks in advance for any helpC:\>type runany.bat
Code: [Select]C:\WINDOWS\system32\cscript.exe C:\WINDOWS\system32\eventquery.vbs

C:\>type runany.bat
Code: [Select]C:\WINDOWS\system32\cscript.exe C:\WINDOWS\system32\eventquery.vbs

c:\whatis.bat

C:\>type whatis.bat

Code: [Select]@ECHO %%~f0 is %~f0
@pauseC:\>

Output from runany.bat :

information 4201 5/9/2009 8:42:16 PM Tcpip NEWBILL
warning 27 5/9/2009 7:23:09 PM e1express NEWBILL
information 7036 5/9/2009 6:48:10 PM Service Control M NEWBILL
information 7036 5/9/2009 6:43:44 PM Service Control M NEWBILL
information 4377 5/8/2009 6:09:48 PM NtServicePack NEWBILL


C:\>c:\whatis.bat
%~f0 is c:\whatis.bat
Press any key to continue . . .

C:\>Hi I have created, something like this, create a temp FOLDER, then I want the 2009v2.vbs file to run

@echo off
md c:\temp


cd "C:\\Other\2009v2.vbs"

The vbs file won't runfigured out this

cscript "C:\Other\2009v2.vbs"

However it does run, but I receive an error message on the bat...

how do I prevent the bat file from showing, or make smaller

4774.

Solve : copy files to different direcotry when they match specific string.?

Answer»
I have a file that contains list of SEARCH strings (like ABCDE, XYZ etc..) separated by new line.

I have a source folder where there are around 35000 files (.txt).

We need the destination folder populated (copied ) with matching files...

I have to do this in MS DOS. can anybody give me a batch file...or vbscript.....

thanks,
rav.Your question is a bit ambiguous. Do the files get copied to different destinations depending on which string they match? What if a file name matches none of the string arguments?

How many string arguments are there? Might be easier to hardcode an array rather than load array from file.

Your profile mentions your OS as Linux Variant. VBscripts run in Windows or the SHELL program. They do not run in MS-DOS.

Code: [Select]Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("search.txt", ForReading)

'Load Array
i - 0
Do Until f.AtEndOfStream = True
ReDim Preserve arrSearch(i)
arrSearch(i) = f.ReadLine
i = i + 1
Loop
f.Close
'End Load Array

Set f = fso.GetFolder("c:\source")
Set fc = f.Files

For Each fs In fc
For Each arg In arrSearch
If INSTR(1, fs.Name, arg) > 0 Then
fso.CopyFile fs.PATH, "c:\dest", True
End If
Next
Next

Save file with a vbs EXTENSION and run from the command prompt as cscript scriptname.vbs

You will need to add path information to match your environment.

Good luck. linux variant? BASH?


you can use the question mark ? to fill in unkowns

for example, instead of dir file393039*.txt , dir file???*.txt
4775.

Solve : Bat2Exe problems when using icons.?

Answer»

well im TALKING about when you call the batch file, it shows the line, but when you just run it, it doesn't.

do you want it to echo its own PATH?I honestly have always had issues with the "additional INFO" area. Have you tried unchecking that box and checking the "ghost applications" box?

EDIT: I followed the link that BatchFileBasics sent to download the new version (v1.5). It rocks! I was using 1.4 until now. So the comments i made were regarding 1.4. THANK you BatchFileBasics!Ken wrote:
Quote

Another issue just came up that maybe someone here can answer. In the BAT file (before compiling) I have an "Echo Running %1", this works when the file is a BAT file called from another BAT file, but as soon as I 'exe' it, the echo statement disappears. Anyone have an idea for a work around here?

There are other controls for redirection:
http://www.zsh.org/mla/users/1997/msg00526.html

Quote
"Will interpret the `1>&2' as
saying you want stdout to go to both the old stderr *and* the pipe,
which in this case you don't."


Your bat to exe converter might have command line options for redirection?
or
the following workaround might survive the conversion PROCESS:

echo Running %1 1>output.txt

type output.txt

WOOOHOOO that worked.
The 1>output.txt did it.

I'M FREE...lol

Thanks guys, just have the ICON to test next.

V1.5 is definately better.I definitely agree too! I can add the "additional informations" area without ANY issues at all!
4776.

Solve : Disable UAC via batch??

Answer»

Is there a way to disable UAC via a .bat?reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f


you can try the above..Don't you mean regedit.exe?no, reg.exe its the cmd.exe equivilant of regeditthanks.I think this is very unwise.

Slapshot, you are a beginner who has just asked how to copy files from one directory to another, and when told made two mistakes :-
1) you did not believe the answer would copy the CONTENTS of the directories, and
2) you did not even try it to see what happened
The first mistake is simply a matter of learning
The SECOND mistake shows you will always be a learner until you become a little more adventurous.

Those were my thoughts when I read that thread,
but I chose to be kind, and kept them to myself.

Slapshot, I now think you may have become far too adventurous.

Fools rush in where angels fear to tread, and the registry is one of those areas.

If the UAC and registry suffer too much adjustment, repairing the damage might take enough threads to merit an ENTIRE FORUM to itself !!!

Are you sure you want to do this ?

Regards
Alan
lol thanks for your concern. i appreciate it however I am extremely experienced with computers, just not batch files/cmd commandsSorry I misjudged your level of competence.

You may well know more than me, in which case please consider this advice to genuine beginners who stumble across this thread and decide they want to play with the registry and/or UAC.

I NEVER depend upon a *.reg backup to repair damage I may inflict on the registry.

A *.reg backup is TOTALLY UNABLE to correct the registry if the Registry is badly damaged.
Whether *.reg can still do a repair via SAFE mode or the "RECOVERY CONSOLE" I do not know - I have been careful/fortunate to have never experienced this situation.

I generally do make a *.reg backup just in-case it might be helpful, BUT it can only be used to MERGE with the registry. This will ONLY correct changes made to "values", and restore any keys and values that were deleted. It will NOT remove any keys or values that have been added.

A *.HIV backup has a more powerful restoration capability - it can do all that *.reg can do, and in addition it will remove all the keys and values that have been added.
BUT with extra power comes extra disaster - I found that regedit does not know WHERE the *.hiv came from, and depends upon me to tell it. At that point my fears overcame my inquisitiveness and I cancelled. I strongly suspect that the wrong user input would give the wrong registry destination, and that Windows would fail to detect the user error and plant the *.hiv image in the wrong place and cause total confusion and destruction

I also suspect that a registry catastrophe would have the same problems for both *.reg and *.hiv - if SAFE mode or RECOVERY CONSOLE is needed for one, it will be needed for the other.

A Restore Point captures an image of the registry, after which the registry can be modified, after which restoring the system from that Restore Point" should undo the damage - IF YOU CAN REVERT TO THAT POINT. I have SEEN several posts in several forums where innocent users (not even registry dabblers) have wanted to neutralise a recent change, and have then discovered that Restore Points are greyed out and inactive, or available but "damaged" and have no effect.
System Restore and Restore Points are controlled by special keys in the registry.
If the registry gets trashed, perhaps System Restore will totally fail.

Personally, I take no needless risks and only venture into the registry if I really want some "extra" benefit,
and I do so in the confidence that my System start-up/ log-in has included a brand new ERUNT image of the registry, and Windows can use the ERUNT image to instantly repair the registry where ever a *.reg or *.hiv can repair it, AND if the registry is too badly trashed for Windows to work, ERUNT can mend the registry via RECOVERY CONSOLE.
N.B. Immediately before I make any "exciting" changes to the registry I spend 8 Seconds creating a brand new ERUNT image - not because I doubt what was created when I logged in, but because since then I may have altered the target of a TAB in xplorer2, or I may have asked COMODO to remember my decision upon permitting some action, and any one of many other applications may have also made changes to their registry keys since start-up, so if I use today's log-in image the "perfect" result will forget the subsequent things I wanted it to remember.

I depend upon ERUNT to mend my registry whenever it is broken.
I have never experienced sufficient damage to "need" ERUNT from RECOVERY CONSOLE, but many people have been rescued by ERUNT from total disaster.

A search on this site will give information on where to download ERUNT and how to use it

Regards
Alan
Sorry I misjudged your level of competence.

You may well know more than me, in which case please consider this advice to genuine beginners who stumble across this thread and decide they want to play with the registry and/or UAC.

I NEVER depend upon a *.reg backup to repair damage I may inflict on the registry.

A *.reg backup is TOTALLY UNABLE to correct the registry if the Registry is badly damaged.
Whether *.reg can still do a repair via SAFE mode or the "RECOVERY CONSOLE" I do not know - I have been careful/fortunate to have never experienced this situation.

I generally do make a *.reg backup just in-case it might be helpful, BUT it can only be used to MERGE with the registry. This will ONLY correct changes made to "values", and restore any keys and values that were deleted. It will NOT remove any keys or values that have been added.

A *.HIV backup has a more powerful restoration capability - it can do all that *.reg can do, and in addition it will remove all the keys and values that have been added.
BUT with extra power comes extra disaster - I found that regedit does not know WHERE the *.hiv came from, and depends upon me to tell it. At that point my fears overcame my inquisitiveness and I cancelled. I strongly suspect that the wrong user input would give the wrong registry destination, and that Windows would fail to detect the user error and plant the *.hiv image in the wrong place and cause total confusion and destruction

I also suspect that a registry catastrophe would have the same problems for both *.reg and *.hiv - if SAFE mode or RECOVERY CONSOLE is needed for one, it will be needed for the other.

A Restore Point captures an image of the registry, after which the registry can be modified, after which restoring the system from that Restore Point" should undo the damage - IF YOU CAN REVERT TO THAT POINT. I have seen several posts in several forums where innocent users (not even registry dabblers) have wanted to neutralise a recent change, and have then discovered that Restore Points are greyed out and inactive, or available but "damaged" and have no effect.
System Restore and Restore Points are controlled by special keys in the registry.
If the registry gets trashed, perhaps System Restore will totally fail.

Personally, I take no needless risks and only venture into the registry if I really want some "extra" benefit,
and I do so in the confidence that my System start-up/ log-in has included a brand new ERUNT image of the registry, and Windows can use the ERUNT image to instantly repair the registry where ever a *.reg or *.hiv can repair it, AND if the registry is too badly trashed for Windows to work, ERUNT can mend the registry via RECOVERY CONSOLE.
N.B. Immediately before I make any "exciting" changes to the registry I spend 8 Seconds creating a brand new ERUNT image - not because I doubt what was created when I logged in, but because since then I may have altered the target of a TAB in xplorer2, or I may have asked Comodo to remember my decision upon permitting some action, and any one of many other applications may have also made changes to their registry keys since start-up, so if I use today's log-in image the "perfect" result will forget the subsequent things I wanted it to remember.

I depend upon ERUNT to mend my registry whenever it is broken.
I have never experienced sufficient damage to "need" ERUNT from RECOVERY CONSOLE, but many people have been rescued by ERUNT from total disaster.

A search on this site will give information on where to download ERUNT and how to use it

Regards
Alan

4777.

Solve : Complicated Batch?

Answer»

Steini

Be curious no more !!!

A line is not a proper line unless it is terminated.
Normally it makes little difference if a final line of code is completed with a CR/LF,
but sometimes a program does not process an input string until it sees the end of the string.

I get exactly the same result as you if I use code with the last two lines looking like
Code: [Select]:: g
REM H|

By appending a new line I get the result you expected and the code looks like
Code: [Select]:: g
REM H
|

Notepad created this code, and displays a blinking "|" to designate the cursor, i.e. where the next character will appear when you type one. It is NOT part of the code.
In each case the "|" denotes the end of the file.
The defective code concludes with "H".
All it needs to make it work properly is a terminating line-end.

Ten years ago I used an automatic "prettify" program to adjust indentations in a 'C' library. It looked good. I "made" the code and the compiler and linker gave no errors, they just crashed in a heap. I still remember the effort and aggravation before I found that "prettify" had removed the "redundant" final terminating line-end, and that error had absolutely no effect upon the compilation of 48 out of 50 files, but 2 out of 50 had something at the end which required terminating, and without it "the results are undefined" and the best you can hope for is a core dump !!!

Regards
Alan
Dias

Sorry, I cannot remember the "BAD" code which crashed even when commented out.

I was EVALUATING perhaps several algorithms to do a calculation, and comparing the results. I added another variant and it crashed the CMD shell.

I preceded the variant with "GOTO SKIP1", and FOLLOWED the variant with ":SKIP1" and it still crashed. Obviously the BAT/CMD interpreter suspended execution after "GOTO SKIP1" whilst looking for ":SKIP1", but something in the "BAD" code variant caused it to CRASH.

I preceded every line of the variant (about 20 lines) with "REM ", and it still crashed.

I selected and cut the 20 line variant, and everything worked as it should.

I carefully rebuilt the variant a couple of lines at a time, finding and correcting a few spelling and SYNTAX errors, and got it working.
I recognised and corrected my MISTAKES, but have forgotten what they were.
I learnt from this that even when a "REM" is being processed, there are some "BAD" code mistakes that can crash the shell.

The next time I make this mistake I will report back

Regards
Alan.

4778.

Solve : BAT Program Help?

Answer»

Hey, I NEED some help with a .bat program.

I need to code a script that will COPY all the files in a certain directory and paste them to ANOTHER specified directory.

So for example, the user will be prompted with the .bat file asking what the full path to the directory of the files are. Then it will copy all the files in that directory and paste them into C:\directory_name_here.

Thanks in advance.

@echo off
cd %1
copy %2\*.*
cls


Syntax

program.cmd c:\myfiles c:\morefilesDoesn't that just copy the directories? I need to copy the files in the directory to another directoryno it copys the files

change directory to %1 , or C:\myfiles
copy %2\*.* or C:\morefiles\*.*
clearscreen


to copy too copy from
%0 %1 %2 | |
Program.cmd C:\myfiles c:\morefiles

4779.

Solve : how to check perl available in batch file?

Answer»

I've always CONSIDERED it as something that INSTALLS itself to be SIMILIAR to the old PC-DOS REXX processor, QBASIC, and BASICA interpreters, in that you wouldn't need to say, C:\DOS\QBASIC /RUN runit.bas

and could simply say QBASIC /RUN runit.bas

much more friendly for those writing batch scripts (such as in this case)

4780.

Solve : Display filename and length in batch file?

Answer»

The script will dispaly the filename. I need to display the length as well eg. filename is abc.txt, the length is 6
the script as below:

@echo off
for %%a in (C:\*.*txt) do (
set fname=%%a
echo %fname%
)
C:\>cat filelen.bat
Code: [Select]@echo off
for /f "delims==" %%i in ('dir /b *.txt') do (
echo %%i
echo %%i | wc -c)


C:\>filelen.bat
Output:

Quote

a-hire.txt
13
bat.txt
10
caavsetupLog.txt
19
caisslog.txt
15
myFILE.txt
13
mymoney.txt
14
ReadMe.txt
13
savenow.txt
14
savestr.txt
14
teststr.txt
14
tokens.txt
13
unix.txt
11
ver.txt
10
x.txt
8
xvar.txt
11
xx.txt
9
xxx.txt
10
zzz.txt
10
C:\>
you can use vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
WScript.Echo strFile.Name,Len(strFile.Name)
Next
save the above as myscript.vbs and on command prompt
Code: [Select]c:\test> CSCRIPT /nologo myscript.vbs
output
Code: [Select]C:\test>cscript /nologo test.vbs
11 MickeyMouse Road.doc 23
11 MickeyMouse Road.pdf 23
a-hire-1-0601-txt 17
a-hire-2-0601-txt 17
a1.csv 6
a2.csv 6

alternative solution, in Python (for Windows)
Code: [Select]import os
path=os.path.join("c:\\","test")
os.chdir(path)
for files in os.listdir("."):
print files,len(files)
save the code as myscript.py and on command prompt
Code: [Select]c:\test> python myscript.py
Ghost,

Why does wc -c show 9 characters when there are only six?

C:\>cat unix.txt
666666

C:\>cat unix.txt | wc -c
9

C:\>carriage RETURN and linefeed, and the EOF mark, probably.Quote from: billrich on June 11, 2009, 07:40:55 PM
Ghost,

Why does wc -c show 9 characters when there are only six?

C:\>cat unix.txt
666666

C:\>cat unix.txt | wc -c
9

C:\>
there are some unknown characters i believe. please check your unix.txt again. Most probably there are \r\n or somethign . you can use od to check what's inside your file
Code: [Select]c:\test> od -c file.txt

here's mine
Code: [Select]C:\test>more file.txt
666666

C:\test>cat file.txt | wc -c <-------------------- No need to use cat .. see wc example below
6

C:\test>wc -c < file.txt
6
there are no other characters after the last "6"
C:\>cat ghost.bat
Code: [Select]@echo off
echo 11 MickeyMouse Road.doc | wc -c
echo 11 MickeyMouse Road.pdf | Wc -c
echo a-hire-1-0601-tx | wc -c
echo a-hire-2-0601-txt | wc -c
echo a1.csv | wc -c
echo wcup a2.csv | wc -l
Output:

C:\>ghost.bat
Quote
25
25
19
19
8
C:\>i will show you an example
Code: [Select]C:\test>echo 11 MickeyMouse Road.doc | wc -c
26

C:\test>echo 11 MickeyMouse Road.doc | od -c
0000000 1 1 M i c k e y M o u s e R
0000020 o a d . d o c \r \n
0000032


after ".doc" there is a space. is counted as 1. also , the echo command gives you \r\n at the back. that's why whenever you use echo like this
Code: [Select]C:\test>echo test
test
<---- extra blank
C:\test>

if you add them up, its 26 characters. cmd.exe's echo just treat everything after as 1 character, including quotes like "

Since you already have GNU tools, you can use printf instead of cmd.exe's echo..
Code: [Select]C:\test>printf "11 MickeyMouse Road.doc" | wc -c
23
this is CORRECT one.Ghost,

Hey, you are good. Do you work for Microsoft or AT&T? I like these Unix solutions better than than the VBS solution. I hope the lady who started this thread is STILL reading. Thanks for the effort over and above . . .

Quote

C:\test>more file.txt
666666

C:\test>cat file.txt | wc -c <-------------------- No need to use cat .. see wc example below
6

C:\test>wc -c < file.txt
6
Quote from: billrich on June 11, 2009, 09:12:34 PM
Ghost,
Hey, you are good. Do you work for Microsoft or AT&T?
no. i am "self employed" and a hobbyist now. previous job as win/*nix administrator.
Quote
I like these Unix solutions better than than the VBS solution. I hope the lady who started this thread is still reading. Thanks for the effort over and above . . .
no problem. Its good that most of these *nix tools are ported to windows to complement what batch lacks.
4781.

Solve : Batch to stop SQL2005 service MSSQL$CSS ( sqlservr.exe )?

Answer»

Looking for the INSTRUCTION for my batch file to easily stop and start the MSSQL$CSS SQL2005 server service.

Looking to perform this through NET STOP and NET START.... ( whatever the service is called )

I have been able to us ethis to clear print spoolers before such as

NET STOP SPOOLER
NET START SPOOLER

in a batch. So I would like to do this as well without having to go to the system management --> services to STOP and START, but do from command line instruction that I can add to a batch backup program to stop the service and backup the database, then start the service back up after the backup of the data is completed.

Some say that you can back up SQL2005 on the fly, but I'd rather shut the service off to know that data is not being altered during the backup process.

Thanks!

Dave
Well
Code: [Select]@echo off
taskkill -f sqlservr.exe
pause >nulwill end the process.

and then svchost will start it up again...


look into downloading and trying PSSERVICE from SYSINTERNALS- looks like it might be the type of thing your looking for.Quote from: BC_Programmer on October 29, 2008, 04:36:33 PM

and then svchost will start it up again...


look into downloading and trying PSSERVICE from sysinternals- looks like it might be the type of thing your looking for.
Less arrogance in the future please.
I'm trying to help.I wasn't being arrogant, I was merely stating a fact.

Actually, if you keep taskkilling in a loop for a while, svchost will give up starting it. Unfortunately I believe it also disables the service, causing problems with SQL server.


Also- what if SQL server is in the middle of a transaction when you taskkill it? databases could get CORRUPTED, file handles remain open, meaning starting it again later (assuming the fact that svchost hasn't already disabled the service because it kept "crashing"), would CAUSE SQL server to have problems gaining EXCLUSIVE access to it's own databases again.


Killing processes is never a really clean solution, even if it would appear so- even when it works- terminating processes leaves a lot of cruft, from open file handles to open registry keys and even open devices (try killing a burning program when it's in the middle of a burn...)Quote from: BC_Programmer on October 29, 2008, 05:06:32 PM
I wasn't being arrogant, I was merely stating a fact.

Actually, if you keep taskkilling in a loop for a while, svchost will give up starting it. Unfortunately I believe it also disables the service, causing problems with SQL server.


Also- what if SQL server is in the middle of a transaction when you taskkill it? databases could get corrupted, file handles remain open, meaning starting it again later (assuming the fact that svchost hasn't already disabled the service because it kept "crashing"), would cause SQL server to have problems gaining exclusive access to it's own databases again.


Killing processes is never a really clean solution, even if it would appear so- even when it works- terminating processes leaves a lot of cruft, from open file handles to open registry keys and even open devices (try killing a burning program when it's in the middle of a burn...)

I'd rather not, and I have 0 experience with MySQL, He asked how to end a process, I gave him an answer.he asked how to end a service. Although a service is a process, it's always best to get svchost to shut down the service cleanly.

Your solution works fine- but it could have ramifications beyond the solution (I stress the could part since it's highly likely that SQL server is smart enough to notice that it's service is disabled and enable it again anyways).Quote from: BC_Programmer on October 29, 2008, 05:18:18 PM
he asked how to end a service. Although a service is a process, it's always best to get svchost to shut down the service cleanly.

Your solution works fine- but it could have ramifications beyond the solution (I stress the could part since it's highly likely that SQL server is smart enough to notice that it's service is disabled and enable it again anyways).

Agreed, period.Thanks for info both of you!

Dave
4782.

Solve : Doubt in cmd comands.?

Answer»

Hello every one

I have facing a problem while echo a list on command promt , and need the help .

I have a list: LIST=abc:::123:::xyz
Now i want to print this list in a file as follows:
abc
123
xyz

Now i dont know how to do it , PLZ help me to slove this.

Thanks in advance.Code: [Select]REM SET LIST
set LIST=abc:::123:::xyz
REM CHANGE ::: TO "SPACE"
set LIST=%LIST::::= %

REM GET ALL TOKENS ON LIST
for %%a in (%LIST%) do echo %%a

pauseC:\>TYPE finalstr.bat
Code: [Select]@echo off
set str=abc:::123:::xyz
echo."%str%"
set str=%str::= %
echo %str%

for /f "tokens=1,2,3,4 delims= " %%a in ("%str%") do ( set x=%%a & set y=%%b & s
et z=%%c)

echo.x: %x%
echo.y: %y%
echo.z: %z%



echo %x% > savestr.txt
echo %y% >> savestr.txt
echo %z% >> savestr.txt

echo. The file with each string on separate line

Type savestr.txt
Output of finalstr.bat

C:\>finalstr.bat
Quote

"abc:::123:::xyz"
abc 123 xyz
x: abc
y: 123
z: xyz
The file with each string on separate line
abc
123
xyz
C:\>
thanks, it helps me if you have gawk for WINDOWS(see my sig )
Code: [Select]C:\TEST>set str=abc:::123:::xyz

C:\test>echo %str%|gawk -F":::" "$1=$1" OFS="\n"
abc
123
xyz

redirect to new file as needed.
4783.

Solve : batch file - urgent?

Answer»

Hi,
i need to create a batch file wich would change my/users regional and lanugage options format from English (Canada) to English (United States)



Thanks a lot.

I Appreciate your help.

why do you need a batch file to do it? I'm not sure if you can do it in a batch file but here's some steps to bring up the language bar, in XP.
Quote

To show the Language bar (using Classic view in Control Panel):
1.Click Start, click Control Panel, and then double-click Regional and Language Options.
2.On the Languages tab, under Text services and input languages, click Details.
3.Under Preferences, click Language Bar.
4.Select the Show the Language bar on the desktop check box.

FBI have crated an application in vb .net and i want to make sure that all my users have their regional and lanugage settings set to english us (mm/dd/yyyy)- as we agreed with them.

i know how to do it manually.......but i want to run this batch file when INSTALLING the application

thanks


i found this - it changes your SETTING to mm//dd/yyyy but not English canada to english us

:: ShortDate_Save_Restore.bat
:: Process Steps:
:: 1 Save current shortDate format,
:: 2 Set format to Standard M/d/yyyy
:: 3 Execute passed parameters
:: 4 Restore original shortDate format
@SETLOCAL&@SETLOCAL ENABLEEXTENSIONS&@SETLOCAL ENABLEDELAYEDEXPANSION&@IF NOT DEFINED EchoState @SET EchoState=OFF
@ECHO %EchoState%

:: Display current format
REG.EXE QUERY "HKCU\Control Panel\International" /V sShortDate | FINDSTR.EXE /I sShortDate
DATE /T

:: CAPTURE (and save) the current date format output from 'REG QUERY'
FOR /F "TOKENS=1,2*" %%A in ('REG.EXE QUERY "HKCU\Control Panel\International" /v sShortDate ^| FINDSTR.EXE /I sShortDate') DO (
SET _KEY=%%A
SET _TYPE=%%B
SET _VALUE=%%C
)

:: Reset the format to the system default value MM/dd/yyyy
REG.EXE ADD "HKCU\Control Panel\International" /f /v sShortDate /t REG_SZ /d MM/dd/yyyy

:: Verify that the value is set
REG.EXE QUERY "HKCU\Control Panel\International" /v sShortDate | FINDSTR.EXE /I sShortDate
DATE /T
PAUSE

:: Run process
@ECHO.CALL %*
CALL %*
:: End process
4784.

Solve : Change content of variable.?

Answer»

Win XP (H) Cmd.exe Batch script.

In a For loop is it possible to change the content of %%A by removing the FIRST CHARACTER only without using the Set command.

e.g. Code: [Select]Set var=%%A
ren %%A !var:~1!

will correctly rename the FILENAME in %%A but is there a command which will remove the first char of %%A so that the code COULD be:

Code: [Select]ren %%A !%%A:~1!or something like that???
what do you want to do actually?At present, nothing. Just querying if its possible to change the content of an %%A type variable in the same, or similar, MANNER to that of an %A% type variable.

4785.

Solve : "Eval" in MS-DOS batch file??

Answer»

Sorry if this is a very basic question, but surprisingly, extensive googling on the topic has yielded nothing of value.

How do I do an "eval" in MS-DOS?

The task at hand is to capture the current hostname in a variable so I can use it elsewhere in the script. I found the "hostname" command, which when executed spits out the hostname. What I want to do is grab the output of the hostname command and store in in a variable.

I am thinking there must be some kind of directive in the batch file, either special characters surrounding the expression, or some kind of a switch, to say "don't treat this string as a LITERAL, INSTEAD EVALUATE it and return me the result".

Help?

set /a can be USED for doing arithmetic, I think it works for strings to.
C:/>set /a hname = hostname
0
C:/>echo %hname%
0
I found something that works. Ugly, but it works.

@echo off
for /f "tokens=* delims= " %%a in ('hostname') do (
set HOST=%%a
)
echo %HOST%I thought you wanted to evaluate an expression- not redirect the output of a command into a variable. Although rereading your original post makes it quite clear this was your intention. Sorry if I MISLED you.1. You can get it all on one line.

Code: [Select]for /f "tokens=* delims= " %%a in ('hostname') do set HOST=%%a
2. The tokens/delims block looks a little odd. As in redundant. Spaces as delims, when they are the default, and I think host names don't have any spaces anyway, so the tokens bit is redundant too, but I am ready to be corrected.

3. On my XP system, you can get the same result, but with alpha chars in upper case, by merely expanding the system variable %userdomain% but maybe that won't be true for all systems?

Code: [Select]C:\>for /f %a in ('hostname') do @echo %a
pupp-c92f25ed23

C:\>echo %userdomain%
PUPP-C92F25ED23



Code: [Select]C:\>echo %userdomain%
PUPP-C92F25ED23

the above command will not give you the hostname, instead it will print the domain. So I guess you use a local account for logging into your computer.

4786.

Solve : How to find usernames via the computer name from command prompt within a network?

Answer»

I don't think the title made sense!

I would like to know the command that finds a USERNAME via the COMPUTER name on our network to assit with updating our asset listing,

thanks

helenThere is no such command. You could use the command net view. Just type net view and HIT enter. It will give you a LIST of all the computer currently connected to the same DNS SERVER as you are.

But that is about as far as you will get with the command prompt.

4787.

Solve : BAT2EXE adding Quotes to SET statements??

Answer» GOOD morning EVERYONE, the newest VERSION of Bat_to_EXE_converter does somerthing new.

I have a bat file that has the following:

set MODULE=%3
set SERVERNAME=%4

If the file is in BAT format, the results are:

set MODULE=SY
set SERVERNAME=NULL

Once I compile the BAT file into an EXE, the results are:

set MODULE="SY"
set SERVERNAME="NULL"

This definately messes up my scripts
if {%4}=={NULL} set SERVERNAME=%COMPUTERNAME%

Any ideas on how to stop this?


Ken


i don't personally use BATtoEXE and i have heard problems associated with it. however, i do have experience in programming with other languages like Perl and Python and have used their converters (perl2exe for Perl and pyinstaller/py2exe for Python) to produce EXE files and have worked PRETTY well. If you are not RESTRICTED to batch, i recommend you pick up one of these languages and play with it. Where is the site that created the complier ( converter ) from bat to exe?
Contact their Support Department?

In the meantime try:

REM on the command line for the bat file try "%3" and "%4"

@echo off
set MODULE=%3
set SERVERNAME=%4



REM on the command line for the bat file try "%3" and "%4"

set MODULE=%3
set SERVERNAME=%4
echo Module = %MODULE%
echo Servername = %SERVERNAME%

REM Once I compile the BAT file into an EXE, the results are:

set MODULE="SY"
set SERVERNAME="NULL"

REM This definitely messes up my scripts
if {%4}=={"NULL"} set SERVERNAME=%COMPUTERNAME%
echo servername %SERVERNAME%

C:\>
4788.

Solve : Change screensaver registry remotely...?

Answer»

/cry ... I'll maybe work on a BAT file running the the startup folder. The students are locked down from this AREA and shouldn't be ABLE to make changes. Thank you so much for trying to get this to work for me. I really, really appreciate your time!

Have a good one!If it's any consolation, at least I PERFECTED my registry Access routines for use with network PCs.As long as we both learned SOMETHING from the experience, then i say i was worth it!

4789.

Solve : I need a way to check a txt file for 0 or above..?

Answer»

I have a stats file that generated on the hour and it includes the following in it. What I need to do is if the failed reaches above 0 then reset the service that is running this. I am not sure what the code is to check a certain line in the stat.txt file like row 10 can anyone help with this one?

Statistics of (myserver/3300, 11:00:00)
----------------------------------------------------------------------------

AVERAGE
Queue Time Total Pending Executing COMPLETED Failed
==========================================================================
0.00 2451 0 0 2439 12


what (number) line do you want to check?
Thanks for responding I attached the txt file and the line I need to check is under failed. So if under failed the number is above 0 I need to reset the service.

[Saving space - attachment deleted by admin]So it's always the 11th line? (that's what i was asking)Yes SirCode: [Select]@echo off

REM Open stats.txt
REM skip 10 lines and read 11th line
REM in 11th line isolate 6th space DELIMITED token
REM PUT it in an arithmetic (numerical) variable
REM check if greater than zero

for /f "skip=10 tokens=1-6 delims= " %%1 in (stats.txt) do set /a fails=%%6

echo number of fails: %fails%

if %fails% GTR 0 goto failure
goto success

:failure
echo failure count greater than zero
goto next

:success
echo failure count equal to zero

:next

Very nice I TESTED this out and it works perfect.

Thank you for your valuable time and help with this. You are very welcome.

4790.

Solve : replace substring when giving file name to print?

Answer»

Hello,

i WANT to execute the following command

LPR -S 192.168.3.20 -P AUTO d:\SAMPLE.txt

replacing in the filename the word sample with the word test.
I mean the real file that i want to print is test.txt

How can i do this from DOS? Is there any function that can be used to replace the word sample with the word test?What do you mean??
Quote from: alex1982 on October 10, 2008, 07:43:19 AM

i want to execute the following command

LPR -S 192.168.3.20 -P AUTO d:\sample.txt

replacing in the filename the word sample with the word test.
I mean the real file that i want to print is test.txt

If you want to do it at the prompt, why can't you just type this?

Code: [Select]LPR -S 192.168.3.20 -P AUTO d:\test.txt
Or if the command is in a batch file, why can't you load it in Notepad, change "sample" to "text" by use of the delete key and a bit of typing, and then save the batch file?

I fully EXPECT your answer will be that it's not as simple as that, but since you have given no background information, I don't SEE what else can be suggested.
4791.

Solve : Regedit, to dos variable??

Answer»

There's a specific variable i want to GET from the registery.
Let's say the lastgamename used.

REG QUERY HKEY_CURRENT_USER\Software\Valve\Steam /v LastGameNameUsed

If i use this the output will be
Quote

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Software\Valve\Steam
LastGameNameUsedREG_SZogelami
By that set q=REG QUERY HKEY_CURRENT_USER\Software\Valve\Steam /v LastGameNameUsed
Will not do it.

I want it only to be
ogelami

And i want to be able to use it, like in an ECHO.
echo helo %q%
That prints "Hello ogelami!"Code: [Select]
@echo off
set regcommand=REG QUERY HKEY_CURRENT_USER\Software\Valve\Steam /v
set keyname=LastGameNameUsed
for /f "tokens=1,2,3 delims=<TAB>" %%A in ( ' %regcommand% %keyname% ^| find "%keyname%" ' ) do set LastName=%%C
echo Hello %LastName%

Important note: Do NOT merely copy and paste this. Replace in the 4th line with a TAB character, obtained by pressing the key of that NAME.

Thank you times and times ! it worked fine!
Another happy customer! Glad to hear it worked. Good luck, my friend!
Thank you, there's anoter small thing i need help with.

When i receive a directory variable, the slashes are just regular slashes, i want them to become backslashes =), any solution?Quote from: ogelami on October 12, 2008, 05:11:57 AM
Thank you, there's anoter small thing i need help with.

When i receive a directory variable, the slashes are just regular slashes, i want them to become backslashes =), any solution?


This is a path name got from the REGISTRY?

You mean they are forward slashes? like this / ? And you want them to be back slashes like this \ ? Please explain.
Quote from: Dias de verano on October 12, 2008, 05:16:10 AM
Quote from: ogelami on October 12, 2008, 05:11:57 AM
Thank you, there's anoter small thing i need help with.

When i receive a directory variable, the slashes are just regular slashes, i want them to become backslashes =), any solution?


This is a path name got from the registry?

You mean they are forward slashes? like this / ? And you want them to be back slashes like this \ ? Please explain.


yes, excatly
if i get "SteamPath" instead "LastGameNameUsed" it will return in C:/Program/Steam
what i want is it to be C:\Program\Steam
to replace one character or string in a variable by another:

To replace X with Y in %myname%:

Code: [Select]set myname=%myname:X=Y%
and to replace Z with nothing (remove all the Zs) in UncleName:

Code: [Select]set UncleName=%UncleName:Z=%
and to replace cat with dog in %animalname%:

Code: [Select]set animalname=%animalname:cat=dog%
Thus:

Code: [Select]C:\>set myname=aXa

C:\>echo %myname%
aXa

C:\>set myname=%myname:X=Y%

C:\>echo %myname%
aYa
and

Code: [Select]C:\>set pathname=c:/program/steam

C:\>echo %pathname%
c:/program/steam

C:\>set pathname=%pathname:/=\%

C:\>echo %pathname%
c:\program\steam
Works both at prompt and in a batch

thank you!
4792.

Solve : batch puzzle: conditionally truncating filenames throughout subdirectories?

Answer»

Hi all! I came across this site searching for some pieces to help me solve a batch puzzle I'm up against. I am vaguely familiar with DOS and programming in general, but lack specific knowledge of dos commands; I don't want to inadvertently modify files that don't need it, and I don't know how to apply a command to all subdirectories.

I am pulling all my files off of my college server, and have discovered that everything I ftp'd off the server now has ";1" appended to the end of the filename, e.g. I now have an .mp3;1 collection, and my pictures are in .jpg;1 format. Of course I only noticed this after they were all mixed with my normal files, so I have to check to see if the name is incorrect before I rename it, so as not to change the ok files to .m's and .j's.

Here is the problem I'm trying to solve:
I want to batch rename all files in a folder and it's subdirectories (actually across my entire flash drive, but I don't think that distinction matters?) by reading in the current name, checking to see if the name ends in ;1, and if it does then removing the last 2 characters and using the corrected string for the new name.

i.e.

pic.jpg -> pic.jpg
pic2.jpg;1 -> pic2.jpg
music\01.mp3;1 -> music\01.mp3
music\okay.mp3 -> music\okay.mp3
misc\1\file.doc;1 -> misc\1\file.doc

It seems like this could be done with just one if statement within a for loop;
For (all files in directory and subdirectory)
get oldname
If (oldname ends in ;1) {
newname = truncated oldname (remove last 2 characters only regardless of length)
rename oldname newname
}
Next


Any suggestions on how to best ACCOMPLISH this? Code examples (or a working batch file!) would be much appreciated. Also PLEASE explain briefly exactly what each piece of code would do what.

Thanks for any help!For instance, could I do

for /f %%f in('dir /s /b') do If %%f:-2% equ ";1" ren %%f %%f:~0,-2%

or something similar? Haven't tried running this since I'm don't have the files I want to run it on with me.This might work. By using the semi-colon as the delimiter, you can deconstruct the file name, then reconstruct it for the ren command

Code: [Select]@echo off
for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') do (
ren "%%i;%%j" "%%i"
)



Thanks for the help; unfortunately I can't get it to run; I get alternating lines of:

"The SYNTAX of the command is incorrect."
"The system cannot find the file specified."

I am simply cutting and pasting to a .txt file with Notepad, saving to the top directory I want to affect (test folder), and renaming to a .bat EXTENSION. I can't get any version of the above code to do anything. Is my procedure off or am I creating a syntax error somewhere?

p.s. entering the following - for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') ren "%%i;%%j" "%%i" - in the command prompt returns "%%i unexpected at this time" and nothing happens. Modifying to %i returns "ren unexpected at this time"Quote

p.s. entering the following - for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') ren "%%i;%%j" "%%i" - in the command prompt returns "%%i unexpected at this time" and nothing happens. Modifying to %i returns "ren unexpected at this time"

Fixed the ren command. See code below.

Quote
"The system cannot find the file specified."

I should have mentioned this message was expected. Files not containing the semi-colon did not need to be renamed. By appending a semi-colon, the file would not be found, throwing an error. Sloppy perhaps, but effective.

Code: [Select]@echo off
for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') do (
ren "%%i;%%j" "%%~nxi" 2>nul
)

I made to slight change to the ren command to send errors to the nul device. Sorta like throwing dirt under the rug. since OP needs to rename only the files that end in ;1, why not just do a dir *;1 ??Quote from: Sidewinder on October 27, 2008, 04:51:24 PM

Code: [Select]@echo off
for /f "tokens=1-2 delims=;" %%i in ('dir /s /b') do (
ren "%%i;%%j" "%%~nxi" 2>nul
)


Worked perfectly! It was great to have explorer open and watch everything SNAP back to normal.

Thanks a ton.
4793.

Solve : Activate a program with correct code lines?

Answer»

OK this might be a long shot, but perhaps someone can guide me in the correct way. I admit I am not that great in programming but I do understand a little like renaming, xcopy delete etc . This ONE has put me in difficulties and it has no samples for me to try with. You can download this utility tool from here (no virus included, I PROMISE) and it is not an install version.
http://mitab.maptools.org/dl/mitab-1.7.0-win32.zip

I need to find the correct line of code to activate this program via batch file to GO to "D:\Data\test" and CONVERT "tab" files to "mif" files and also the reverse "mif" files to "tab" files. The amount of tab files varying during times so it has to take the all files in the folder. I may tell that the tab file also has other files attached to it, so it is not just a "RENAME thing" for it to work.

I have a hard time to understand the documents included with the program...

Anyone who like to take the time would be appreciated and be able to put me into the right track.

RegardsIt seems like the program has to live in the same folder as the files, I got it to run that way. But it needs to run with a loop as it only execute one file at the time...

4794.

Solve : Pass direction character '>' to SCHTASKS /TR switch value?

Answer»

I have a batch file to create a scheduled task on multiple servers. I am trying to set the task RUN: option to call the command and direct output to a logfile. The issue is SCHTASKS interprets the '>' for its role instead of being a member of the string for the /TR switch. My desired result for the tasks RUN: is without brackets ["C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log]

Code: [Select]SCHTASKS /Create /S servername /RU account /RP password /SC ONSTART /TN Reboot /TR "C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log
So you can see that at the '>' character it thinks I want to send the entire line to c:\temp\reboot.log.

I have tried to use the escape character ^> but it does not work either. Am I attempting something that SCHTASKS was never meant to handle?

I tried to pass the > character to a local variable also but cant get that work either, my plan was to then pass the variable to the SCHTASKS /TR and see if I could trick it in there. I set up a test to resemble the purpose I need above.

Code: [Select]@ECHO off
SETLOCAL ENABLEEXTENSIONS

set cmdstrg="test test" > test.log

ECHO %cmdstrg%
My desired result would be:
cmdstrg contains this string without brackets ["test test" > test.log]

Has anyone else found a way around this?

Thanks All!In the interest of keeping it simple, why not substitute the short name (8 dot 3) for your directory: C:\BigDir\App 2.0. The rest of the path has no embedded spaces, so you can use as is.

You can construct of short name path from a dir /x C:\BigDir listing.

Good luck. Hi

This should answer the '>' question.

TYPE %0 | FIND "reboot.log" | FIND /V "FIND" > NEWCMD.CMD
GOTO :EOF
"C:\BigDir\App 2.0\Maintenance\Reboot.cmd" > c:\temp\reboot.log


I recommend you PASTE the last two lines to the end of your Batch command.
GOTO :EOF is to prevent your batch file from trying to execute the command string.

You may copy the first line I gave to any convenient place within your Batch command.
This copies the last line as a new creation, NEWCMD.CMD.
It does this by typing the entire batch command, and passing the output through FIND to reject any line without the text "reboot.log" - and then it passes through FIND a second time to exclude itself.

The result is a CMD file NEWCMD.CMD, which performs your special command string.
If the above does not work with SCHTASKS etc. (of which I know nothing) you MAY need to start the final line with SCHTASKS and all its option switches before the quoted command string.

The above is based on a special DOS trick I invented before there was Windows.
It still works on Windows XP - most unusual for Microsoft - every version of Microsoft Excel can create and use macros, but when my Excel spreadsheet was run with a different version of Excel it always found at least one macro to do a different way with the wrong answers !!!

Regards
Alan
That was very ingenious, ALAN_BR.
Thank you Dias, I appreciate that.

If you liked the last one, you may love this one from the same era.

Code: [Select]@echo off
IF %1.==. GOTO Z
IF NOT %0.==c:\BaT\cD#. c:\BaT\cD# %1 %2
TYPE c:\BaT\cD#.BAT > C:\CD%1.BAT
REM TYPE removes any terminating 'Ctrl Z' so destination is appended to "CD "
CD >> C:\CD%1.BAT
IF NOT %2.==. ECHO %2 >> C:\CD%1.BAT
:Z Last line command "CD " has NO CR/LF so above line can append as argument.
REM File ends "CD /D " WITHOUT NewLine. Notepad is recommended editor.
CD /D
Autoexec.bat used to invoke " CDhome " and that immediately switched the DOS shell to the "home" directory and path upon start-up.
After Start-up I might move to a different directory and path, and then command " CDhome " would instantly take me back to where I wanted to be.
" CD# home " was the magic command to (re)create a new version of CDhome.BAT.
" CD# argument " similarly creates CDargument.BAT.
" CD_F3 " was what I chose for Drive F:\ and the 3rd most important folder on that drive.

It was especially useful when I had a large set of fixes to implement on a software package. I had a structure C:\Z\Z\Z\Z etc etc with perhaps 100 Z's, and one of those folders would be my latest set of code. At any time I could refer to ..\ for the previous variant, or ..\..\..\..\ to go back 4 versions (actually I used .....\ which OLD DOS realised was the same - pity that NT DOS is not that clever !!!).
Relative to my home position, ..\ took me back 1 version, whilst Z\ took me back 99 versions (reuse of a "linear" buffer as a circular buffer).
When I finished one of the fixes I could erase files that were 99 versions out of date (i.e. contents of Z\), and copy the latest version to Z\, finally " CD Z " would allow me to easily revert to the "best so far" at ..\ should I make mistakes with the next fix, and " CD# home " would set my new position as my new home.
Without CD# I would have had the grief of typing " CD C:\Z\Z\Z\Z\Z etc etc " with exactly the correct quantity of Z's.

My old systems had a path that started with " C:\;C:\BAT\; etc etc "
I was not a touch typist, so mostly I worked in "hunt and peck" mode,
but I could always find "#" next to the "Enter" key,
hence I always used "#" wherever possible, even though it was the first (and only) key that lost its legend.
CONSEQUENTLY I actually used "#" wherever the above shows "home",
i.e. " CD# # " would create a variant with "home" destination in CD#.BAT in C:\.
Consequently the "master" CD#.BAT was put in C:\BAT so that a simple " CD# somewhere " might start with the variant in C:\,
BUT that would perform " IF NOT %0.==c:\BaT\cD#. c:\BaT\cD# %1 %2 " so control is switched to the "master",
and the variant with the old target destination avoids trying to modify itself (something else that DOS objects to !!!)

The second argument was introduced when I had a computer with multiple drives,
and this allowed the command " CD# _F3 F:\ " to append an extra command to CD_F3 to switch drives,
so that subsequently " CD_F3 " would not only aim at the chosen path, it would also aim at the chosen drive.
This last little kludge is no longer required with NT DOS which now gives CD the /D option,
but other commands could be appended - e.g. DIR to remind me what files I have at that path on drive F:\

This batch File has been INVALUABLE to me for over 20 years.
I am a little sad that its tremendous "MUST have" value has been diminished by the arrival of NT DOS.
Unfortunately progress happens. Can anyone still ride a Penny Farthing bicycle !!!.

Regards
Alan

4795.

Solve : boolean functions?

Answer»

Is there a way to use boolean functions in the IF statement? Things like logical and, or, xor.

Something that would act, like this looks
Code: [Select]if %var%==x OR y (then...)Code: [Select]for %%a in (x y) do (
if '%var%' equ '%%a' (
commands
)
)Thanks for the help devcom.

If I am understanding your code correctly, both x and y will be compared against %var% separately. Problem is, this way, there is a true/false PRODUCED for both x and y. I need to logically say (X AND Y) or (X OR Y). That way I have only one true/false produced. I hope that makes sense. Perhaps I'm the one confused.Maybe you want something else.
In Boolean logic OR is inclusive, not exclusive.
Do you want to say either but not both? You use the XOR which is exclusive.
Do that make sense? Lets say A could be 0 or 1 and B could be 0 or 1. You want the case where A or B has a value f 1, but not both.
You would have something like like this
if A + B = 0 goto getouttahere
if A + B = 2 goto getouttahere
some commands
....
:getouttahere

Sorry that is not real BATCH code, but you get the idea.

An example:
Code: [Select]@echo off

set var=x

for %%x in (x y) do (
if "%var%"=="%%x" (
echo true
) else (
echo false
)
)

pause
The output of the example:
Code: [Select]true
false
Press any key to continue . . .
X and Y are processed separately and compared against "%var%" separately, yielding one true and one false. I am needing to have them processed as one logical statement which would yield only one true/false. Perhaps this is just not POSSIBLE with a batch file.Maybe these will help

1. from set /? (My asterisks)

Code: [Select]The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated. The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

() - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
<< >> - logical shift
& - bitwise and
^ - bitwise exclusive or
| - bitwise or
= *= /= %= += -= - assignment
&= ^= |= <<= >>=
, - expression separator

*** If you use any of the logical or modulus operators, you will need to
enclose the expression string in quotes.***

Any non-numeric strings in the
expression are treated as environment variable NAMES whose values are
converted to numbers before using them. If an environment variable name
is specified but is not defined in the current environment, then a value
of zero is used. This allows you to do arithmetic with environment
variable values without having to type all those % signs to get their
values.
2.

http://groups.google.com/group/alt.msdos.batch.nt/search?hl=en&group=alt.msdos.batch.nt&q=boolean&qt_g=Search+this+group

Thanks everyone.

@ Dias de verano

Thank you.
Through the link you provided, I was able to find this ftp://garbo.uwasa.fi/pc/link/tscmd.zip. Many good examples found there, including how to incorporate AND/OR/XOR/NOT into IF statements.

An example of logical OR the long drawn out batch file way:
IF "%var%" is something other than "a" or "b" or "", then ask user for valid input.
Code: [Select]: logical.or.loop
set logical.or=
if "%var%"=="a" (set logical.or=true)
if "%var%"=="b" (set logical.or=true)
if "%var%"=="" (set logical.or=true)
if not "%logical.or%"=="true" (
echo.
set var=
set /p var=Invalid input, please try again.
goto logical.or.loop
)

4796.

Solve : Compare file date to current date?

Answer»

try to put Mon 10/27/2008 in quotes ("")Thank you.

I ended up working through it prior to seeing your post, and I have successfully tested this:

Code: [Select]@ECHO off

:loop
REM set variable to flag file mod date in sys format
for /f "tokens=1,2" %%i in (C:\Admin\flag.txt) do (
set dt=%%j
)
REM Create variable from sys date parsed to just mm/dd/yyyy
for /f "tokens=1,2" %%i in ("%date%") do set sysdt=%%j
REM compare flag mod date to sys date
IF %dt% EQU %sysdt% GOTO indexer
REM ECHO Not Equal
REM DATES not same so wait 10 minutes and try again
ping -n 601 localhost > nul
GOTO loop

:indexer
REM ECHO equal
REM dates same so close Indexer
CALL C:\Admin\EndIndex.bat
REM wait for fileserver to come back up
ping -n 901 localhost > nul
REM start Indexer again
CALL C:\Admin\StartIndex.bat

EXIT



Thanks to everyone for all your help!!!!

Now, I just have to wait for an update initiated reboot to see if the script that writes to the flag file will run EVEN with 3rd party initiated reboots. If not, I'll be back to find out more about the SUGGESTION to listen for the reboot event.

4797.

Solve : Config.sys editing?

Answer»

Hi everyone,

I juste have a question about config.sys that I've tell in irc CH's channel and no one could answer me.
In a scenario where I only have Io.sys Msdos.sys and comand.com I would like to edit Config.sys, without any EDITORS,
is there any solutions ?

Thanks and sorry for the baddest english in the world.
This is like stepping into a time warp and it's not pretty. You can use the copy command to WRITE your file:

Code: [Select]copy con config.sys

After the copy command, enter each line of your file. You cannot edit lines, so if you make a mistake, start over. You can backspace in the current line only.

Use ctl-Z or F6 to create a end of file marker. Hit enter one last time to return to command prompt. For obvious reasons, copy con works best with low volume input.

Good luck.

If you're interested, I have a little editor called edlin I can let you have cheap. Were you really going to offer Edlin?
What DOS is the person using? MS-DOS? Some VERSIONS have QBASIC and there is a EDIT command that uses that to edit text files. Good morning,

Thanks for the answer I just mail my professor to get the real question,
That is the complete question :
" Your aim is to create a CONFIG.SYS or AUTOEXEC.BAT file with only using the internal command from MS-DOS ( 6.0 or older ) IO.SYS MSDOS.SYS and COMMAND.COM.

I think I'am gonna use Copy CON given that no one editor is allowed.

One example of Config.sys :
Device=C:\DOS\himem.sys
Device =c:\DOS\ Emm386.exe Noems
DOS=high,UMB
DEVICEHIGH=c:\mouse\mouse.sys
BUFFERS=20
FILES=40

I'am trying to stay tuned !!
And if you got any other solutions

Thanks and sorry for the english skill
I have used ECHO and the > and >> redirection symbols many times to do this task.

Code: [Select]C:\>echo Device=c:\DOS\himem.sys > config.sys

C:\>echo Device=c:\DOS\Emm386.exe Noems >> config.sys

C:\>echo DOS=high,UMB >> config.sys

C:\>echo DEVICEHIGH=c:\mouse\mouse.sys >> config.sys

C:\>echo BUFFERS=20 >> config.sys

C:\>echo FILES=40 >> config.sys

Code: [Select]C:\>echo @echo off > autoexec.bat

C:\>echo prompt $P$G >> autoexec.bat

C:\>echo PATH=C:\DOS;C:\WINDOWS >> autoexec.bat

C:\>set TEMP=C:\TEMP >> autoexec.bat

C:\>set BLASTER=A220 I7 D1 T2 >> autoexec.bat

C:\>lh smartdrv.exe >> autoexec.bat

C:\>lh doskey >> autoexec.bat

Yumero, if you couldn't think of this very basic thing by yourself, and if your idea of "research" is to ask on IRC and on here, I think this course is not for you.

" Of this very basic thing "
Ok everyone begin may you are unbeatable about MS-DOS but I'm a neophyts then because I'am posting here you think I didn't search or try myself ?
It's real i didn't really search and reflect about the solution.
But when in the Windows course you have only see how to MD CD RD and Tree /F how do you WANT to make this thing... Maybe it's innocuous for you not as for me bare with me and if you think that it's too easy for me to ask the question here just gimme the way.

Anyway thanks you I'm working on to make a complete answers with every indication cya.

4798.

Solve : dos for command?

Answer»

I have a file LOG file for which I need to read each line. If a line in the log file starts with the word 'Record' or 'ORA' I want to capture the complete line and write it to a new file.

I have this, but it doesn't work correctly:

for /f %%a in (main.log) do (
echo %%a >> newfile.txt
)use findstr . type findstr /? to find out moreBut how do incorporate the findstr command into the 'for' loop?sorry DUDE, i don't do batch.
you can search for similar solutions in the forum (there are plenty) , or you can wait for the batch enthusiast to give you a hand.

This might work for you:

Code: [Select]@echo off > newfile.txt
cls
setlocal enabledelayedexpansion

for /f "delims=*" %%A in (main.log) do (
SET line=%%A & call :findit
)
exit /b

:findit
for /f %%B in ("!line!") do (
if %%B equ Record echo !line!>>newfile.txt
if %%B equ ORA echo !line!>>newfile.txt
)

Good luck.

gkata,

( The following code works. I have TESTED and retested the code. )

C:\>type mainlog.txt
Record bbbbbbbbbbbbbbbbbb
ORA xxxxxxxxxxxxxxxxxxxxxxxx
Now is the time to find

C:\>type orastr.bat
Code: [Select]@echo off

setlocal enabledelayedexpansion
echo Hello > newfile.txt

for /f "delims=*" %%A in (mainlog.txt) do (
echo %%A | findstr "ORA Record" >> newfile.txt

)
type newfile.txt
Output:

C:\>type newfile.txt
Hello
Record bbbbbbbbbbbbbbbbbb
ORA xxxxxxxxxxxxxxxxxxxxxxxx

C:\>gkata,


C:\>findstr /?
Searches for strings in files.
.
.
.


For example : 'FINDSTR "hello there" x.txt' searches for "hello" or
"there" in file x.txt.
.
.
.

C:\>Quote from: billrich on June 12, 2009, 06:42:34 AM

...
for /f "delims=*" %%A in (mainlog.txt) do (
echo %%A | findstr "ORA Record" >> newfile.txt
....
the above method calls findstr for each line iteration. If there are 10000 lines, then findstr will be called 10000 times, which is inefficient.
better to use it the other way round , ie
Code: [Select]for ..... ( findstr "ORA Record" mainlog.txt ) do blah blah
if there are further processing on each line found, or simply pipe to newfile if what OP wants is only to find ORA records
Code: [Select]findstr [blah options] "text_to_find" >>newfile
ghost,

You are right the for loop is not needed:

Code: [Select]@echo off
echo. > newnewfile.txt
findstr "ORA Record" mainlog.txt >> newnewfile.txt

type newnewfile.txt
Output:


C:\>type newnewfile.txt

Record bbbbbbbbbbbbbbbbbb
ORA xxxxxxxxxxxxxxxxxxxxxxxx

C:\>

p.s. Works just like the Unix grep command.

Quote from: billrich on June 12, 2009, 07:42:31 AM
p.s. Works just like the Unix grep command.
and also awk/sed. these tools iterate files and find patterns so they are similar. however, awk goes a bit more in that it is a programming language by itself. therefore, one does not need to learn grep/sed and use only awk to do the job( of MANY , eg cut, wc). this will reduce your learning curve a lot.
4799.

Solve : Pull files from server?

Answer»

Hi

I NEED to create a batch file to copy files from a specific FOLDER on a server to each host computer. The batch file can be stored in a shared folder on the network, or can reside on each host computer (which are about 400 users).

I'm very new to batch files

Please help

Thanks
MeeeMzHi,
I just thought I'd stop by and say "HI"!

One thing that's occurred to me is that you're talking about doing 'something' with files on (obviously) an NTFS drive from a DOS program and also doing it over a network.
Am I right so far?

DOS can't even see an NTFS drive.
I know DOS has 'grown up' a lot since the days when I had to learn it, to run my IBM XT Clone with DOS 2.0 on it.

Maybe someone with experience with the "New DOS" can tell you how to do what you outlined. I'm out of my element here. Sorry.

Good Luck,
The Shadow I am also fairly new to batch files, but this is the sort I use at work for copying images to new destinations

copy "full path to file" "full path to destination"


i.e

copy "c:\test files\0001.txt" "\\destinationpc1\c\test files\"
copy "c:\test files\0001.txt" "\\destinationpc2\c\test files\"
copy "c:\test files\0002.txt" "\\destinationpc1\c\test files\"
copy "c:\test files\0002.txt" "\\destinationpc2\c\test files\"
copy "c:\test files\0003.txt" "\\destinationpc1\c\test files\"
copy "c:\test files\0003.txt" "\\destinationpc2\c\test files\"

I don't know if you can put more than one destination per line, as I don't copy to more than 1 PC anyway. Of course the destination folder needs to excist in the 1st place.
Hi

metallithrax's suggestion will PUSH files out from the server.

A simpler solution is to replace
copy "c:\test files\0001.txt" "\\destinationpc1\c\test files\"
with
copy "c:\test files\*.*" "\\destinationpc1\c\test files\"

That avoids the need to individually copy each and every specific file.
If *.* copies additional files which are not required, then copy from a different folder that has been specifically CREATED to hold whatever files need to be deployed.

In addition you may need to keep your resume up to date in anticipation of a sudden job search when the C.E.O. or Financial Director finds his files are out of date. Just because you are not responsible for maintaining the Network does not mean you will escape blame.

You may need to add more complexity so that for each destination you :-
1) test whether or not it is on-line BEFORE you push files at it;
2) produce an "exception report" file listing any offline or other problem.
Also for each destination, either immediately or as a subsequent action
3) compare the destination files with the originals that you pushed out, and
4) produce an "exception report" file listing any problems.

The reason for a delay before stages 3 and 4 is to allow for Anti-virus and Firewall etc problems. If they don't like something they may stop it before it gets to its destination, OR there might be a late reaction to a "virus" and perhaps it might take a while to quarantine.

If you get any exception reports, you may be able to take corrective action and try again,
otherwise you can email the report to whoever can fix it,
thus avoiding a visitation from management and making you bullet proof - or at least finger-pointing proof.

You will of course get a lot of grief from the Network Maintenance engineers if your exception reports keep on SENDING them to fix an offline problem at a P.C. that has been switched off for a few weeks pregnancy leave !!!


You will find life easier if you can avoid any problems with the network.
All you have to do then is to PULL files into each P.C. from the server.
e.g. Each P.C. upon start-up and or User log-on, could run
copy "\\destinationpc1\c\test files\*.*" "c:\test files\"
or whatever is relevant to your network.

By using the PULL solution it is simple to add a warning to the user if the Network has failed to download from the server, and he can immediately phone the Network maintenance engineers - and for the ladies you could also advise to PHONE NOT EMAIL any network problems !!!!

Regards
Alan

4800.

Solve : Remove Spaces from String?

Answer»

Ok I got it.

I ended up creating a second FOR loop that READ from a dummy file I dumped to to pull the IP back in without SPACES at the end.


THANKS for your help.