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.

4701.

Solve : Batch file delete file by file name?

Answer»

I'm trying to create a batch file that will delete files by a certain name. The files will all be similar to this. a20081010.txt or a20081011.txt or a20081012.txt... etc. Then if the files are older then 30 days for datemodified then I WANT to delete the file. Here is what I have so far. OBVIOUSLY, it doesn't work in it's current state. If I comment out the IF EXISTS it works if the file is older then 30 days. So I just need to work in the file name PART. Any help would be greatly appreciated!

SET objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Documents and Settings\Username\My Documents\batch file\test")
For Each efile in objFolder.Files
If exist a********.txt Then
If DateDiff("d",eFile.DateLastModified,Now) >= 30 Then
objFSO.DeleteFile(eFile)
End If
Next


just one wildcard will do. Code: [Select] if exist a*.txt...
FBOk I added just one wildcard to it but when I try to run it I get an ERROR with line 4 saying it's expecting a 'Then'. If I comment line 4 out it works fine. So I'm guessing something is wrong with that line, just don't know what......The file existence test is redundant, it's also incorrect syntax. A file would not be in the files collection if it did not exist. VBScript doesn't use wildcards, but you can improvise.

Code: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Documents and Settings\Username\My Documents\batch file\test")
For Each efile in objFolder.Files
If Mid(eFile.Name, 1, 1) = "a" And objFSO.GetExtensionName(eFile) = "txt" Then
If DateDiff("d",eFile.DateLastModified,Now) >= 30 Then
objFSO.DeleteFile(eFile)
End If
End If
Next

why is this in MSDOS?

FB

4702.

Solve : Compilation?

Answer»
Hi, There is problem like that. Which is the best language to compile dos command with there.. like in C you use
"System ("command") but some time like "/\^" this type of character junrate a problem on that so what is the SOLUTION.?
Quote from: Deadly D on September 11, 2009, 09:48:58 PM
Hi, There is problem like that. Which is the best language to compile dos command with there.. like in C you use
"System ("command") but some time like "/\^" this type of character junrate a problem on that so what is the solution.?


LEARN proper C string escaping.Why not C# or Visual Basic?
http://www.helium.com/items/1524872-making-use-of-escape-sequences-in-c-and-visual-basic

Thanks for the replay.

but C# need .net framework i think and all COMPUTER not use this THINGS so that's the problem any other way
4703.

Solve : Moving chaotic data ... looking for suggestions?

Answer»

A friend of mine came to me with her laptop that her whole family uses and data is scattered everywhere. She was wondering if I could help her get the data organized into folders for types of files such as music, pictures, documents etc.

I was thinking that I could write up a batch file using the MOVE COMMAND, but am concerned over the possibility of data loss SINCE I dont see where the MOVE command verifies that the data was copied from point A to point B successfully as a checksum match prior to deleting the data's prior location.

I looked into xcopy as a possible solution since it will verify, but it also will replicate the data and if trying to write back to the source drive I will get a cyclic copy error.

So i am stumped trying to figure out the best way to get her chaos of data sorted into folders through multiple batch lines specifying each file extension to search and move if found with data integrity verification.

I remember years ago my computer science teacher trying to tell us not to use the MOVE command because it was dangerous, but I dont see any other way to make this happen.

Any suggestions with code snippets on how to safely achieve a data move with sorting and verification of data integrity when reading and writing to same drive?

Thanks

Check out TeraCopy, which is free, works in GUI or command line mode, and does CRC verification of copied & moved files.

http://www.codesector.com/teracopy.php
Yes, don't use the MOVE command. *

And there are way to do what you what. You can organize what seems to be a random distribution of stuff. Without moving stuff. Do you have a fair amount of drive space? I mean like at LEAST 20 per cent free?

Do you know for sure that file extensions are the only thing that matters?
What about the content of the files? That requires Human Reasoning.


* Using the MOVE command for lots of files you surely will get to a point where a file name is duplicated in another folder. Trying to move both files into the same directory will cause and error or you will delete one file which may have different content.
Find all your jpeg pictures with :


Code: [Select]C:\>dir /b /s *.jpg > jpeg.txt
use a For loop to copy all pictures in jpeg.txt to whereever you please.


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

setLocal EnableDelayedExpansion
cd \

dir /b /s *.jpg > jpeg.txt

for /f "delims==" %%a in (jpeg.txt) do (

copy "%%a" c:\jpeg\

)C:\>

Output:

04/14/2008 07:00 AM 25,759 wpakey.jpg
04/14/2008 07:00 AM 17,719 wpatop.jpg
11/19/2002 07:59 AM 9,161 wreath.jpg
05/02/2009 08:51 AM 1,301 wrenches_66x57.jpg
05/02/2009 08:51 AM 3,550 wsadvisor_logo_66x57.jpg
07/08/2009 07:33 PM 1,480 xp_logo_50x50.jpg
07/17/2009 05:31 PM 20,866 yellowrose.jpg
11/20/2008 10:16 PM 5,857 yellow_tiles.jpg
01/30/2009 12:50 AM 46,135 ZHCN_dell_bg_firstrun.jpg
01/30/2009 12:50 AM 46,126 ZHTW_dell_bg_firstrun.jpg
02/13/2003 03:35 AM 18,669 z_burst1.jpg
02/13/2003 03:35 AM 19,910 z_burst2.jpg
02/13/2003 03:35 AM 16,985 z_heart.jpg
02/13/2003 03:35 AM 17,611 z_kidney.jpg
02/13/2003 03:35 AM 17,004 z_oval.jpg
05/11/2009 09:33 PM 81,709 {46CAC505-936C-4891-891B-D1ABB86F4
use3.jpg
724 File(s) 55,246,166 bytes
2 Dir(s) 306,873,536,512 bytes free

C:\jpeg>yellowrose.jpg

C:\jpeg>

Rem the " " is necessary since the path to a picture might contain a space
copy "%%a" c:\jpeg\Thanks everyone for your help, and verifying that the instructor was correct in avoiding "MOVE" command years ago back in High school.

Yah Geek-9PM good point about reasoning... the other issue was to maintain some of the structure she has, where a replication of a tree would be established after Pictures folder category and Documents folder category as say in the path

C:\vacation\ Bermuda contained both a bunch of JPG photos and a poem she wrote while on vacation as a .DOC file

the tree would remain intact and so at

C:\Data\Pictures the sub directory tree would include

c:\Data\Pictures\Vacation\Bermuda and all the JPGs


and at

C:\Data\Documents\Vacation\Bermuda she would have her single document poem


*So if she is hunting for pictures all pictures are found in that PICTURES Folder Tree under C:\data\pictures\

and her poem as well as any other .DOC, .RTF, or any other document format that she needs will be in the C:\Data\Documents and maintain her prior group of Vacation\Bermuda

By maintaining her old structure there would be no LIKE filename overwrite problems.

So what do you think? *Only potential problem I could see in this setup is hitting the maximum path length and clipping (losing acces to ) data at the edge of maximum file/folder path length. I pray that she doesnt have data that burried under multiples of sub-directories. Suppose I shoudl check...lol Quote

replication of a tree would be established
You get the idea. Make an abstract structure.
Create a directory with a tree structure that makes sense. Populate the tree with shortcuts. Most application programs, in my experience, have no trouble using a shortcut to find the actual location of a file. The shortcuts take very little disk space ans allow you to use an alias name and an alternate icon.

The are some programs that even do this for you. Some MP3 player software will organize your songs into play lists without the need to actually move the data. Also, photo album programs can do the same thing a deal with the problem of duplicated names.

And you can even replace the Windows Explorer (Not Internte Explorer) with another program that does better job of organizing this.

The advantage of using shortcuts is that you can move them, make new ones, delete them, modify them, rename them all without doing harm to the original file.
And they are quick, very little system, overhead.

Check this out:
http://techblogs.wordpress.com/2009/01/31/15-windows-explorer-alternatives/




Hey thats cool ... I didnt even think about that. But the problem there would be when she wants to backup her data, it is still scattered.... so that I why I am thinking that the data has to physically move to a new path of C:\data\....

Maybe I should use more than batch, but a thumb drive as a cache to store the data, an intermediary bucket to move the data to, "but without the move command". An instruction that XCopys the matching data to thumb drive, then back to the C:\data\... then have a CLEANUP process after a verification that the files locates at C:\..."wherever they came from" matches the new location at C:\data\...

I was thinking that this would fix the Cyclic Error issue with searching drive C and writing back to drive C and avoiding a loop. I suppose I could also use an exclusion, trying to figure out of the exclusion of path C:\data would work or if the thumb drive temporary file cache is a better idea. Thumb drive would likely slow down the process vs disk to disk without the USB communications bottleneck.

What do you think?
DaveLembke,
You are smarter that you need to be. It does not have to be that difficult.
The standard backup tools have all kinds of options that you can use to backup data and make special data sets with exceptions. You can even have the backup program detect files changed and make additional backups of just the files that have recently changed.

Normally all the user data should be in the Documents and Settings area, if using Windows XP. Some application programs will put stuff in the Programs folder, which is annoying. But you can have the backup set selectively backup part of the
programs folder.

What I love about the backup program it can know where everything relay belongs. You only have to tell it to restore to original location and it will do just that. And if yo chose another location, it will duplicate the tree structure. Trying to do this in batch is a big chore.

If you have another hard drive bailable you can transfer all of My Documents onto the spare drive and not ruin the My Documents link.Please read this:
http://support.microsoft.com/kb/310147

My preference is to have My Documents of the main user on another partition. That way I can just backup all of the drive. Other users on not in the partition. Some files I do not use anymore I put into the documents of the other users. That is one case where I use the move. I do not need to do that very often.

The are so many ways to backup it is hard to give a simple answer. But it is not realty hard. Just requires some fore thought.
http://www.genie-soft.com/asp/community/KnowledgeArticle.asp?KBID=105

Hope this is of some help. And I am sure OTHERS here even more ideas about how they would take on this kind of project.

4704.

Solve : Good morning / Good afternoon display in BAT?

Answer»

Hello,

I am CREATING a logon BAT and i would like to display "Good Morning" or "Good Afternoon" depending on the current time.

I have looked this up for some time now and cannot seem to find a way to make this work in a BAT. I really do not want to use a VBS for this one...

This is what i am looking for:
If a user logs in when the logon.bat executes it will display "Good Morning" if the time is before 12pm and after 12am. Then if the user logs in after 12pm and before 12am, it will display "Good Afternoon".

I am getting frustrated with this on and need assistance. Can anyone assist me with this?

Thank you!

-HoFLQuote from: TheHoFL on May 28, 2009, 04:43:27 PM

Hello,

I am creating a logon BAT and i would like to display "Good Morning" or "Good Afternoon" depending on the current time.

I have looked this up for some time now and cannot seem to find a way to make this work in a BAT. I really do not want to use a VBS for this one...

This is what i am looking for:
If a user logs in when the logon.bat executes it will display "Good Morning" if the time is before 12pm and after 12am. Then if the user logs in after 12pm and before 12am, it will display "Good Afternoon".

I am getting frustrated with this on and need assistance. Can anyone assist me with this?

Thank you!

-HoFL
for /f "delims=:" %A in ("%time%") do if %A LSS 12 (echo Good morning!) else (echo Good afternoon!)I just added this to the beginning of my BAT and it is not working. It simply closes the CMD windows very quickly. I added pause after it, but it will not stay open. Any ideas?Quote from: TheHoFL on May 28, 2009, 04:57:55 PM
I just added this to the beginning of my BAT and it is not working. It simply closes the CMD windows very quickly. I added pause after it, but it will not stay open. Any ideas?
Sorry...add space between "delims=:" and %A

If that doesn't work, run CMD and drag the BATCH file to the window...press enter and see if it displays any messages.Works like a charm! Thank you for your assistance! You are very much appreciated right now!

-HoFLQuote from: TheHoFL on May 28, 2009, 05:01:41 PM
Works like a charm! Thank you for your assistance! You are very much appreciated right now!

-HoFL
No problem! Feel free to stick around and help out other members, or get help if you need it!I am always looking for people to help. I am somewhat new to some of the commands used in BAT files. I pretty much used to make them when i needed them and then stop. I am trying to take the time to learn now though. Quote from: TheHoFL on May 28, 2009, 05:04:47 PM
I am always looking for people to help. I am somewhat new to some of the commands used in BAT files. I pretty much used to make them when i needed them and then stop. I am trying to take the time to learn now though.
That's great! Batch is extremely easy to learn, a bit difficult to master, but is so usefull for organizing files/folders or automating tasks!Check this out, you will find it awesome! ...

Code: [Select]@echo off

for /f "tokens=2*" %%a in ('net user "%Username%" /domain ^| find /i "Full Name"') do SET DisplayName=%%b

for /f "delims=:" %%A in ("%time%") do if %%A LSS 12 (echo Good morning and welcome %DisplayName%) else (echo Good afternoon and welcome %DisplayName%)
echo.
ECHO You are currently signing on to %COMPUTERNAME%
echo.
ECHO Please wait while authenticating %username% with the %USERDOMAIN% domain.
echo.

pause

echo on
Very nice! I SAVED that one in my bat folder.
I really like the idea too.

Thanks for starting this topic, and thanks to Helpmeh for the solution.
Quote from: TheHoFL on May 28, 2009, 05:11:02 PM
Check this out, you will find it awesome! ...

Code: [Select]@echo off

for /f "tokens=2*" %%a in ('net user "%Username%" /domain ^| find /i "Full Name"') do set DisplayName=%%b

for /f "delims=:" %%A in ("%time%") do if %%A LSS 12 (echo Good morning and welcome %DisplayName%) else (echo Good afternoon and welcome %DisplayName%)
echo.
ECHO You are currently signing on to %COMPUTERNAME%
echo.
ECHO Please wait while authenticating %username% with the %USERDOMAIN% domain.
echo.

pause

echo on
Quote
System error 1355 has occurred.

The specified domain either does no exist or could not be contacted.

Good afternoon and welcome

You are currently signed on to COMPUTERNAME

Please wait while authenticating USERNAME with the USERDOMAIN domain.
Note, %userdomain%==%computername% and %computername% NEQ %username%...

Just putting that out there...Hmm... Are you connected to an AD domain? This seems to work for me...

Quote from: TheHoFL on May 28, 2009, 05:20:20 PM
Hmm... Are you connected to an AD domain? This seems to work for me...


To an what?Just ran it right now. This is what i got. I changed the credentials and information, but this is what came up. Because i am joined to a domain the domain is not the PC name... fyi...

Quote
Good afternoon and welcome Michael LASTNAME

You are currently signing on to COMPUTERNAME

Please wait while authenticating username "USERNAME" with the DOMAINNAME domain.
Oh and AD is Active Directory.

fyi...http://en.wikipedia.org/wiki/Active_Directory


4705.

Solve : Symbols like: ^|, ^/ and ^\?

Answer»

Hi,
I have seen these (in the TITLE) symbols sometime, but don't know what they are or what they are called, so can't search for them. Could anyone tell me, at least what they are called?....I'll do the research myself , but will PROBABLY come back here

Thanks guys
Two-eyesGenerally, they are called "special characters." They can mean different things and perform different functions within different programming languages or shell environments. They generally have a DEDICATED meaning within the language or environment.Symbols that require a ^ before them in a batch file so they can be DISPLAYED aren't allowed in paths.

4706.

Solve : DOS Batch Problem?

Answer»

I use DOS BATCH commands to FTP information from the IBM ISeries mainframe to a PC and then open that information using Excel. This works fine until a user has loaded about 4 big files. Then it does not download the information. That user has to restart their computer before they do more files. I have tried a memory manager with no luck. It sounds almost like a buffer problem. Is there a DOS command to clear the buffer or is there ANOTHER option someone can recommend I try? Thanks for any help.Could you post the batch?I have not USED excel. But excel has an import manager.

Don't download 3 or 4 jobs to RAM and then try to have excel work correctly.

Download the files to the HDD and have excel import one JOB at a time.

How much free SPACE on the HDD? How much free RAM?

If you are low on HDD space save to a CD from the IBM mainframe

Good Luck
cat-bomb here is my batches:
@ECHO off
CD C:\2pc
if(%1)==(t) ftp -i -s:ftptext.bat
if(%1)==(d) ftp -i -w:9000 -s:rcvcsvfl.bat
if(%1)==(d) start excel.exe c:\2pc\AS400FLE.csv
if(%1)==(ut) ftp -i -w:9000 -s:ftputext.bat
if(%1)==(uf) ftp -i -w:9000 -s:upload.bat
exit

Open 192.168.0.1
QUSER
Z9876
cd qsys.lib/dist400d.lib/
get FTPBINFO.file c:\2pc\rcvcsvfl.bat
quit

OPEN 192.168.0.1
QUSER
Z9876
GET /FTPFILES/SA153448 c:\2pc\AS400FLE.csv (replace
QUIT

The first batch is my control batch, the second batch updates the next batch with what I want to download and the third batch does the actual download. This allows the user to download the information from the I Series and have it open in Excel. We do it this way so that we know who is downloading information and by opening in Excel the user does not have to go look for the file on there computer. If you can see something wrong or can think of a easier solution it would be greatly appreciated.

4707.

Solve : Moving files where filename contain characters from a list?

Answer»

I have a LARGE number of files in a directory but only want to MOVE over those that contain numbers that match any in a LIST of "ID's" that are in a text file. For instance, i have a file called test_111.wav and in the ID text file 111 is part of the list i want that file to be moved. If a file doesn't contain the specific number in the name then it doesn't get moved over. Does anyone have any suggestions or let me know if I am not explaining this clearly.

4708.

Solve : Verify the user entered value is correct.?

Answer»

Hi,

I am new to creating batch file. Infact this is my first batch file.
I want the user to input values according to question.
Below is an example:
@echo off
echo Hello Welcome to Automation!
pause
echo Enter the Month, START date, end date, year.
set /p month=Enter month?
set /p startdate=Enter start date?
set /p enddate=Enter end date?
set /p year=Enter year?
pause
echo Enter the date range(start date and end date) in mm/dd/yyyy format.
set /p startdaterange=Enter start date range?
set /p enddaterange=Enter end date range?
pause
echo The data for the specified date range has been collected and save
echo in you database.

echo Thank you.

Now my question is when user enters month, it should be a valid entry, same for date and year. how will i verify. if user enter ABC for year..the system should promt " invalid data" and should ask th euser to renter the value.

Please help.
Thank you.
AnuThis can get compacted in batch. You would need to check each response from the user to every possible answer that might be given.

example:
for the month you would need to check that
1 the value is not blank
2 there are no characters or other letters
3 the value is not less than one
4 the value is not GREATER than 12
ext.

there are other programming languages that are better suited for this task. Will this solution need to be strictly batch or can say VB or .NET be used? Quote

there are other programming languages that are better suited for this task. Will this solution need to be strictly batch or can say VB or .NET be used?

I agree with wbrost . But it could be done in batch as an exercise in learning more about batch. Is that what you want?
As for me, it would take me about 10 to 20 minutes in a language I know well. But in batch it would be an all day project.It can be done with a for loop. I saw something when reading for /? but I can't remember the switch (if there is any). Hi everyone...

I am new to this forum. Plz guide me how can i post the question.

Thanx
4709.

Solve : create shortcuts using a batch file?

Answer»

My batch file moves a folder to "C:\example", but after it moves it, i want to make shorcuts to some files inside "C:\example". How would i do that?Quote

i want to make shorcuts to some files inside "C:\example". How would i do that?

What kind of files are these? Executables? File types associated with an application?

Normally I would suggest a VBScript, but the NT Toolkit has a shortcut utility:

Quote
shortcut: [-? -h -f -c -r -s] [[-t] target [[-n] name]] [-d working directory]
[-a Arguments] [-i Iconfile] [-x Icon index] [-u {all|[natdix]}]
[-l logfile]

-? -h This HELP
-f Force overwrite of an existing short cut
-c Change existing shortcut
-s Make shortcut non TRACKING (Stupid)
-r Resolve broken shortcut
-t target Specifies the target of the shortcut
-n name Specifies the file name of the shortcut file
-d directory Specifies the directory name to START the application in
-a arguments Specifies the arguments passed when the shortcut is used
-i iconfile Specifiles the file the icon is in
-x index Specifies the index into the icon file
-u [spec] DUMPS the contents of a shortcut. 'all' is the same as 'natdix'
but the letters of 'natdix' can be specified to display specific
fields in the shortcut (repeats allowed, and order FOLLOWED)
-l logfile record error messages in specified file

4710.

Solve : how can we put space when i getmac?

Answer»

hello everyone,

when use "getmac" command i WANT use also some spaces to the SCREEN how can i do it Could you show us
a your code
b your actual and WANTED OUTPUT

4711.

Solve : net user command?

Answer»

i wanna display the NAME with NET user command can you help me PLEASE ? How should i do

4712.

Solve : IDE SATA conflict prevent boot cds..?

Answer» HELLO all

few days ago, i deleted an ntoskrnl.exe from system32 by mistake which TURNED out to be not the wisest of choices cuz it was required to boot the system..anyway,to avoid reformatting the whole system,am trying to MAKE a DOS boot cd from which i can copy the boot files that might have been deleted. So i went on to download and burnt a boot cd( http://www.bootdisk.com/bootdisk.htm) and then RESTARTED the PC *censored* the cd didnt boot (it gave me this error www.freeimagehosting.net/image.php?b47aaa1b02.jpg )

i have read somewhere in the internet that a mixture of IDE(my DVD writer) and SATA(my 80 gb hard disk) drives causes conflict and this was evident with my attempt to create a Norton Ghost 2003 image when I had to add a -NOIDE command befor building the image to avoid the conflict. The result ofcourse was that in DOS mode, Ghost couldnt see my DVD drive and was able to detect only SATA hard drive.

So my question is, what should i do to create a working bootable DOS cd?What OS ? ?
Do you have your Windows CD ? ?

You need to get things running properly before Ghosting the drive or you will wind up with a useless image of things and still have the same issues.
Do you have a previous Ghost image ? ?-it is win xp sp2
-yes i have one..but i need the boot cd to access DOS for a faster process.
-i already have a working ghost image patio. No issues with that. The problem i had(which i luckily solved) was this ( http://www.techsupportforum.com/microsoft-support/windows-xp-support/230835-ghost-2003-boot-dvd-rw.html ) ..This is not though my problem. It is the creation of a boot cd that wouldnt produce the error in the pic and would allow me to use DOS FREELY ..
4713.

Solve : Else command?

Answer»

Quote from: Larssie111 on AUGUST 10, 2008, 12:18:31 PM

That doesn't help me

I know.
Your picture shows that the two files being compared are not the same, and the differences are SHOWN. Then your code goes into a loop. I expect you have made an error of logic somewhere.

Your code is very difficult to UNDERSTAND. Its structure is what programmers call "spaghetti code". FURTHERMORE, all the labels are named with cryptic letters and numbers, they all have similar names, the variables also, and it is not surprising that CONFUSION has resulted, and nobody wants to get a headache trying to unravel it. Quite apart from everything being in (single) Dutch! You should learn to write simple, readable, understandable code.






But i'm Dutch The code is language independent, but I think you don't understand me.
Oo
But i have already made it in a couple of hours in Microsoft Office Excel
4714.

Solve : Calculating?

Answer»

How do you calculate in Dos
I want only + and -
Is this homework of some sort?

Hint: Set command.Yes it is
We don't write other people's homework.

I already gave you the command you need.


Hint2: In Command Prompt, set /?By the way, set arithmetic is only POSSIBLE in modern NT family command prompts, not "DOS".
or in visual BASIC make a new consle application and type
dim number1, number2, + sum
number1 = a number
number2 = a number
sum = number1 + number2
consle.writeline "the sum of" & number1.tostring() & " and " & number2.tostring() &
"is " & sum.tostring())I also have a calculating problem.
I would like to calculate how long some commands take.
For example:

@echo off
set old=%time%
echo %old%
rem some commands here
echo %old% %time%
set /A delay="%time% - %old%"
echo %delay%
pause

I get an error "MISSING operator" then on the next line I get an 18.
Can anyone help with this?
FrankFrank, I suggest you start a new topic. You will get more replies there.

Larssie111, he's got the answer to your question in his code. Quote from: Carbon Dudeoxide on August 11, 2008, 03:08:02 AM

Larssie111, he's got the answer to your question in his code.

but %time% is not a number.
I thought that "BATCH" might work with "time" as a number like some other PROGRAMS (eg. exel).

I started a new thread for my question (Calculating using time).
Frank
4715.

Solve : Only typing certain parts of a text file?

Answer» HI all!

I was wondering if it's possible - and if so, how? - to print only a certain part of a text file with the type COMMAND.

e.g:

Text file:
Quote

llama
A llama is an animal, which is...

chocolate
A delicious FOOD which...


coffee
A drink which helps keep....

How would i go about printing only say, the bit Quote
chocolate
A delicious food which...
?


Thanks in advance,

Kamak
i also would like to know this.
sorry I'm of no help.u cant us the type command alone to generate such an output
put u can type out som lines of the file

@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a cont=1
for /f "delims=" %%i in (file.txt) do (
if "!count!" EQU "3" echo %%i
set /a count=!count!+1
)
endlocal


this code will print the 3rd line
if u want it to print from the 3 to 5 row u have to do this


@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a count=1
set /a count2=3
for /f "delims=" %%i in (New.txt) do (
if "!count2!" GTR "5" set /a count2=0
if "!count!" EQU "!count2!" (
echo %%i
set /a count2=!count2!+1
)
set /a count=!count!+1
)
endlocal
pauseQuote from: .bat_man on June 12, 2008, 10:50:53 AM
u cant us the type command alone to generate such an output
put u can type out som lines of the file

@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a cont=1
for /f "delims=" %%i in (file.txt) do (
if "!count!" EQU "3" echo %%i
set /a count=!count!+1
)
endlocal


this code will print the 3rd line
if u want it to print from the 3 to 5 row u have to do this


@echo off
setlocal ENABLEDELAYEDEXPANSION
set /a count=1
set /a count2=3
for /f "delims=" %%i in (New.txt) do (
if "!count2!" GTR "5" set /a count2=0
if "!count!" EQU "!count2!" (
echo %%i
set /a count2=!count2!+1
)
set /a count=!count!+1
)
endlocal
pause
Thank You welcom welcomWhat if you wanted only certain lines. Say lines 3, 5, 8, etc.?Think I got it. At least it is doing what I want. Anyone have a cleaner way to do this, post for all to enjoy.

if EXIST File2 del file2
setlocal ENABLEDELAYEDEXPANSION
set count=0
for /f %%v in (File1) do (
set /a count=!count!+1
echo !count!
if !count!==3 echo %%v > File2
if !count!==5 echo %%v >> File2
if !count!==10 echo %%v >> File2
if !count!==70 echo %%v >> File2
if !count!==71 echo %%v >> File2
if !count!==72 echo %%v >> File2
)
4716.

Solve : regsitering all dll files inside a folder?

Answer»

There are 100's of dll in a folder and I want to run regsvr32 on all those dlls. How can I do that?
Please help.

Thanks.after searching on net for a while about vbscript, I am able to write the following the script which solves my problem:

Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("D:\MyFolder") 'point to your directory
Set fc = f.Files
set shellObj = CreateObject("WScript.Shell")
Dim cnt
cnt = 0

For Each objFile In fc
If fso.GetExtensionName(objFile) = "dll" then
shellObj.Run "regsvr32 /s " & objFile
cnt = cnt+1
End If
Next
Wscript.echo("Total dlls found and registered = " & cnt)


curious if such things can be done through batch files ALSO. I am new to both vbscript and batch files.

Thanks.This would be the batch code equivalent:

Code: [Select]@echo off
set cnt=0
for %%v in (D:\MyFolder\*.dll) do (
regsvr32 /s "%%v"
call set cnt=%%cnt%%+1
)
echo Total dlls found and registered = %cnt%

Both batch code and VBScript have their uses. Generally I think you'll find batch code underpowered and a bit CRYPTIC (six months from now will you remember what %%v represents?).

VBScript can be a bit wordy and much work takes place in functions with positional parameters (six months from now will you remember the parameter order for the instr function?)

VBScript combined with HTML code can create front-end GUIs for even the most boring of scripts. Batch code is strictly command line.

Both are good tools to know. If you find yourself doing repetitive computer chores, scripting is a fine way to automate them.

Thanks for the reply. It does the work but the only difference is in the output of count. It gives output as:
Total dlls register = 0+1+1+1+1+0+.... and says you do the bloody math yourself

Anyway, thanks.

Vivek.

PS: I may not remember what %%v STANDS for even after 1 month but I can always bookmark this page and will visit it whenver in doubt.If you're gonna do arithmetic you have to tell the interpreter:

Code: [Select]@echo off
set cnt=0
for %%v in (D:\MyFolder\*.dll) do (
regsvr32 /s "%%v"
call set /a cnt=%%cnt%%+1
)
echo Total dlls found and registered = %cnt%

Of course the DIY method works too.

4717.

Solve : graphic images or pictures?

Answer»

I still don't understand what you're saying ( and SINCE I'm trying to write in perl I switched to the perl forum) but what I want is to be able to run a perl program and open and manipulate a picture in perl or whatever.

Thanks
DianeOkay, I'll try to simplify. Win XP only.

When you are using Cmd.exe, the so-called Command Prompt, you are still running in Windows, there is no MS-Dos in Windows XP just a Dos emulator program which runs in a window. This dos emulator looks like Dos, feels like Dos, smells like Dos, uses dos-look-alike commands (and many more), in some cases performs like Dos and is most often called Dos but is a program running in Windows.

Here is a definition of emulate from Dictionary.com:
To imitate the function of (another system), as by modifications to hardware or software that allow the imitating system (Windows) to accept the same data, execute the same programs, and achieve the same results as the imitated system (MS-Dos).

The emboldened and underlined words are mine.

In Windows when you click to open a file the file extension (.txt or .jpg or .jpeg or .gif etc...) is checked against a list of Associations to determine what program is associated with that filetype and should be used to open the file. So, if .jpg files are associated with Windows Picture and Fax Viewer that program will be started and the program in turn opens the file. If the program associated with the file-type is not capable of opening the file an error message and options are displayed and the user must select what should happen next.

What you should understand is that when you open a file by entering commands at the Command Prompt or by clicking on it in a Window the same process occurs. File associations can be changed by the user, see here..

If you want to open an image using Perl then I think you have to code the instructions to open the file WITHIN your program. Unfortunately my Perl knowledge level is not good enough for me to advise you how to do this. Perhaps some other member will drop by..

Good luckAnd I assume APPLE has their own version of cmd.exe also (or even the same one)?



QUOTE

The "" is required if the path and the file name of the started file needs to be quoted. (ex: start "" "C:\Documents and Settings\Compaq_Owner\My Documents\Perl\us.jpg")

The "" is not required if the path and file name of the started file does not need to be quoted. (ex: start c:\temp\us.jpg)

Please, if the started file needs to be quoted then I was assume that this is some type of C (language) variable? And the unquoted started file but be an absolute?

Thanks
Diane

I know nothing of C programming language.

Quote from: dimilinowski on August 11, 2008, 11:00:57 AM
And I assume Apple has their own version of cmd.exe also (or even the same one)?

Apple doesnt have any thing that even remotely RELATES to Command Prompt or MS-DOS, because Command Prompt and MS-DOS were created by Microsoft which is were they got MS-DOS(Micro.Soft-Disk.Operating.System)

but there is a emulator of Command Prompt for Mac OS X that you can download here.Quote from: dimilinowski on August 09, 2008, 06:29:59 AM
what I want is to be able to run a perl program and open and manipulate a picture in perl or whatever.

Here is a tutorial on opening files in Perl.

4718.

Solve : Show last line of text file?

Answer»

Hi

I have a batch file that performs a few actions on a binary file and then GENERATES a report (.txt). The last line on this report (.txt) list how many ERRORS encountered.

Is it possible for DOS to display the last line of TEXT from the reprot (.txt) to the users instead of having to open the report (.txt) file.

ThanksIf you used for to set the text file into variables, but only using a single variable.. the last line of the text file would be set as the result

for /f "tokens=1*" %%a in (yourtextfile.txt) do set a=%%a
THANKS for the code, I tied the line of code in a bat file but it does not seem to work.

My coding experience is in VB.NET so unfortunately I have little experience in DOS coding so I am unsure if the line of code that you supplied works on its own are requires more code.

I appreciate your help on this.

Thanks

he posted good solution look:

yourfile.txt
Code: [Select]AAA
BBB
VVV
yourbat.bat
Code: [Select]for /f "tokens=1*" %%a in (yourfile.txt) do set a=%%a

for /f "tokens=1*" %%a in (yourfile.txt) do set a=AAA

for /f "tokens=1*" %%a in (yourfile.txt) do set a=BBB

for /f "tokens=1*" %%a in (yourfile.txt) do set a=VVV

so at last a will ALWAYS be last line of fileSorry, I am not getting it.

Are you saying that the line of code previously supplied works and displays the last line of text because I am not seeing it, what I get is the first word of each line displayed on the screen as like below

C:\>set a=Checking

C:\>set a=Checking

C:\>set a=Checking

Etc..

Thanks
Needed fixing, I think. Try this. "delims==" selects the whole line (i.e. the delimiters are the start and end)

Code: [Select]@echo off
for /f "delims==" %%a in (yourfile.txt) do set lastline=%%a
echo %lastline%
Works now. Thanks for your help, it is much appreciated

4719.

Solve : DOS 6.22 Clock Problem?

Answer»

I have a system that does not have windows on it and is running DOS 6.22. The date and time will not maintain which seems to be common according to the comments I have been reading.
The system is on a small network so I used the net time COMMAND to get the time from a PC running windows 2000. I put this into a file that is CALLED during the reboot sequence but it is not rebooted often so the date and time are always wrong.

Does anyone know if you can add the "at" command to standard DOS 6.22 so I can set up a batch file with the net time command and call it with the at command every day?

Thanks for any assistance. Welcome to the CH forums.

Have you tried solving the date/time problem by replacing the cmos battery?

Thank you for your reply.

No I have not tried replacing the CMOS battery yet. I started to try and find some information on line and most of it said that the battery would not fix the issue.

I am by no means an expert but the clock will show a date and time ahead of the current date and time. I READ a few things that said the clock would just remain constant if the battery was dead is this true?

Thanksdead battery usually means Jan 1st 1980 12:00 AM at cold start.

If the battery does not fix this then....

Some older NON-Y2K ( Non-Year 2000 ) compliant systems had this issue where the year would be like 2054 when the BIOS could not support the true year output.

I had a 486DX4-100Mhz system that did this. You would set the date back to correct date and upon reboot, right back to 2054 or some year that was insane like that.

I remember AOL not liking this incorrect Year, and upon forcing it back to 2000 or 2001 in Windows 98 SE it was fine until reboot, when it would go back to 2054 or a year like that.

BIOS was not Y2K compliant on the Dragon 486 Motherboard.

Ended up having to install a 3rd party piece of software that would correct the date/time issue for this motherboard. Cant remember what it was called since I got rid of that system in 2001... gave to neighbor for playing DOS games.

Is your CPU older than a Pentium 133 Mhz? Most Pentium systems supported Y2K roll over, some 486 systems did, but most didnt, and just about all 386 systems would not roll over, and all 286 and before systems I believe would not go to 2000 due to the 2 digit year from 99 to 00 being 1900 instead of 2000.

4720.

Solve : delete file fast?

Answer»

like you know if you delete too much files it takes too much time anyway to delete this files in shortime ? What are you trying to delete?

What Operating System?Quote from: zodehala on August 10, 2008, 05:51:50 AM

like you know if you delete too much files it takes too much time anyway to delete this files in shortime ?

Can we have that again in English?
Quote from: DIAS de verano on August 10, 2008, 07:14:57 AM
Can we have that again in English?

Did you ever consider that the original poster might not be used to the English language?Quote from: kpac on August 10, 2008, 09:51:41 AM
Quote from: Dias de verano on August 10, 2008, 07:14:57 AM
Can we have that again in English?

Did you ever consider that the original poster might not be used to the English language?

Of course I did, and I felt that they should make a bit more effort, since their meaning was not clear, so I fed that back to them.Quote from: Carbon Dudeoxide on August 10, 2008, 05:56:21 AM
What are you trying to delete?

What Operating System?

winXP_pro_sp2And:
Quote
What are you trying to delete?
Quote from: kpac on August 10, 2008, 02:59:56 PM
And:
Quote
What are you trying to delete?

any filesQuote from: zodehala on August 11, 2008, 12:12:16 PM
any files

Is it pictures/text files/folders or programs?zodehala, deleting many files takes time. You cannot change this.
If you are emptying a Flash DRIVE or Portable Hard Drive (completely get rid of everything on the drive, you can Format it very quickly.
If you are deleting CERTAIN files, you can HOLD SHIFT while pressing Delete and it will delete it permanently without going to the Recycling Bin.a SCIRP like phpbb has more than 250 files (total 3-4mb) in unix server i can all files about 1-2 sec using cpanel. but in windows (my comp.) i can all files about 45-60sec

whyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy?1. Effect of different filesystem: ext2fs vs FAT or NTFS
2. Only one letter 'y' in the word 'why'.
Quote from: zodehala on August 12, 2008, 12:34:01 PM
a scirp like phpbb has more than 250 files (total 3-4mb) in unix server i can all files about 1-2 sec using cpanel. but in windows (my comp.) i can all files about 45-60sec

Quote from: Dias de verano on August 12, 2008, 12:38:18 PM
Effect of different filesystem: ext2fs vs FAT or NTFS

Basically:

cPanel, and a website's files are on a web server, and your files are on your hard drive.....
Obviously a web server's file-removal speed is going to be faster than your PC.
4721.

Solve : Batch Program Tip?

Answer» NEVERMIND, dont use CTRL+V to paste it in.. make SURE quickedit mode is on and then paste it in using the right MOUSE BUTTON
4722.

Solve : i want to make a file name changer.?

Answer»

I have a lots of music, and lots of them have an underscore in lots of places eg.
blabla_bla_-_blabla.mp3 i WANT to replace all underscores with spaces instead.

I also have a few game folders i with CD in the name that i want to remove eg.
CD Blabla i want to remove the CD in the name of the folder.


Thank you. =)QUOTE

I have a lots of music, and lots of them have an underscore in lots of places eg.
blabla_bla_-_blabla.mp3 i want to replace all underscores with spaces instead.

If you can read the hieroglyphics on the wall, you are WELCOME to try this. Note: This was literally tested with blabla_bla_-_blabla.mp3.

Code: [Select]@echo off
setlocal enabledelayedexpansion

for %%V in (C:\temp\*.mp3) do (
set newname=%%~nxV
set newname=!newname:_= !
ren "%%V" "!newname!"
)

Be sure to point to your directory.

Quote
I also have a few game folders i with CD in the name that i want to remove eg.
CD Blabla i want to remove the CD in the name of the folder.

This can be accomplished by tweaking the posted code. If it's only a few game folders, doing it manually might be faster than writing code.

Good luck. Quote from: Sidewinder on August 12, 2008, 05:18:46 AM
Quote
I have a lots of music, and lots of them have an underscore in lots of places eg.
blabla_bla_-_blabla.mp3 i want to replace all underscores with spaces instead.

If you can read the hieroglyphics on the wall, you are welcome to try this. Note: This was literally tested with blabla_bla_-_blabla.mp3.

Code: [Select]@echo off
setlocal enabledelayedexpansion

for %%V in (c:\temp\*.mp3) do (
set newname=%%~nxV
set newname=!newname:_= !
ren "%%V" "!newname!"
)

Be sure to point to your directory.

Quote
I also have a few game folders i with CD in the name that i want to remove eg.
CD Blabla i want to remove the CD in the name of the folder.

This can be accomplished by tweaking the posted code. If it's only a few game folders, doing it manually might be faster than writing code.

Good luck.


Thank you very much, it helped but it doesn't make it in underfolders. :/
its above 300gig games
so its quite a few dunno if this will work (i dont test it)

change this

Code: [Select]for %%V in (c:\temp\*.mp3) do (to
Code: [Select]for /F %%V in ('dir /b /s *.mp3') do (
ofc YOR file must be in right folder
4723.

Solve : command prompt help?

Answer»

Hi...

I want to run a multistep process on command line but without user's input. I want this input to come from a batch file. How can i do that? I am trying to automate this process




ex:
c:\>Hello how are you?
user: fine ----------------------->-----------
write a number | ------> to come from batch file sequentially
user : 4 --------------------->-----------

I want command line to take input from batch file


thanks
Not sure I understand your question.

Do you have anything to show us?What i simply want is -- User shouldnot enter anything from standard input and the input should come automatically to the command prompt.So you want to MAKE a batch file, right?

Something like this?

Code: [Select]echo How are you?
echo Fine
pause
or do you want the batch file to interact with another CMD Window?Code: [Select]echo.Hello how are you?
set /p answ=
echo.user: %answ%

echo.write a number
set /p answ=
echo.user : %answ%
set /p allow user to input text and save it to variableQuote from: devcom on August 13, 2008, 03:21:43 AM

Code: [Select]echo.Hello how are you?
set /p answ=
echo.user: %answ%

echo.write a number
set /p answ=
echo.user : %answ%
set /p allow user to input text and save it to variable
Yeah but he said he didn't want the user to input anything Thanks for the prompt replies...


You are right Carbon Dudeoxide --->

----- "I want the batch file to interact with CMD Window?-----
I think I am starting to get a vague idea of what you want.....

So you start a batch file, it will ask 'How Are You?' and you want it to automatically reply and say 'fine'?

Lol, is it just me or is anyone else getting confused? Actualy i m implenting a code from java which EXECUTES on command prompt but cmd prompt hangs and waits for an answer.. i want this answer to automatically reach cmd prompt..... any way HW can i do that....Anything you can show us or give an example?jsut an example for what i mean.....

In Java :

Process p = runtime.exec("cmd /c start xcopy c:\abc.txt c:\bin /m);


at cmd prompt:

c:\>xcopy c:\abc.txt c:\bin /m
Does C:\bin specify a file name
or DIRECTORY name on the target
(F = file, D = directory)? _


--- here cmd prompt expects an input which I want to come automatically
Quote from: MAKT on August 13, 2008, 04:55:11 AM
Thanks for the prompt replies...


You are right Carbon Dudeoxide --->

----- "I want the batch file to interact with CMD Window?-----


lol, i didnt read it carefully
4724.

Solve : Parsing text file to get variables.?

Answer»

I'm trying to parse multiple text files to determine whether a dummy mac was used or not for a setup script. MAC is the 3rd field. I thought about looking for the first X# of characters but given that I don't know if the reserved IP is 1, 2, or 3 digits long, I need to figure out how to get it for all 3 conditions. (batch file will be run on W2k)

The files would all look similar to this example:
RIP,7,000000000007,TM####A,"Unassigned",DHCP
RIP,80,000000000080,WS####A,"Unassigned",DHCP
RIP,81,000000000081,WS####B,"Unassigned",DHCP
RIP,203,000000000203,WS####RR,"Unassigned",DHCP
RIP,204,000000000204,WS####SS,"Unassigned",DHCP
RIP,205,000000000205,WS####TT,"Unassigned",DHCP
RIP,219,001E4F4DBC54,WS####ZZ,"DELL_GX745",DHCP

My thought is once I figure out how to get the MAC inta a variable, that I will run multiple loops that get the MAC from the control file, and compare it to what is in the configured file dump. With one loop to do this for each file that I need to compare.

Worst case, I will just do multipe search and replaces for RIP,#, and replace it out so that I know the first 12 will ALWAYS be the MAC.

Thank you in advance for your HELP!Code: [SELECT]@echo off
setlocal enabledelayedexpansion

REM line format in test.txt is as follows:
REM RIP,204,000000000204,WS####SS,"Unassigned",DHCP

REM The FOR line does this:
REM for each line in test.txt, deem the line
REM to be 6 tokens SEPARATED by commas.
REM create one explicit variable called %%A
REM and load the first token into it.
REM
REM Load the remaining five tokens into
REM five implicit variables called %%B %%C %%D %%E %%F
REM ready to be expanded if called for.

for /f "tokens=1-6 delims=," %%A in (test.txt) do (

REM get the 3rd token by expanding %%C
REM and store it in the variable called mac.
set mac=%%C

REM In a loop, we need to USE delayed expansion
echo !mac!
)
That's exactly what I was looking to get. I will be plugging away at getting to the next steps from these results. Thanks much.

4725.

Solve : My DOS sytem finally failed?

Answer»

I have one PIECE of software which ran on a 386dx40. Today (14 years in) I finally got the "non sytem disk error".
I have moved the HDD to a E-Machine PC running Win XP SP2. With the HDD installed alone my old program was able to launch. (Full DOS 6 environment is working along with FAT, MBR ? I just know enough to be dangerous)
I have copied the files to 2 locations for archival purposes and hope to still run the DOS program.
btw, Windows XP does not report errors on the Drive.
Question/Opinions please..
Would I want a DOS emulator? my program will not run with Win XP running. (In command window or outside of it)
Would I want to use a boot manager - not my choice as I need both systems open all day.then you might want to use a emulator, try dosbox http://dosbox.com/ i use it to play Street fighter 2 and it works good,That application wouldn't be the Borland QUATRO spreadsheet would it?

I KEPT a spreadsheet with it under DOS, and ever since my last DOS machine died a number of years ago I've been thinking I OUGHT to resurrect that thing somehow. But Quatro won't run in a Windows command prompt window or under Wine on Linux like I had hoped. I tried some other emulator quite a while ago, maybe it was DOSBox, but it didn't work either.

Some DOS programs really bent the rules of good software design in the NAME of performance, and now you can't run them.

One thing I don't think I tried yet is to boot some PC with a FreeDOS CD and try it.

But anyway, there are three options here that might work, depending on what application it is:
FreeDOS, DOSBox, and Wine.Ken, the program is for Print Estimating, so it is mostly a database spreadsheet application. DOSBox has it up and running smoothly. I've edited the DOSBox.conf file to launch my program automatically. The authors last instruction to change directory may be in error as DOSBox errors. From the c:> I simply execute my program .com

4726.

Solve : Extract first characters from each line from a txt file?

Answer»

Who KNOWS how can i extract for example 10 characters from each line from a txt file.
And for each extracted string to SAVE it in a txt file.
Google couldn't help me this time. Code: [Select]@echo off
setlocal enabledelayedexpansion
if exist target.txt del target.txt
for /f "delims==" %%L in (source.txt) do (
set string=%%L
set firstchars=!string:~0,10!
echo !firstchars! >> target.txt
)


THANKS a lot!!! That's it, it WORKS.

4727.

Solve : Help!!! How Do I Delete All folder From A Directory?

Answer»

I have a problem deleting all folders in a directory.The only way i found is to use rd /s [NAME Of Folder],but i want to delete all folders at once... I tried rd /s *.* & rd /s * but that did not worked.The same with del command. SORRY For My Bad English Waiting for your help...TyCode: [Select] rd /s [Name Of Folder]

That is the correct format to use. Specifically what did you use for name of folder?

Quote

but i want to delete all folders at once

What result did you get?

Note: Expect incorrect results if you're logged-in to any directory within the named folder tree structure.

First of all i want to thank you,for replying in my post.Now if i have a folder named Folder1 i write rd /s Folder1.With this way i delete the folder and all the subfolders contains in it.My problem is if i have in a folder other 10 folders.How can i delete these 10 folders all at once???(I don't want to delete the first folder,i want to enter to first folder and then delete everything that is in it. Waiting....In order to GIVE you UNDERSTAND i'll give you an other example.If i want to delete all the files a folder contains i write del /q *.* .Now with rd what should i write instead of *.*?Quote
I don't want to delete the first folder,i want to enter to first folder and then delete everything that is in it

That was an important piece of information.

Code: [Select]@echo off
for /f "tokens=* delims=*" %%i in ('dir /s /b /a-d folder1') do (
del /f %%i
)
for /f "tokens=* delims=*" %%i in ('dir /s /b /ad folder1') do (
rd /s /q %%i
)

Note: You should use a fully qualified path to folder1. The code is written as a batch file to be run from the command prompt.
I will look for what this loop does.Now i can't understand exactly.I will look for it and you will have my reply if i accomplished it.
4728.

Solve : Makedependen warnings?

Answer»

I am USING makedepend source downloaded from
http://llg.cubic.org/docs/vc7.html

Now as I am using this it returns me NUMBER of warnnings that Quote

C:\makedepend\makedepend: warning: C:/Program Files/Microsoft Visual Studio/VC98/Include/winuser.h: non-portable WHITESPACE encountered at line 2444

Can any one help me out to slove this , while before using this CODE I was not getting this warning with makedepend .

previously I use makedepende exe provided by someone , I dont have the source code of that one.

Thanks for any help .makedepend utility always complains about whitespace before the '#' in preprocessor directives.

if any one get this warnings the easiest way to avoid that , dump these warnings into a temp file and deleting this temp file at the end.
4729.

Solve : Search and Replace files in a folder?

Answer» WOW! I mean I want to replace Q10,Q10_,Q10- into Q1. Should this pattern "\s[Qq]1\s" work on that scenario as well? I'm having a hard time deciphering your intent.

If you want to replace Q1 with Q1,Q1_,Q1- then yes, the pattern posted should do it.

If you want to replace Q1,Q1_,Q1- with Q1, then no, the pattern does not match the data.

In the script, the input box is the replacement string and the pattern is what you're searching for (hardcoded into RegEx.Pattern).

BASED on your test data, q1 q1 0q1 1q1 q1 0q10 q10 q100 q1, you don't need a regular expression to see that Q1,Q1_,Q1- is an incorrect pattern.

Did you use the tool I suggested. It won't do the replacement, but it will indicate if the pattern matches the data. Always a good first step.

Hey! How can we modify your latest vbscript to have a counter for those affected files only. 'Coz what I want is to show the number of files affected (texts changed) and what are those files thru a msgbox after the process is done. You can use the test method of the regular expression. Not sure what version of the script we're using so I used the last script posted. The new code has not been tested, you make have to tweak it a bit.

Code: [Select]Const ForReading = 1
Const ForWriting = 2

strReplace = InputBox("Enter Replacement String: ","Text to replace!")

Set RegEx = CreateObject("VBScript.RegExp")
RegEx.Pattern = "(\bq1\b)"
RegEx.IgnoreCase = True
RegEx.Global = True

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("C:\44444444\builder") 'use your directory
Set fc = f.Files

count = 0
For Each fs In fc
If fso.GetExtensionName(fs) = "xml" Then
Set fi = fso.OpenTextFile(fs.Path, ForReading)
strContent = fi.ReadAll
fi.Close
Set fi = fso.OpenTextFile(fs.Path, ForWriting)
retVal = RegEx.Test(strContent)
If retVal Then
newContent = RegEx.Replace(strContent, strReplace)
fi.Writeline newContent
count = count + 1
Else
fi.WriteLine strContent
End If
fi.Close
End if
Next

MsgBox "Done! There were " count " files affected"

Happy trails. Thankz Bro! I'll check this code in a bit. Have a 'lil problem 'bout regex. Ex.: My text fiIe has the contents of "Q1", "Q1_1", "Q1_2", "Q10", "Q10_1" ... and I want to change Q1 only into something like "Q50", "Q50_1", "Q50_2" ... For that I'd used the pattern "q1\b|q1_" 'coz per this site -> "http://msdn.microsoft.com/en-us/library/1400241x(VS.85).aspx" =>

x|y -> Matches either x or y. For example, 'z|food' matches "z" or "food". '(z|f)ood' matches "zood" or "food".

I'd tried it and it didn't WORKED for me, only "Q1" are affected. Any idea what's the cause? Is my pattern wrong? Quote
Is my pattern wrong?

Of course it's wrong, it's always the pattern.

Try using \s for the white space instead of \b.

You can try this: "(q1\s|q1_)"

It would be helpful to let us see the first 10 or so records from the text FILE. Stringing it out makes it harder to visualize what the actual data looks like.

Try to keep the pattern simple.Hey! It still won't work. For example: This is the content of my text file:

"q1" "q1_1" "q1_2" 0q1 1q1 q1 0q10 q10 q100 q1
George Bush
"q10" "q10_1" "q10_2"

and I want to replace all occurrences of q1 like in "q1", "q1_1", "q1_2" and change them into "q50", "q50_1", and "q50_2". Also, "Q10" should not be affected neither "q10_1" or "q10_2". hey! Your code works but it replaces also the underscore in "Q1_1" or "Q1_2" and turned them into "Q501", "Q502" assuming I replaced Q1 by Q50. You have all the tools you need to get the script working. I'm thinking that regular expressions may not be a solution after all.

There does not seem to be any pattern to the data, although I did find Waldo It's one thing to replace all the q1 with Q50, it's another to have leading quotes, leading spaces and leading numeric characters along with trailing quotes, trailing spaces and trailing characters with different rules as to when to make a replacement..

For example, if you use the double quotes in the pattern, you need to use them in the replacement string. This sounds simple enough until you find newly quoted strings that never had quotes in the original text. If you don't use quotes in the pattern, you run the risk of making replacements that shouldn't be made.

It might be easier to parse each word and decide whether to make a replacement or not. In this manner you could change the pattern depending on the chunk of data you've parsed.

Good luck. OK. I'll THINK about that. I'll look for some other solutions on this one. Thankz!
4730.

Solve : Multiple files on batch?

Answer»

Hey guys,

Just WONDERING how to run two or more programs at the same time through a batch file, as an example

@echo off
cls
echo This is an example
utilman
mstsc
secpol.msc
lusrmgr.msc

if you TRY this out you can see only one opens at a time, it does get distrubing when your in a rush to finish some work, any help will be great...

thanks Curious.....why do you need to run all of those at the same time?

Try putting 'start' at the BEGINNING of the utility name.Thats WORKS perfect, THANK Carbon

The reason i needed this is because without the 'start' before command line it opens after you close previous task, this is delaying when you are trying to do two or more things at once if you know what i mean

KhasNo.....but as long as you're satisfied.

4731.

Solve : ping more than one ip?

Answer»

is it possbile to ping more than one IP WITHOUT any script or appalication or etc.How do you mean?You can run SOMETHING like this from the command prompt:

Code: [Select]for %v in (204.228.150.3,69.147.108.30) do ping %v

No script. No APPLICATION. Just down and dirty.

Quote from: Sidewinder on AUGUST 13, 2008, 11:33:35 AM

You can run something like this from the command prompt:

Code: [Select]for %v in (204.228.150.3,69.147.108.30) do ping %v

No script. No application. Just down and dirty.



very very THANX
u r perfect Lol, okay...

Good Work Sidewinder
4732.

Solve : Boot CD + menu?

Answer»

Hi, I want to make a Bootable CD that has a menu appear giving options to auto run such utilities as "spinrite" "ghost" "Partition Recovery" etc.
I have successfully created a Ghost boot CD " (found instructions on internet) but had to use a windows .img file that seemed to restrict my CD files size to 1.4mb. Don't know why. This stopped me from adding the other programs that I would have been able to navigate to manually.
I have limited experience making batch files but do understand basic programming and basic DOS commands.

I know I will need a version of DOS, the Utilities and a "menu script" called at boot up. I assume that will be Autoexec.bat.
At this point I only have the utilities ready.

Could someone help me with the recipe to bake a CD with 'my menu' as the 1st screen seen please?

Thanks in advance, Darrell



you arnt being CLEAR enough, what do you need to do?
Are you using DOS , or command.exe or cmd.exe ?
you need autoexec.ini to run in later version of windows
you need autoexec.bat to run in earlyer versions of windows


the .img file you burned is the cd image itself so a 1.4mb cd image
is the entire disc, i may be wrong about that, but it DOESNT make sence to have
more then one image on a disk.The reason the .img's came out this size is you probably clicked the default .img size during the burn which for some reason was set to floppy size...
What program did you burn with ? ?Ok, sorry about the lack of info. I do a lot of repairs to PC's and often need to boot a broken PC. The CD I wish to make will run independently of any OS and needs to boot into a 'menu' giving me options to goto various programs eg: ghost, spinrite ( to test and fix hard-drives) etc. It's equivalent would be a Barts PE or knoppix although this won't have the overhead that those Live CD's have.

As I said, I managed to make a boot CD which automatically starts into ghost, I use this to try to copy the hard-drive onto another hard-drive before I try to fix it. It basically replaced my ghost floppy boot disk.
Now I would like to go one step further and add an menu that I can select by a number that gives me possibly 4 or 5 choices of my most used utilities (all were once bootable floppies).

I currently have the following files: on my ghost boot cd:
=====================
autoexec.bat
command.com
config.sys
io.sys
mouse.com
mouse.ini
mscdex.exe
msdos.sys
oakcdrom.sys
AND 2 folders called ghost (ghost.exe inside) and net (1 nic driver inside + netbind.com)

BTW I don't need the nic\net stuff as it doesn't work unless the PC has the 1 and only driver that I put into the folder. I just used the net bit because it was PART of the only METHOD (recipe) I could get working, so I just left it in. It throws an error and just skips over it and boots straight into ghost. Yahoo!!
======================

My autoexec.bat looks like this

@echo off
SET TZ=GHO+08:00
mscdex /L:D /d:mscd001
MOUSE.COM
\net\netbind.com
echo Loading Ghost...
D:
cd \ghost
GHOST.EXE

if %config% == FROMFLPY goto FLPYBOOT
if %config% == FROMCD goto CDBOOT

goto FAILED

:FLPYBOOT
echo Insert Ghost boot disk 2 (containing Ghost.exe)
pause
if exist a:\ghost\ghost.exe goto GHOSTFND
goto FLPYBOOT

:CDBOOT
echo Insert Ghost boot disk 2 (containing Ghost.exe)
pause
if not exist b:\ghost\ghost.exe goto CDBOOT
b:
goto GHOSTFND

:GHOSTFND
cd \ghost
echo Loading...
GHOST.EXE
goto END

:FAILED
echo Unknown boot menu selection
goto END

:END

============================
I think the help I need is what version of DOS to use (maybe the one I already have, the file is dated 16/07/1999), what other files to use, if any, and how can I make the whole 700MB CD available so I can put extra programs on it.
Obviously an example of a simple menu DRIVEN Batch file would be the other main bit of info I would need. I am able to edit it to suit my needs if needed once I have an idea of how it would work.

I hope this info is more complete and you can help. Thanks again. Darrell



The menu is built in config.sys. This is a copy I built to load different NIC drivers.

[menu]
MENUITEM=650, Dell Precision 650, Dell Precision 670
MENUITEM=745, Dell Optiplex 745
MENUITEM=755, Dell Optiplex 755
MENUITEM=7500, Dell Inspiron 7500
MENUITEM=C840, Dell Latitude C840
MENUITEM=D800, Dell Latitude D800, D810, D820, D830
MENUITEM=GX270, Dell Optiplex GX270
MENUITEM=GX280, Dell Optiplex GX280
MENUITEM=GX620, Dell Optiplex GX620

[COMMON]
DEVICE=HIMEM.SYS /TESTMEM:OFF
BREAK=OFF
DOS=HIGH,UMB
FILES=10
BUFFERS=10
LASTDRIVE=Z
SHELL=COMMAND.COM /P /E:1024
DEVICE=OAKCDROM.SYS /D:MSCD000
DEVICE=GCDROM.SYS /D:MSCD001 /C0
DEVICE=GCDROM.SYS /D:MSCD002 /C1
DEVICE=GCDROM.SYS /D:MSCD003 /C2
DEVICE=GCDROM.SYS /D:MSCD004 /C3

[650]
DEVICE=\650\protman.dos /I:\650
DEVICE=\650\dis_pkt.dos
DEVICE=\650\e1000.dos

[745]
DEVICE=\745\protman.dos /I:\745
DEVICE=\745\dis_pkt.dos
DEVICE=\745\B57.dos

[755]
DEVICE=\755\protman.dos /I:\755
DEVICE=\755\dis_pkt.dos
DEVICE=\755\e1000.dos

[7500]
DEVICE=\7500\protman.dos /I:\7500
DEVICE=\7500\dis_pkt.dos
DEVICE=\7500\CBENDIS.EXE

[C840]
DEVICE=\C840\protman.dos /I:\C840
DEVICE=\C840\dis_pkt.dos
DEVICE=\C840\EL90X.dos

[D800]
DEVICE=\D800\protman.dos /I:\D800
DEVICE=\D800\dis_pkt.dos
DEVICE=\D800\B57.dos

[GX270]
DEVICE=\GX270\protman.dos /I:\GX270
DEVICE=\GX270\dis_pkt.dos
DEVICE=\GX270\E1000.dos

[GX280]
DEVICE=\GX280\protman.dos /I:\GX280
DEVICE=\GX280\dis_pkt.dos
DEVICE=\GX280\B57.dos

[GX620]
DEVICE=\GX620\protman.dos /I:\GX620
DEVICE=\GX620\dis_pkt.dos
DEVICE=\GX620\B57.dos

4733.

Solve : if error occurss???

Answer»

Hello everyone ,

For example ;

echo %number%>>C:\users\user1\desktop\test.txt

Assume that there is no path like this above on computer and after running the program echo gives error how do i UNDERSTAND that echo has error and how do i avoid displaying the error that occured to the screen .

Thank you Putting 2>errorlog.txt will SEND error messages to a log, and using the ERRORLEVEL variable can tell you what type of error. Echo something 1>file 2>errorlog.txt
If %errorlevel% neq 0 echo ERROR OCCURRED& goto menuAdd "if %errorlevel% neq 0 goto menu" after the commands. %HOMEPATH%\DesktopQuote from: BC_Programmer on September 10, 2009, 07:55:06 PM

%HOMEPATH%\Desktop
HOMEPATH doesn't have a drive. Use %userprofile% homedrive and path together.
Don't replace the RED with the variables.

Try using this as the path.

"%userprofile%\Desktop\%nameset%.bat"
4734.

Solve : how to uninstall the password protected software??

Answer»

in my pc i have installed "blue coat K9 web protection software"
now i NEED to uninstall it but i forgot my password.
but my e-mail id given at the time of installation was a wrong id becoz of my negligence.
now please find me a solution through the ms dos to find password or to uninstall the software without the password


if its secrete send the solution to my id [EMAIL removed to prevent UNWANTED spam]
the person who answers this problem-can get command to do extraodinary locking and security tasks in is system,

so please hellp me.Welcome to the forums.

You make it sound like you are LOOKING for a way to bypass a password lock-out.

What are you intentions?

4735.

Solve : cmd mac address print into file ????

Answer» HELLO everyone ,

How can i PRINT MAC address of the computer to txt file and create file on desktop as default lacation for the local area network

THANKS try getmac
4736.

Solve : CPU usage during batch execution?

Answer»

If I write a batch to loop constantly in order to check a change in VALUE, it will DRIVE the CPU usage up to 100%. Other than using AT or SLEEP, can I make it a less intensive PROCESS? How does AT work without visible CPU usage anyhow?The AT command works with your SYSTEM's Scheduled Tasks, by adding whatever to the list of Tasks to do.

Instead of sleep try the Ping command for use as a wait command:
Code: [Select]ping -n 1 -w <Time to wait> 1.1.1.1
The ping command measures in milliseconds so:
1000 would be the same as 1 second.

4737.

Solve : Using Findstr /x can't find exact match.?

Answer»

When using:

Code: [Select] echo X>>FILE.txt

FINDSTR /x "X" %CD%\file.txt
The echo places a space and newline character after the "X" so when i try and find and exact MATCH it doesn't find it. Is there a way to either:

a) not place a space and newline character when echoing
b) add a space and newline character when using findstr /x

cheers FBWorks fine for me:

Quote

C:\Temp>echo X>>file.txt

C:\Temp>findstr /x "X" file.txt
X

C:\Temp>findstr /x "X" %cd%\file.txt
X

Quote
The echo places a space and newline character after the "X"

How do you know that? I suspect it inserts carriage-return and LINE-feed characters. What version of the command PROMPT are you using?

OK having tried to go through this step by step logically i can't see what's going on... maybe it's something to do with having more than one string in the file my actual code looks like this:

Code: [Select] findstr /x /i %comm% %CD%\users\current\software.dat >num.dat
where %comm% is a user defined variable and the file software contains:

"help
list
telnet
account
bbs
cracker
"
when i write a test script to find out what's wrong it sometimes works and sometimes doesn't

I suspect your right it's probably a carriage return and line-feed and i don't know what version, im using Vista so i guess the latest?I suspect the lines it doesn't work for are the first and last lines. You only have one word per line. Why even use the /x switch? The /i switch makes it case insensitive, which is not an exact match anyway.

Code: [Select]@echo off
set comm=help
findstr /i "%comm%" %CD%\users\current\software.dat >num.dat


4738.

Solve : Find and Copy files in dos from undefied path?

Answer»

Hi all, I am new to this FORUM, kindly help me to find out the things.

I have created some of BATCH files to copy,transfer,PRINT files from specific path in command promt.

Now I want to find Microstation DGN files from my hard drive. I dont know the exact path where the file would be located but i have the path like this " D:\Complex\Area\Work\Agency\Drawing\...\.....\.... " I know that into "drawings" i can have my .DGN file but in that Drawing directory there are some more child directores & how to find them through dos ?

Now can I get these drawings & paste in other drive(defined path) from DOS prompt ??
what would be the code of batch file for this ?
What OS are we talking about. If it's vista then you can use the where command. Code: [Select] where /?
Else you'd have to use: Code: [Select] dir /a-d /b /s D:\Complex\Area\Work\Agency\Drawing\*.DGN
that will list all .DGN files in drawings and all SUB directories. to copy them you need to output that information into a .TXT file and then use xcopy to copy them to the new directory.

FB

4739.

Solve : How to pipe or redirect STDOUT into an EXISTING Console application's STDIN?

Answer» HI,
I want to launch and read the output of a DOS .bat process from WITHIN another programming language (LabVIEW.) if I launch both the DOS-command and my app this way:

MyBat.bat | MyApp.exe

Then MyApp's STDIN does receive the STDOUT of MyBat - MyBat is a .bat file that loops indefinately and updates the CONSOLE (or STDOUT) once a second.

... the trouble is, I need to launch MyBat from within MyApp - which I can do - but how to pipe/redirect MyBat's STDOUT so MyApp can read it?

It's not acceptable to write-to/read-from a disk-file!

Can I use
MyBat > ?
or
MyBat | ?

to write to MyApp's STDIN? - If so, how?

I don't understand the nature of the arguments to the pipe and redirect operators, but wonder if, perhaps, a DEVICE can be defined such that MyBat could pipe or redirect to MyDEVICE, and MyApp could read from it?

Any help is appreciated,
Cheers! Maybe it would help if you could tell us what is the piratical use. Batch files are just that. Batch files. They have limited ability to respond to events. They normally do a sequence of stuff as fast as they can and then quit.
Sometimes an application needs data from the DOS command line. The application can start a 'shell' process that invokes a DOS command and then closes the shell.
But if you have something that returns once a second, maybe it should be a device. The serial port on modern computers can store up to 16 bytes of data without overflow. So you would not need a ISR or DMA if the data were LESS that 16 bytes each time.
4740.

Solve : how to put space between echos???

Answer»

Hello ,

how can we PUT space between to echo to display space

for EXAMPLE

echo hello
how can i put space here
echo world


i want display like

hello
space ??
worldIf you want to use Echo as a newline, TRY this:
Code: [Select]echo.
Will just display a blank lineone method would be to do the following:

set /p choice= SYSTEM IS WAITING FOR YOUR CHOICE:

this will display each space after the equals sign.Try doing like you did for echo:

Code: [Select]set /p choice=. System is waiting for choice:

4741.

Solve : Remote Shutdown Command?

Answer»

okay, this: HTTP://support.microsoft.com/kb/919216 article was used......I didnt already have a restrictremoteusers key value, so i created ONE, and set the value to '0'. I also disabled "Restrictions for Unauthenticated RPC Clients" in the Group Policy Object Editor. Yet, I am still DENIED access for remote shutdown. http://blogs.msdn.com/aaron_margosis/archive/2006/01/27/518214.aspxQuote from: Dias de verano on August 18, 2008, 11:24:21 AM

http://blogs.msdn.com/aaron_margosis/archive/2006/01/27/518214.aspx

I added INTERACTIVE to the list, but i am still told access denied
4742.

Solve : How do I copy text in a text file to another file using batch file??

Answer»

Hi All,

I am using windows XP pro and I need to be able to take a RAW text file and using a batch file and pipe out certain information into another text file.

Example:

Raw text file may contain name, address, phone etc… and I want to take all the text lines that have the name “Smith” in them and COPY them to another text file called ‘Names.txt’

Is there a way to pipe the entire line into another file?

THANKS for your help
Ken


You can use the Type command and pipe its output through Find.exe.

Suppose Rawfile.txt contained these lines

John Smith
Bill Brown
Sam Jones
Smith Z Wilson
George W Shrub
Amy Q Smith

then this command would create a file called Names.txt

type "Rawfile.txt" | find "Smith" > "Names.txt"

Names.txt would look like this

John Smith
Smith Z Wilson
Amy Q Smith
Thank you very much... That does what I want. Have a Great Day!

Ken

4743.

Solve : please help me it is an emergency?

Answer»

I have a FAILING drive and need to copy it using x copy I think it is finding the failing drive as drive F:

I want to copy it to a new folder on my C: drive but need to make the folder first to put the drive in.

Can someone please help me make a new folder and copy the failing drive to to the C: drive new folder.

thanks for the helpAt Windows start run type cmd

At command shell type cd\.

At C:\> type md foldername ((( foldername being say DRIVEC )))

next enter at the C:\>

xcopy f:\*.* c:\foldername\*.* /s/d/y ((( replacing foldername with say driveC if you used that name )))

if the drive is healthy enough you will get all your data. If there are bad sectors your system may copy data until it hits the bad sector and fails if this is the case you can try to run SCANDISK on the F:\ drive to try to patch the bad sectors and then try the process above again.

Depending on how much data you have this can take a while, andbe sure drive C:\ had adequate space to take all of F:\ or you will run out of HD space on the C:\ driveI did it but it copied 153 files that I didn't recognize and said not enough disk space. The drive I am trying to copy is 80 GB to a C: drive of 250 GB free. I am in the vista dos prompt

is there something else I can do since it appears dos can see the drive but windows can't? I ran spinrite and it can see the info too. I just need to get the files off then i can trash the drive.
I recommend Teracopy from http://www.codesector.com/teracopy.php

Very real benefits for you include :-

* Error recovery. In case of copy error, TeraCopy will try several times and
in the worse case just skips the FILE, not terminating the entire transfer.

* Interactive file list. TeraCopy SHOWS failed file transfers and lets you fix
the problem and recopy only problem files.


I am happy with the Free portable version
There is a Pro version also, but I only spend money when the free version is inadequate.

Regards
Alan
Not sure if this is appropriate, but if you try to copy a file >4Gb to a FAT formatted drive, you get just that error message (not enough space)

If your C: drive is fat formatted and your F: drive is ntfs, then that is likely to be the problem

Grahamis there a way around it?
http://www.wdc.com/en/products/index.asp?cat=5


http://www.wdc.com/en/buy/wheretobuy.asp?lang=en


http://store.westerndigital.com/store/wdus/DisplayHomePage
Quote from: gpl on June 08, 2009, 09:46:55 AM

Not sure if this is appropriate, but if you try to copy a file >4Gb to a FAT formatted drive, you get just that error message (not enough space)

If your C: drive is fat formatted and your F: drive is ntfs, then that is likely to be the problem

Graham


if he's running Vista from a 250GB C: drive, I doubt it's FAT

Quote from: ALAN_BR on June 08, 2009, 09:19:43 AM
I recommend Teracopy from http://www.codesector.com/teracopy.php

Very real benefits for you include :-

* Error recovery. In case of copy error, TeraCopy will try several times and
in the worse case just skips the file, not terminating the entire transfer.

* Interactive file list. TeraCopy shows failed file transfers and lets you fix
the problem and recopy only problem files.


I am happy with the Free portable version
There is a Pro version also, but I only spend money when the free version is inadequate.

Regards
Alan


XCOPY can do the very same thing. /C can be used to continue copying if an error occurs.

Also, since there is the option to only copy files that already exist, as well as a way to output files that would be copied, one can redirect the output from that display of possible files with the switch to only show those that already exist in the destination, and, on a subsequent use that list of files that do exist in the destination as the /EXCLUDE: parameter.


It takes a little thought but the same functionality that "teracopy" offers is reproducable via XCOPY, thanks to it's large number of options.





I agree xcopy can do this sort of thing

I like the fact that if Teracopy has a problem getting a good copy, it will automatically make several repeated attempts before moving on, with no manual intervention

Additionally it checksums each source file and each destination copy, and compares the results, and gives a nice summary of the failures.

Regards
Alan
4744.

Solve : help please ECHO PROBLEM it doesnt write into text file?

Answer»

hello

in my program i GET inputs from the user and i wanna print in to TEXT file but it doesnt print the varible i get from user can you help

ECHO ------------------------------------------------------------------------
set nameset=
set /p nameset=Please Name your Setup File LIKE OFICE,HOME etc.:
echo ------------------------------------------------------------------------
set userna=
set /p userna=Please type your exact USERNAME ON WINDOWS and Press Enter Key:
echo ------------------------------------------------------------------------
set ip_addrress=
set /p ip_addrress=Plaese Type your IP ADDRESS and press Enter Key:
echo ------------------------------------------------------------------------
set subnetmaks=
set /p subnetmask=Please Type your SUBNET MASK and press Enter Key:
echo ------------------------------------------------------------------------
set dgatew=
set /p dgatew=Please Type your DEFAUT GATEWAY and Press Enter Key:
echo ------------------------------------------------------------------------
set dnsnum=
set /p dnsnum=Please Type Dns Number and Press Enter Key:

echo netsh interface ip set address "LOCAL Area Connection" static %ip_addrress% %subnetmask% %dgatew%>>C:\test.txt
h














C:\>writetofile.bat
Please Name your Setup File LIKE OFICE,HOME etc.: home
Please type your exact USERNAME ON WINDOWS and Press Enter Key: billrich
Plaese Type your IP ADDRESS and press Enter Key:999999999
Please Type your SUBNET MASK and press Enter Key: 6666666
Please Type your DEFAUT GATEWAY and Press Enter Key: 8888888
Please Type Dns Number and Press Enter Key: 3333333
ipinfo is:
nameset is home
userna is billrich
ipaddress is 999999999
subnetmask is 6666666
Default is 8888888
DNS Number is 3333333

Windows IP Configuration


Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : ok.cox.net
IP Address. . . . . . . . . . . . : 68.999999999

Subnet Mask . . . . . . . . . . . : 8888888888888
Default Gateway . . . . . . . . . :6969696969


C:\>type writetofile.bat

Code: [Select]@echo off

set nameset=
set /p nameset=Please Name your Setup File LIKE OFICE,HOME etc.:
echo nameset is %nameset% > ipinfo.txt

set /p userna=Please type your exact USERNAME ON WINDOWS and Press Enter Key:
echo userna is %userna% >> ipinfo.txt

set /p ip_address=Plaese Type your IP ADDRESS and press Enter Key:

echo ipaddress is %ip_address% >> ipinfo.txt


set /p subnetmask=Please Type your SUBNET MASK and press Enter Key:
echo subnetmask is %subnetmask% >> ipinfo.txt

set /p dgatew=Please Type your DEFAUT GATEWAY and Press Enter Key:

echo Default is %dgatew% >> ipinfo.txt

set /p dnsnum=Please Type Dns Number and Press Enter Key:
echo DNS Number is %dnsnum% >> ipinfo.txt

ipconfig >> ipinfo.txt

echo ipinfo is:

type ipinfo.txt

4745.

Solve : Make batch react to buttons?

Answer»

Dias, this interests me the most.
Code: [Select]REM Create getkey.com
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>getkey.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>getkey.com
echo l/[emailprotected]>>getkey.com

What and how is this done?A .com program is an 8086 assembly language program for running under MS-DOS. The effect of the lines you quoted is to create such a (previously written) program byte by byte. What the program does is

1. wait for a keypress
2. place the ascii value into errorlevel
3. exit
Quote from: Dias DE verano on October 11, 2008, 03:31:08 AM

1. Your code only works for lowercase letters of the alphabet 'a' to 'z'.

2. But you show uppercase letters to the USER. ASCII 97 is 'a' not 'A'. The keypress program gives a different code if a key is shifted or if Caps Lock is operative.
Would the use of /I make uppercase and lowercase the same?Quote from: Sky Ninja on October 11, 2008, 10:06:52 AM
Would the use of /I make uppercase and lowercase the same?

The use where?

Nevermind, it wouldn't. I meant in the if's.
Anyway, I figured out how to get new errorlevel settings.
Code: [Select]set key=%errorlevel%
[b]echo %errorlevel% >C:\errorlevel.txt[/b]
REM ASCII value of key is contained in %Key% Press a known key, then press an unknown key, and if it's different from the known key, you've got a new errorlevel.
Code: [Select]If %Key%==48 echo 0 [%Key%]
If %Key%==49 echo 1 [%Key%]
If %Key%==50 echo 2 [%Key%]
If %Key%==51 echo 3 [%Key%]
If %Key%==52 echo 4 [%Key%]
If %Key%==53 echo 5 [%Key%]
If %Key%==54 echo 6 [%Key%]
If %Key%==55 echo 7 [%Key%]
If %Key%==56 echo 8 [%Key%]
If %Key%==57 echo 9 [%Key%]
::----------------------------------------------------------
If %Key%==13 echo ENTER [%Key%]
::----------------------------------------------------------
If %Key%==27 echo Escape [%Key%]Without wishing to be horrible, I will point out that code which contains a zillion lines like this:

Code: [Select]IF X = 1 goto one
IF X = 2 goto two

[...]

IF X = 254 goto twofivefour
IF X = 255 goto twofivefive

(etc)


... is generally the mark of the beginning coder. Sometimes it cannot be avoided, but it is much better to find a more compact SOLUTION, which I already have shown.

Hey, this is just an addition to Jacob's code.
4746.

Solve : Please Help!!!!?

Answer»

A COMPANY gave me a compaq 800 and when it boots up it reads DISK ERROR....but when I put in Windows xp it installs half way then reads the same thing and RESTARTS....How do i get to the Bios and DOS Command from here, or should i just replace the hard drive???Seems like the hdd has failed but it's always worth confirming by using the hdd manufacturer's diagnostics from here..

4747.

Solve : Verifying the content of the read string from input file?

Answer»

Hello,
I want to verify the content of the text read from the input file, before I transfer it to an out file.
I did try to put its content into a variable, but it doesn't work.
Some body can help me please?
Thanks.

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

However the following works:
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
echo.%%k>> "OutputFile"
)
You have to set it as a variable or it will on work within a for loop. Thanks for the answer...
But, if you want me to understand, could you WRITE down please.
Thanks.SET var=%%k

Then when you want to use the info from %%k, use %var% instead. I did try it before, and one more time now, but %var% is set Null.
So when I do
SET var=%%k
echo %var%
--> I get "ECHO is off." (that's because the variable is set to NULL)

If you want to whole example, look what I've send this morning around 10:30

ThanksIn the FOR loop, make sure that TOKENS=*Newbie batch lesson #2 (That means you, helpmeh, who ought to know this by now!)

delayed expansion

When a batch file is run, normally, all variables are expanded ONCE ONLY, at parse time. This happens before the code is run.

In a FOR loop or other place where code is between parentheses, attempting to set a variable whose value is not known at parse time causes it to be set to a null value (a blank) so that attempting to echo the variable is interpreted by cmd.exe as just echo by itself.

Unless you use delayed expansion:

1. use the setlocal COMMAND with the option enabledelayedexpansion
2. within the parenthetical structure, use exclamation marks ! instead of PERCENT signs %

Code: [Select]
@echo off

REM Do this once, e.g. at the start of the batch file
setlocal enabledelayedexpansion

FOR /F "tokens=1* delims=]" %%j IN ('type "%param%" ^| find /V /N ""') DO (

REM get the value held in the FOR metavariable into a variable
REM so we can slice it
set subStr=%%k

REM example: using echo to show value
echo Value 1 of subStr=!subStr!

REM now we can cut it down to its FIRST 12 CHARS
Set subStr=!subStr:~0,12!

REM example: using echo to show value
echo Value 2 of subStr=!subStr!

)


Incidentally, to protect against null variables producing "ECHO is off." messages at runtime, you can put some text, or at least a dot, after the echo, for example like this

echo.%var%

but if you get things right, you should not need to do this.



Thank you very much.
It works great.
The exclamation mark did all the difference.

4748.

Solve : How can I identify dynamic environment variables - SET does not help?

Answer»

gh0std0g74 - thanks for dropping in.

Quote from: gh0std0g74

cause AFAIK, %DATE% , %TIME% or %RANDOM% are little things that cmd.exe gives you out of convenience, they are not environment variables.

The Set command Help display (set/?) names these as "dynamic environment variables". AFAIK the placeholder does not contain a value, the value is computed when the dynamic environment variable is expanded. Not containing a value means that the dyn env var cannot be displayed using Set, there simply isn't anything to display.

Regards

D.What ghostdog means is, they are not "really" environment variables, in that they do not reside in the environment block (which is basically what "set" shows.)

Also- applications can only change the environment block- including acronis.

I would imagine that they documented what variables they define.Quote from: BC_Programmer on June 07, 2009, 10:04:16 PM
What ghostdog means is, they are not "really" environment variables, in that they do not reside in the environment block (which is basically what "set" shows.)
that's right. Dusty

When I first saw you jpeg I could not read it until I clicked and it enlarged.
When enlarged I saw " %cmdcmd line% ".
I now realize my tired eyes misplaced the space, it now LOOKS like %cmdcmdl ine%,
but when I greatly magnify the image I realize the "space" is an artifact due to "DOS" not using proportional spacing.

Thank you for your explanation. The world makes a little more sense now.

Thank you for the link to "The uses of Setlocal Enabledelayedexpansion",
and also for pointing me BACK to the use of "SET /?" - previously I never read through to the end because my problems were usually resolved halfway through ! !

Thanks to everyone who recently posted.

If Acronis created a variable "acronis_in_variable" I would be O.K. with "set acro=%acronis_in_variable%".
Unfortunately I do not know the name(s) of any variables they may create,
and do not even know if they create any at all.

n.b. My interest is in ANY sort of variable that Acronis may use or influence,
not just fixed and dynamic, but also other sorts (I vaguely remember last year I encountered at least two other sorts, including "dynamic").

Regards
Alan
I think, what your seeing as "dynamic" variables, are merely variables Acronis adds before running your script.

See, when a program executes another program, it can pass a new environment block to that program. Acronis, for example, is possibly adding new variables to it's environment block and passing that as the environment of the script.

Havey you tried using "SET" from within your script? perhaps redirecting it to a file? This will reveal such variables.

I still believe that Acronis would have this type of stuff documented somewhere.Hi

No, we have a misunderstanding.

I have never seen any sort of variable that looked as though it was RELATED to Acronis.
I merely hoped that there was such a variable that might give me a clue upon what it was doing.

I have ALREADY tried
Code: [Select]ECHO CMDCMDLINE == %CMDCMDLINE% >> C:\Utils\CMD\ToBak.txt
SET >> C:\Utils\CMD\ToBak.txt
The first item shows me command issued by Acronis, which was
CMDCMDLINE == cmd /c ""C:\Utils\CMD\ToBak.cmd" A B C D"

I had been hoping to learn of other dynamic/volatile/special variables, such as %CMDCMDLINE%, which SET does not display, but which are displayed with a suitable
Code: [Select]ECHO %whatever%
to give me a further insight.

I have already inspected several MBytes of Acronis documentation without success,
and have also posted queries on the Acronis support forum looking for specific guidance.

I have lost hope of finding any useful Acronis variable of any sort, and think they probably have not created any such thing, so I am giving up on this and will use a totally different approach to meeting my requirements.

My thanks to everyone who has responded to this thread.
I have gained extra useful knowledge, even though my original quest has failed

Regards
Alan
it's also possible, that they are passing some items via command-line arguments to your batch file.Yes, my script captures
CMDCMDLINE == cmd /c ""C:\Utils\CMD\ToBak.cmd" A B C D"

The TRAILING "A B C D" are the only arguments that I receive, and they do not help me either !

Regards
Alan
4749.

Solve : Possible??

Answer»

Is it possible to create a batch file on one computer (my PC) that will tell it to shutdown, but leave (SOMETHING?) on so that a command could be run on my laptop and transmitted to my USB network adapter in the PC to tell it to start up? Am I crazy Simply, nope. thought notIf the computer supports Wake On LAN (WOL) then you can do it. You computer (NIC and BIOS) need to support WOL, and make SURE it is enabled in the BIOS. Then you can USE a program like http://www.wakecomputer.com/WOL/index.aspx or http://www.matcode.com/wol.htm to send a "MAGIC packet" to turn the computer back on. Your laptop can have a USB NIC, but the PC will need to have a hard-wired NIC that supports the WOL.Wake On LAN

good idea!Quote from: GURUGARY on August 17, 2008, 10:25:30 PM

If the computer supports Wake On LAN (WOL) then you can do it. You computer (NIC and BIOS) need to support WOL, and make sure it is enabled in the BIOS. Then you can use a program like http://www.wakecomputer.com/WOL/index.aspx or http://www.matcode.com/wol.htm to send a "magic packet" to turn the computer back on. Your laptop can have a USB NIC, but the PC will need to have a hard-wired NIC that supports the WOL.
I will look into this
4750.

Solve : Build a better Batch file (for changing zip -> 7zip)?

Answer»

I have tons of zip files, and I've been trying to recompress them into 7zip to get some disk space back and I wrote two batch files with for loops to first extract from .zip then when it finishes, it deletes all the zips and does the next for loop for the extracted files into 7zip like so:
Code: [Select] for %%i in (*.zip) do 7z.exe E "%%~ni.zip" -y
del *.zip

----Second Batch ----
for %%i in (*.jpg) do 7z.exe a -t7z -mx9 -mmt "%%~ni.7z" "%%i.jpg"
del *.jpg
So, very basic, but I have a folder with nearly 10gbs of neatly zipped files, if I run this, it'll be zip (10gb) + file (10gb) and I don't know if I have enough room. What I want is to extract, then compress, then go to the next file, any help would be greatly APPRECIATED!Never mind, I got it:

Code: [Select]for %%i in (*.zip) do (
start /wait c:\"Program Files"\7-zip\7z.exe e "%%~ni.zip" -y
del "%%~ni.zip"
start /wait c:\"Program Files"\7-zip\7z.exe a -t7z -mx9 -mmt "%%~ni.7z" "%%~ni.jpg"
del "%%~ni.jpg"
)

It is a waste of time to compress jpg images in zip files, as jpg format files are already compressed and not much further compression is POSSIBLE. However it is good to hide PICTURES of BIKINI babes from Mom and Sis.