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.

5501.

Solve : add line to .txt file?

Answer»

Been LOOKING all over for some way to do this.

i have a file called "times.txt"

looks like this

Code: [Select]0,0,23.809524
1,1,24.390244
2,4,23.809524
5,5,24.390244
6,7,23.809524
8,8,24.390244
how can i add a line like "First Line"

so that it looks like this

Code: [Select]First Line
0,0,23.809524
1,1,24.390244
2,4,23.809524
5,5,24.390244
6,7,23.809524
8,8,24.390244
the PROGRAM that uses this txt file wont accept it unless it has certain line at the start.
if i could batch do this to the file that is generated to be processed i could FULLY automate my script without adding the lines in myself.


any ideas?
alright:

Code: [Select]echo first line > times2.tmp
type times.txt >> times2.tmp
erase times.txt
ren times2.tmp times.txt


First thing that came to my head. MAKE sure to backup your files in case I screwed up.thanks worked like a dream. didn't think about TEMP files oh I forgot- add

Code: [Select]
erase times2.tmp

to the bottom of that

5502.

Solve : Batch File to Rename Filename that contains a % sign?

Answer»

Hi there, I have created a batch file that renames a bunch of files. Some of the filenames that I am TRYING to rename contains the % sign and those don't seem to work. Is there a way to rename the filenames that contain the % sign?

IE: Rename "C:\34%!.DOCX" "34%!.DOC"

Thanks,
PatrickHow did the filenames get percent SIGNS in the first place?

Doubling up each percent sign like this might work-

Code: [Select]Rename "C:\34%%!.DOCX" "34%%!.DOC"

It really is a BAD idea to have "ILLEGAL" characters in file names.
we are using a document management system and it converts the filename to these when documents are saved... All I am trying to do is rename the extension and I don't really have any flexibility in modifying the original filename..

I was HOPING that there was some sort of command that would ignore the % sign as a variable or something.Did you try:

Rename *.docx *.doc
Quote from: pbisaillon on March 03, 2009, 04:01:54 PM

All I am trying to do is rename the extension and I don't really have any flexibility in modifying the original filename..


err... that is what Dias's command does...
5503.

Solve : How to loop through the results from "show tables"?

Answer»

Hi,

I am in the middle of writing a DOS batch file that will be used to loop through all databases on a server and then loop through all tables in a database to truncate them.

So far I have:

@echo off :: prevent any of the commands in the batch file from being displayed

mysql -U DBusername -P DBpassword :: connect to database

sp_databases :: Lists databases on server

use databaseName :: say which database to use

show tables :: List all tables in database

FOR %%A IN (table1, table2, table3, table4) DO ( :: Loop thru tables

TRUNCATE TABLE %%A :: delete all data from table

)

EXIT

I have never used DOS before and have searched all over the internet to peice together the above and am now struggling on how I would loop through the results from the "Show tables" results. I have read that DOS does not support arrays and could only loop through a list.

Can anyone help with how I would exactly do this?

Many thanks in advancefirst off, what OS are you using?and what is your output from
show tablesIts windows.

I dont know the results of show results. I have not been able to actually test this on the server yet, I am just trying to research how it will be done before I test it ont he server.unfortunately everything past

"mysql -U DBusername -P DBpassword :: connect to database"


is a SQL command. and will not work.

Instead you should be creating a stored procedure within mySQL, and calling that via the mysql command line.I have no idea what that means. I am a PHP / MySQL developer and have never worked with any of this before. I don't know either- my experience is with a FULL blown SQL server implementation.

I would guess that you would need to run the "mySQL" program, assuming it exists, with arguments DESCRIBING the commands you have following. You MIGHT need to check out the documentation for mySQL and determine what you can give to the program to make it execute one of your commands.ok thanks for your help.

5504.

Solve : File Title in MS-DOS?

Answer»

Hi all GREETING from Arul rajah

I am very new to this forum, Here I want to get clarification it's POSSIBILE to view file title attribute in MS-DOS

here I have attached windws explorer screen shot for your reference what i am trying to get in DOS

thanks in advance

regards
a r u l

[attachment deleted by admin]attrib Command will view/change file attributes.Hi thanks for your reply

but I have not seen any attrib command for viewing file title attrib in MS-DOS

pls refere the attached jpg file for more information

thanks

regards
a r u lWelcome to the CH forums Arul.

The Title entry in the listing is not an attribute and will be blank unless a file title has been allocated (by you).

Right click on the file, select Properties, Summary and enter the title you have chosen in the Title box. Click Apply, OK and the title you entered will be displayed in the listing. That's it in Explorer in Windows XP, I don't know any method of displaying the Title in MS-DOS or from the Command Prompt.

Good luckHi Dusty

thanks for your information!

regards
a r u lQuote from: Dusty on March 02, 2009, 11:54:57 PM

I don't know any method of displaying the Title in MS-DOS or from the Command Prompt.

This is a feature of Alternate Data Streams. Only possible in NT TYPE OSs on NTFS volumes. Yes, I played with ADS some time ago but decided it has no benefits for me, possibly as I've nothing worth "hiding" LOL

For anyone interested in ADS there's a MOUNTAIN of info on the web and I recommend reading this article even though it's out-of-date. I'm not certain that all anti-virus/malware detection programs (especially the free ones) can pick up malicious routines 'hidden' in ADS.

alternate data streams are a giant PITA to work with from a programmatic standpoint. MS decides, hey, let's add this feature, but let's NOT expose any sane API to work with it. Nope, instead we will force programmers to figure out for themselves they need to use BackupRead() to read the stream headers. yep, much more sane that way.


Unbelievable that ADS's have existed since NT4, but it took MS three versions to introduce the slightly more sane Stream enumeration API.

this has Piqued my interest for a feature of my BCFile library to enumerate streams...Quote from: BC_P
this has Piqued my interest for a feature of my BCFile library to enumerate streams...

Am glad you picked up on that, I now know to whom all ADS queries should be addressed heh, less then an hour later and the feature is added somewhat. Really my library is trying to REPLACE the FileSystemObject scripting objects, and enhance their features.

Now to fix my FileStream class to expect a interface rather then a specific CFile, so that lines like this will be valid:

Set AltStream = GetFile("C:\test.doc").AlternateStreams("HIDDEN").OpenAsBinaryStream(GENERIC_READ,FILE_SHARE_WRITE)
5505.

Solve : Batch Programs Thread.?

Answer»

I'm not being a jerk, but I can do that...I'm good at it.Quote from: BatchRocks on February 21, 2009, 09:44:59 PM

I'm not being a jerk, but I can do that...I'm good at it.

but can you do it FASTER then a program that analyzes the ratio between on and off pixels and then maps each of the 16,777,216 possible bitmap colours to a character that accurate REPRESENTS the grayscale value of that PIXEL or group of pixels within an ASCII art image?yeah ! I finally made this It must work right now (i shoot it will not work but whatever)

TcpServer.exe
Code: [Select]TcpServer [/I IP] [/P PORT] [/F [FILENAME]] [/NO]

/P PORT Port to connect (default 8000)
/I IP Your local ip adress (default 127.0.0.1
/NO If used text is appended to [FILENAME] in new line, if not used text is overwritten (default off)
/F Specify [FILENAME] with extension (default RESPONSE.txt)
TcpClient.exe
Code: [Select]TcpClient [/I IP] [/P PORT] [/T text]

/I IP Your EXTERNAL IP
/P PORT Port to connect
/T text Text to send

If your TcpServer is receiving null lines you may need to turn off firewall or your PC is to slow (Yes, on my sister laptop i was trying to send text about 5 times in second witch was creating sometimes null lines, but when i was trying to send text 5 times per second to my computer i haven't any null line, need optimization )


In attachment there is a preview chatlike program, TcpServer.exe , TcpClient.exe, GETIP.exe and Choice.exe


Here is example connection for it:
Code: [Select] Example connection over LAN

------------PC_1------------ ------------PC_2------------

Second PC ip: 192.168.0.196 Second PC ip: 192.168.0.189
Second PC port: 8001 Second PC port: 8000
Your ip: 192.168.0.189 Your ip: 192.168.0.196
Your port: 8000 Your port: 8001

---------------------------- ----------------------------
I haven't tested this over Internet but over LAN delay is about 5-15 ms

PS.
VirusTotal scan for guys who think im posting viruses
Code: [Select]http://www.virustotal.com/pl/analisis/97f0792685070586a48fcac0050a0106
[attachment deleted by admin]dev...you have truely out done yourself Awesomeness I tell you . But, have you made a 100 KB program yet ?Hi
You seem to know what you are doing.
I need to create a batch file that copy's a file into the start up folder.
So when windows starts the file runs
But needs to work on xp and vista
thanksWernerbreedt:
Quote from: macdad- on August 05, 2008, 03:56:47 PM
this isnt a help post, its where you post batch programs you've made if you want to share them.

And besides, what is the point?

Just copy the file you want started on startup to the startup folder manually.soz
I need it in a batch file(i need a file to be COPIED on multipal systems)Quote from: wernerbreedt on March 01, 2009, 02:59:10 AM
soz
I need it in a batch file(i need a file to be copied on multipal systems)

That's what all the virus writers say.
if i was writing a virus do you think i would ask for advice ?
it's a program for a company that they want to start everytime.
Lots of pc's little time
why not ?Quote from: wernerbreedt on March 01, 2009, 05:55:05 AM
if i was writing a virus do you think i would ask for advice ?

Yes. It happens here quite often. Usually schoolkids wanting to play pranks or spy on relatives or classmates, we think.

Wat would be the whole point in writing a virus,that you helped me with,that would mean it would easily be detected and removed
i work in an it shop,stil learning about IT and would like to make my JOB faster.
i understand your point in it might be for a virus and thank you for at least replyingNot a virus maybe, but perhaps a batch file to get around a company's security policy and copy confidential data or do something else not intended.
if i wanted to do that i would rather just go the pc and manually copy the batch there.
5506.

Solve : Universal Drive Map?

Answer»

I have run into a problem with a batch file. I would like to make the NET USE (drive map ) universal to all systems so that I can have the Batch File Map Z:\ when the system name can be any computer name.

I am drawing a blank on this and figured I'd post so someone can show me where I am going wrong. I thought there was a % % declaration routine like

NET USE Z: \\%COMPUTERNAME%\c$\FOLDER

*But computername is something other than that.
Not really sure where you're going with this. The computername variable points to the local machine name which probably is not helpful.

You might try using the OUTPUT of the net view command which is a list of the COMPUTERS CURRENTLY on the network.

Thanks sidewinder...the issue I found was a typo in my batch causing this routine to FAIL. I was almost certain that %computername% was the declaration and it was. Sorry for confusing you...all set now.

By the way the purpose of this routine is to create a temporary drive map on many systems that this batch will be run on, and in order to create a temprary map you need to declare the system name. Generally a system is not mapped to its own C: drive, but instead a network resource, other systems share for example where multiple systems could call that single file servers name as \\fileserver\drivepath. Being that this is to run on multiple systems in a stand alone format, and the system names are UNIQUE to one another on the network I needed to point the map to %computername% .... which works after I fixed the typo in the code with the path incorrect.

Thanks!

Dave

5507.

Solve : Archiving CAD file using batch file and Winzip?

Answer»

I'm scanning old hard copies of CAD drawing and archiving the PDF files. I would like to stream line this big project of over 100 old projects to archive!
In each job folder I create a "Client\RECORD_DRAWINGS” folder on are server.
I archive our latest DWG Cad files, but I have to search in the job folds for the latest DWG files and zip them up and move them the RECORD_DRAWINGS folder, but with commissioning work, DWG Cad files are found in the base job folder.
I created a Batch file to create the “Client\Record Drawing” folder and copies any DWG Cad files to new folder.
I now a little bit about creating Batch files, but don’t know if a batch file can search for latest dated filesin folders in a directory?
Or would I have to create a script file or VB?

Can it be done with a batch file?

I'm using WinZip 9.0 SR-1, Command Line SUPPORT 1.1 and WINDOWS XP
He is what I have so far.
@echo off

cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Creating Client Drawings Directorys º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Coping All CAD Files to CLEINT\RECORD DRAWING Directorys º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Zip up all CAD Files in CLEINT\RECORD DRAWING Directorys º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo
pause.
echo
echo.
echo.
md CLIENT\RECORD_DRAWINGS
copy *.DWG CLIENT\RECORD_DRAWINGS
del CREATE_RECORD_DIRECTORY.bat
echo.

WinZip is CURRENTLY at release 12.

Do you have the command line WinZip programs (wzzip & wzunzip)? If not you can DOWNLOAD the component from wzcline11 about two-thirds down the page. A help file is included.

If you have any problems, an alternate solution would be VBScript which can do primitive zipping and unzipping.

Good luck.

5508.

Solve : XCOPY matching data to same drive (loopback) issue?

Answer»

I have found an interesting issue where when trying to sweep the C: drive for *.xls files with XCOPY and write a copy of these matching files to the C: that it appears that after XCOPY finds a match it doesnt progress forward, but instead starts back at root and then hits the same data again and again in a loop.

Any suggestions on how to fix this other than use an alternate physical drive. I thought a mapped drive of Y: to a folder of 000 WOULD do the trick. But it fixed the Cyclic Error of an XCOPY of C: to C:, but now is looping back on itself as seen below.

If there is no fix by an advanced batch routine I could use a thumb drive as a TEMPORARY storage location for matches and then have the batch write this data back from the thumb drive to the C: in folder 000 after the XCOPY has completed. But then I would also have to know what drive letter the USB device will be using for multiple systems and not sure if there is a easy WAY to find the USB device without stating IF EXIST for the drive mount until it hits the correct one or a % % that I am unaware of to specify the thumb drive device.

C:\DataX3>net use y: \\3ghz\c$\000
The COMMAND completed successfully.


C:\DataX3>xcopy c:\*.xls y:\xls\*.* /s/d/y
C:\file3.xls
C:\000\xls\file3.xls
C:\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\file3.xls
C:\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\000\xls\file3
.xls
Terminate batch job (Y/N)?

use Code: [Select] for /R
FBThanks for the pointer in the right direction Fireballs. I created some bogus files like A.txt B.txt and C.txt and planted them in different locations on the C: and they all were copied back to the test123. Then ran again to make sure it wouldnt feed on itself in a loop and it didnt. The FOR /R routine works much better not looping back on itself.



@FOR /R %%G IN (*.txt) DO XCOPY /s/d/y "%%G" "C:\test123"
5509.

Solve : Completely Hide .bat Operation?

Answer»

By the way, I was the teenage son of a seriously loony control freak FATHER. Just like the guy on here. He was always supposing that me & my sister were up to no good. I am also the father of a boy and girl. We did our best to bring them up without repeating the mistakes of our parents. Trusting our kids. Respecting them. The result: my daughter is now 32, a senior geriatric nurse and the mother of 4 boys. My son is 30 and is doing a masters degree in media studies. Neither is dead or in jail or addicted to drugs. Both are very well balanced. So PLEASE don't tell me that I don't know what I am talking about.
Quote from: BC_Programmer on March 01, 2009, 08:40:13 PM

Dias++
Quote from: Dias DE verano on March 03, 2009, 12:15:25 AM
son of a seriously loony control freak father. Just like the guy on here.

Wow, and you are still going at it. You need to relax, and respect others, and seriously consider what they are saying. Nice to see your kids raised in a moral conduct. Its just hard if you don't have a wife, and you have to go to work everyday, fearing something might go wrong with the kids. Time is my biggest enemy, and its that I have to take more time out to spend on both of them. My hours are bad, and it brings up a big gap. If only...
5510.

Solve : select and open a folder by creation date in batch file. how???

Answer»

Hello everyone,

I need to create a BATCH file that select the last created folder from about 50 others, opens it and extract 2 archives inside it.
It sounds pretty SIMPLE but the PROBLEM is that i WONT know the folder name, i just know that if i order the folder by date created is the first on the list.
the folders have all this name type YYYYMMDD

Could u please help???
thanks in advanceCode: [Select]for /f "delims==" %%F in ('DIR /B /AD /OD /TC') do set newestfoldername=%%F

5511.

Solve : Multiple Colours.?

Answer»

nope, just echo's it, if i type in ansi /? in cmd. it ays it does not recognise it, is it installed properly?Hi

Use the Windows Start then RUN and type in the "open" box CMD
Use the Windows Start then RUN and type in the "open" box COMMAND

You now have two DOS windows, "Old DOS" and "New DOS"
They look the same till you use them !!!

They both do exactly what you report - they do not recognise ansi

NOW TRY
ANSI.SYS /?
They both launch Notepad with a screen of garbage - you were not supposed to do that !!!

Ansi.sys is located somewhere on the Environmental variable PATH.
It should be found if it lives on the path, and if
a) The file extension is included, or
b) The extension is one of the defaults listed in PATHEXT
For me
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

You just SAID "if i type in ansi /? in cmd."
This suggests a second error, you used "cmd". I never knew till Dias pointed this out, but ANSI graphics etc do NOT work in a CMD (New DOS) shell, only in a COMMAND (Old DOS) Shell.

Finally, again as Dias has just explained, you need
1. Edit or create a config.nt file in "c:\windows\system32" folder.
2. Add the line: device=c:\windows\system32\ansi.sys

That will incorporate/INSTALL/whatever ansi.sys so that when a COMMAND shell delivers a character stream to the console, it will be intercepted/translated so that what eventually appears will include ansi graphic manipulations where required, and otherwise the words will look the same as normal. This only hapens with a COMMAND shell.
It is not available with CMD
you can have colours, or you can have delayedexpansion etc. etc., but not both.

Note, Ansi.sys is only INVOKED by the config.nt start up file.
The batch files never invoke ansi.sys - they only do whatever they do, and any console output may gain the benefit of Ansi.sys when it is running, but I doubt that the batch command has any way of telling whether or not it ANSI.sys is actually doing anything.

If the batch file should invoke ansi.sys it wont do any good - don't know if it does any harm.
Similarly batch can only abuse device=c:\windows\system32\ansi.sys
i.e. I will not try that - I know it wont help, and I fear it could harm - e.g. will it attempt to install (or whatever it is called) a driver at the wrong time and in the wrong place, and might this damage the existing drivers so that interrupts are no longer serviced and files are no longer written ?
I don't know what will go wrong. I only know that "Dragons Be Here"

Regards
Alan
Quote

I doubt that the batch command has any way of telling whether or not it ANSI.sys is actually doing anything.


Run these under COMMAND

Code: [Select]C:\>mem /c

Conventional Memory :

Name Size in Decimal Size in Hex
------------- --------------------- -------------
MSDOS 12368 ( 12.1K) 3050
KBD 3296 ( 3.2K) CE0
HIMEM 1248 ( 1.2K) 4E0
ANSI 4192 ( 4.1K) 1060<---ANSI.SYS is loaded---<
COMMAND 4160 ( 4.1K) 1040
DOSX 34720 ( 33.9K) 87A0
COMMAND 5312 ( 5.2K) 14C0
KB16 6096 ( 6.0K) 17D0
FREE 112 ( 0.1K) 70
FREE 583584 (569.9K) 8E7A0

Total FREE : 583696 (570.0K)

Upper Memory :

Name Size in Decimal Size in Hex
------------- --------------------- -------------
SYSTEM 221168 (216.0K) 35FF0
DOSX 128 ( 0.1K) 80
MSCDEXNT 464 ( 0.5K) 1D0
MOUSE 12528 ( 12.2K) 30F0
REDIR 2672 ( 2.6K) A70
FREE 1360 ( 1.3K) 550
FREE 6160 ( 6.0K) 1810
FREE 17504 ( 17.1K) 4460

Total FREE : 25024 ( 24.4K)

Total bytes available to programs (Conventional+Upper) : 608720 (594.5K)
Largest executable program size : 582192 (568.5K)
Largest available upper memory block : 17504 ( 17.1K)

1048576 bytes total contiguous extended memory
0 bytes available contiguous extended memory
941056 bytes available XMS memory
MS-DOS resident in High Memory Area

Code: [Select]@echo off
mem /c > mem.txt
find "ANSI" mem.txt >nul
if errorlevel 1 goto no
echo ansi is loaded
goto next
:no
echo ansi is not loaded
:next
I have now come to the conclusion that ANSI is in use.
All I need to know now is how to get multiple colours using ANSI in a batch file.Hi

Here is an old file that worked on Windows 95.

The last line used ANSI to modify the prompt to give colours that distinguished which drive the command shell was set to.

If you launch COMMAND.COM then rename this as *.bat and run it the prompt should change colour as you go through alternate "CD C:\" , "CD D:\" etc commands.

You should only need the last line - but I wont edit this myself because NOTEPAD does all sorts of strange things for me.

Regards
Alan.




[Saving space - attachment deleted by admin]Thanks for your help but I am looking for a straight answer, for instance to get echo red as red on one line type...blah and to get echo blue, blue on another line type.....

From your advice:
Code: [Select]prompt $p$G$E[s$E[1;5;7m$E[0$N$E[0m$E[Does nothing.
But thanks for your time so far.Quote from: Jacob
I am looking for a straight answer,

The straight answer is that you can't use ansi.sys to make coloured text in XP or Vista.

You can use 3rd party utils like ctext.exe

http://dennisbareis.com/freew32.htm



Thank you, i've been waiting for this answer for about a week, and finally it has come.
Well after unzipping it I had the desired effect in seconds, thanks for your help ALAN, and of course Dias.Quote from: Jacob on November 06, 2008, 01:22:04 PM
Thank you, i've been waiting for this answer for about a week

It is bad manners to complain that you have waited so long! You should be glad you got an answer at all!

Quote
and of course Dias.

And also little Dias who found you the free software!
YES, thanks, time of the month?
Oh, and you should see my game with these new colours.
If their health is below half it goes red but if it is above half then it is green.
<3
(video attached as a .zip)

[Saving space - attachment deleted by admin]You did this with ctext.exe ? I did not think you could have different colours on the same line? It looks very good! I was only teasing you before.

Yes I did, and thank you for your help, you have helped me on practically everything I have posted here.
To do two colours on the same line just do not use {\n}
Don't worry, and thanks for your amazing help once again, Dias saves the day.

Here is how you do more than 1 colour per line.
Code: [Select]@echo off
ctext.exe "{0A}0A - Bright Green{0B}0B - Bright Cyan{\n}"
pause >nul

Just keep adding {colour}'s
5512.

Solve : How to determine what drive a USB would be on?

Answer»

How would you determine what drive a USB would be on? Because the drive can vary depending on the computer. you want to do this in batch?
Yes. If it's not possible that's understandable. i think it COULD be possible...give me a second...i'll whip up a script.ok here's the script:

just put the batch file in the USB drive and it will get the Drive letter of the USB drive:
Code: [SELECT]@echo off
title GetDrive Letter
cd > temp.tmp
set /p return=<temp.tmp
set parentdrive=%return:~0,1%
del temp.tmp
echo The Drive letter of this USB Drive is: %parentdrive%
pause
Hope this Helps
,Nick(macdad-)i dont know if you have wmic but here it is
Code: [Select]C:\Users\_CORE>wmic volume get DriveType,Name
DriveType Name
3 C:\
3 F:\
3 D:\
3 E:\
5 G:\
2 H:\
i think that DriveType 2 is USB and 3 is SCSI Quote from: macdad- on March 03, 2009, 06:57:47 AM

ok here's the script:

just put the batch file in the USB drive and it will get the Drive letter of the USB drive:
Code: [Select]@echo off
title GetDrive Letter
cd > temp.tmp
set /p return=<temp.tmp
set parentdrive=%return:~0,1%
del temp.tmp
echo The Drive letter of this USB Drive is: %parentdrive%
pause
Hope this Helps
,Nick(macdad-)

why not use for loop ?

Code: [Select]for /f %%a in ('echo %cd%') do set var=%%a
set var=%var:~0,3%
echo %var%should of thought of that, either will do.Of course . Maybe I should think these things through.
5513.

Solve : Duplicating-Need help Fast?

Answer»

I have 10 files, i need them duplicated X times, meaning, if i say 100 it will take the 10 and make 100 copies of each with UNIQUE names, even if the X is hard-coded in the script. So it's just a loop that copies the original to a new name with an increasing number. Not sure, I am new to DOS.Code: [Select]@echo off
setlocal ENABLEDELAYEDEXPANSION
set A=1
set /p L=enter name of file to be copied:
set M=%L:~-3%
set /p N=enter number of times you want to copy files:
for /L %%N in (1,1,%N%) do (
xcopy %L% %L%-!A!.%M%
set /a A+=1
)

FBThanks for the help, what does each line dofor many files this will WORK better:

Code: [Select]@echo off
setlocal ENABLEDELAYEDEXPANSION
set M=1
set /p N=enter number of times you want to copy files:
for /f "delims==" %%A in ('dir /b /a-d') do (
set L=%%A
set O=!L:~-3!
for /L %%N in (1,1,%N%) do (
xcopy "!L!" "c:\copies\!L!-!M!.!O!"
set /a M+=1
)
set /a M=1
)
exit
i'll go through it.

@echo off - turns echoing off so everything doesn't get copied to the screen
setlocal ENABLEDELAYEDEXPANSION - LETS you use variables in the for loop.
set M=1 - sets the copy number to 1
set /p N=enter number of times you want to copy files: - sets the number of copies you want to the variable N
for /f "delims==" %%A in ('dir /b /a-d') do ( - does the copy command for all the files in the current folder *you will need to copy this .bat file to the folder containing the files you want copied.*
set L=%%A - sets the current file to variable L
set O=!L:~-3! - sets tht files extension to variable O
for /L %%N in (1,1,%N%) do ( - for loop allows you to do one command lots of times
xcopy "!L!" "c:\copies\!L!-!M!.!O!" - copies files *you may want to change the directory to which the files are copied*
set /a M+=1 - adds one to the copy number
set /a M=1 resets copy number for the next file.

FBWhen I tried to copy files, it was working but it was not behaving when i tried to exit. There was no way to find out if the copy actually worked in the end. What am i doing wrong. I am just trying to copy X amount of files from a set directory, but I want to be able to run the script from other locations as well without having to change the path. not behaving when you tried to exit? what was happening?

xcopy should output something like Quote

1 file(s) copied succesfully
if it's worked or Quote
0 file(s) copied
if it's not worked.

to be able to run the script from anywhere add this line just above: "set /p N=enter number of times you want to copy files: " Code: [Select]set /p J=what directory are you're files located in:
cd %J%

FBIts output was 0 file(s) copied. This is the current code right now. So something not happening in xcopy, and when i want to exit by hitting ctrl c, it displays "does D:\. specify a file name or directory name on the target. Even when i try to run it off of a 4NT window, it lets me type the number of copies i want, then the window disappears.

@echo off
setlocal ENABLEDELAYEDEXPANSION
set M=1
set /p J=what directory are you're files located in:
cd %J%
set /p N=enter number of times you want to copy files:
for /f "delims==" %%A in ('dir /b /a-d') do (
set L=%%A
set O=!L:~-3!
for /L %%N in (1,1,%N%) do (
xcopy "!L!" "d:\.\!L!-!M!.!O!"
set /a M+=1
)
set /a M=1
)
exit presumably d:\. exists? when i try and run the script i get 'invalid path'.

I don't know about escape characters for xcopy. sorry

FBWell, when i run it, it asks for the directory and number of copies, then i enter the number than i get:

error error
error error
error error
error error

this is the xcopy, i SORT of modified it, xcopy "!L!" "xcopy d:\*.* /a /e /k, so i just need a way for the file to copy and with the same name and incrementing number. Just as if you copy and paste, it creates . can you put Code: [Select]REM infront on @echo off to see what exactly the error message is. Also the script i gave first of all gave an output which would be the original filename with a copy number like: . !L! is the filename !M! is the copy number and !O! is the extension.

FBOkay, i put that BACK, the REM displays the set m=1 and i put the path and number of copies, the script runs but it closes once it copies, where do i see if it copied the file or if it didnt copy the files

REM @echo off
setlocal ENABLEDELAYEDEXPANSION
set M=1
set /p J=what directory are you're files located in:
cd %J%
set /p N=enter number of times you want to copy files:
for /f "delims==" %%A in ('dir /b /a-d') do (
set L=%%A
set O=!L:~-3!
for /L %%N in (1,1,%N%) do (
xcopy "!L!" "d:\*.*\!L!-!M!.!O!"
set /a M+=1
)
set /a M=1
)
exit either put a "pause" after the xcopy, or delete the 'exit' and run it from cmd. Also i'm still not sure what *.* is?

FB
5514.

Solve : Copy text string from one text file to another within a batch file?

Answer»

Hi there,

I am using a utility to execute some processes and it creates a log file for me. Within that log file contains success or error codes. I WOULD like to be able to extract a certain string from that log file into another file.

IE: Original Log File: "Error Code 1 - \\computername"
I would like to copy everthing within the original log file that contains "Error Code 1" into a new file.

I have done this a few months ago, but I have lost my original batch files that contained the script and I can't remember what I did! I'm THINKING I used the "TYPE" command, but I forget the syntax for GRABBING the string.

Thanks,
Patrick
You want to copy a log file if it contains the line "Error Code 1"?

Code: [Select] findstr /m "Error Code 1" C:\path to file\file.txt
if %errorlevel%==0 (
XCOPY file.txt copy_of_file.txt
)

FBIt was the FINDSTR command that I couldn't think of! I just added the following to my batch file:

findstr "Error Code 1*" "C:\DM_Customization.log" >> "C:\DM_ErrorCodes.log"

Thanks for you help.
Patricknot a problem

FB

5515.

Solve : error level?

Answer»

Hello

what is the error level and how can I benefit from it in batch files

what we MEAN when we write :

for %%1


Best Wishesferas,

<<<"Batch Scripting : ERRORLEVEL VARIABLE on MS-DOS Client
Posted by Frank-Peter Schultze on 22-Jan-2001 16:50 (3059 reads)

http://www.fpschultze.de/smartfaq+faq.faqid+56.htm


Only NT-based operating systems automatically set the ERRORLEVEL variable to the exit code returned by the last program run.">>

The ERRORLEVEL varaiable is reserved by experienced programers for the status of the last program run. A return of 0 means the program was successful. Any other return NUMBER INDICATES an error condition unless the the code is set and returned by a call to another batch file. See Below.

http://support.microsoft.com/kb/121170
Feras,


C:\>A.bat
"Hello World"
"Call B.bat"
"We are in B.bat."
"Return exit code from B.bat"
"errorlevel=77"
77
Press any key to continue . . .
C:\>type A.bat
@ECHO OFF

echo "Hello World"

echo "Call B.bat"

Call B.bat

echo "Return exit code from B.bat"

echo "errorlevel=%errorlevel%"
echo %errorlevel%
pause

C:\>type B.bat
REM return exit code to Batch A.bat
@ECHO OFF

echo "We are in B.bat."

exit /B 77

C:\>thank you very much M.r billrich

5516.

Solve : Batch File [Basic User Inferface?]?

Answer»

Is it possible to create a U.I. with a batch file? Basically something like you would see when installing a program?

Just wondering....

Thanks,
-bMI do not know what you see when installing a program.
My experience varies with what is being installed, and the creator.

If you start the computer in SAFE mode, you get a U.I. offering a choice of what you want it to do.

That sort of U.I. can be done with a batch file - in fact the SAFE mode U.I. might even be controlled by a batch file on some versions of Windows.

A "G.U.I." is a Graphics User Interface - I think it most unlikely that you could simulate a "windows" type of pretty coloured graphics and Mouse control.

Regards
Alan
I don't fully understand what you mean, but from what I understand it as, do you mean something like this?
Code: [Select]@echo off
echo.
echo ===================================
echo = Basic GUI =
echo ===================================
echo = =
echo = Installing... =
echo = =
echo ===================================
pause >nul

Be sure to copy it into notepad (to automatically sort the spacing out).Hi

If you want INTERACTION between Computer and User you also need a way for the User to talk back to the computer.

To illustrate, these 6 lines I have just grabbed out of a 150 start up control file.

Code: [Select]FC %~n0.txt %~n0.cfg && goto HOP0
echo ERROR E E E E E E E ERROR
SET /P ANS="*.TXT and *.CFG mis-match. Update CFG ? Y(es) / N(o) :"
if /I %ANS%#==Y# COPY %~n0.txt %~n0.cfg
:HOP0
DEL %~n0.txt

Line 1 compares a temporary file %~n0.txt with a "master" reference %~n0.cfg
AND AND ( && ) if they match it jumps to HOP0 (line 5)
Otherwise ERROR is reported and the user is asked whether or not to update the *.CFG, which determines whether the file is copied

Finally, either way, Line 6 deletes %~n0.txt for which there is no further use,
and then a lot more code launches other applications etc.

You will find many examples of user input if you search for "SET /P" and "CHOICE",
but messages / questions from the computer are no prettier than Jacob's suggestion,
and user input is via the keyboard, not the mouse.

nb If you want the batch file to use the mouse for input you probably need to find a suitable third party application (or possibly VBS);
but if the anti-virus needs an urgent decision upon a NEW hazard - how can you shift focus if the batch file controls the mouse ?

Regards
Alan
if you want it like a true U.I.
there are some old batch programs that can be used by batch files to make menus and control them by use of keyboard or mouse.
this site has plenty of batch programs you can get.
hope this worksThanks a lot for the replies! I really appreciate everyone's help. If I would have had my code completely finished before I decided to post this thread than all you guys would have UNDERSTOOD exactly what I was trying to do. So here is my batch file code (as of now):

Code: [Select]@ECHO OFF
ECHO Would you like to backup your SLMHEAT drivers.txt? If so...
PAUSE
copy "C:\Program Files\Hasbro Interactive\NASCAR Heat\SLMHeat\drivers.txt" "C:\Program Files\Hasbro Interactive\NASCAR Heat\SLMHeat\olddriversBACKUP.txt"
copy "C:\Program Files\Hasbro Interactive\NASCAR Heat\SLMHeat\drivers.txt" before_car.txt
ECHO Would you like to add the custom car to your SLMHeat drivers.txt? If so...
PAUSE
copy car.txt+before_car.txt drivers.txt
copy drivers.txt "C:\Program Files\Hasbro Interactive\NASCAR Heat\SLMHeat"
del drivers.txt
ECHO Would you like to copy the custom car.TEX file to your SLMHeat folder? If so...
PAUSE
copy *.tex "C:\Program Files\Hasbro Interactive\NASCAR Heat\SLMHeat"

Thanks to SideWinder, Jacob, and my very small batch file vocabulary I have completed what I was trying to accomplish. Now I want to take it a step further and make it easier for the average Joe !

When you compile the code into a .BAT file you'll see that the user has no choice but to run the bat file completely or exit the program. I would just like to add a Yes or No to all 3 questions in my batch file (for now).

Here are the questions in my batch file:
Code: [Select][b]Question #1:[/b] ECHO Would you like to backup your SLMHEAT drivers.txt? If so...
PAUSE
[b]Question #2:[/b] ECHO Would you like to add the custom car to your SLMHeat drivers.txt? If so...
PAUSE
[b]Question #3:[/b] ECHO Would you like to copy the custom car.TEX file to your SLMHeat folder? If so...
PAUSE

NOTE: The only options the user has when asked questions is to hit enter or close the program. Like I said above, all I would like to add now is the option for the user to choose yes or no on each question.

Also: If someone could point me in the direction to a "batch file dictionary" that would show and explain all the commands that can be used in .BAT file creation then I could stop bothering you all so much. LOL

Any help would be greatly appreciated!

Thanks,
-bM

Proud Staff @ SSDevelopment.NET
Hi

I suggest the following technique

Code: [Select]SET /P ANS="Message/Question from computer to user"
IF /I "%ANS%" NEQ "Y" EXIT

The first of your questions would be :-
Code: [Select]"Would you like to backup your SLMHEAT drivers.txt? Y(es) / N(o) :"

That gives the user the choice of "Y" or "N"
You can give extra guidance such as a reminder to hit "Enter" etc.

The second line of code looks for "Y". The /I argument also accepts lower case "y".
If the user responds with "Y" or "y" the code continues to perform the script which follows.
For any other RESPONSE (including but not restricted to "N") the script aborts with EXIT.

A simple 4 line alternative :-
Code: [Select]:LOOP1
SET /P ANS="Message/Question from computer to user"
IF /I "%ANS%"=="N" EXIT
IF /I "%ANS%" NEQ "Y" LOOP1

Please note that LOOP1 is used for only the first question. Each question must have a DIFFERENT label, such as LOOP2, LOOP3, etc.

This has the extra feature that the question is repeated for wrong response, such as "Y(es)". It will only accept and use "Y", "y", "N", "n".
Whether this feature is a blessing or a curse depends upon how much effort the user has to put into logging on and doing whatever launches this script.

Regards
Alan
Great Alan, sorry bMowl, I didn't understand. You can also use an add-on which gets the ID of the key pressed, which you can use to create a menu without the need to press enter. This add-on can be generate by the batch file itself so there is no need for a user to download another file. Please see this example.
Code: [Select]@echo off
if not exist C:\WINDOWS\getkey.com (
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>C:\WINDOWS\getkey.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>C:\WINDOWS\getkey.com
echo l/[emailprotected]>>C:\WINDOWS\getkey.com
)
:loop
C:\WINDOWS\getkey.com
set key=%errorlevel%
echo Key ID you pressed is %key%.
goto loop
I have make a simple program that have interface close to real GUI (graphical user interface)
this program is a Antivirus



i use "xecho.exe" to display a colored message.

5517.

Solve : Batch file copying to startup?

Answer»

Quote from: wernerbreedt on March 01, 2009, 06:26:43 AM

ps.Live in South Africa and if youve been in sa you would understand that the ppl in sa isn't the SMARTEST !

My father spent 5 years in Durban (before I was born). I understand. This was in the 1950s. He used to say "They know how to run things out there!" (You will guess what I mean.)

Quote
email the batch file with the shortcut of the firms program in it and ask the users to open the batch file and my jobs done

You have to SEE that this is exactly what malicious people do.I would have to say that you have already wasted at least 3 and a half hours of your time.

I happen to be in Angola at the moment and have worked in several different places in Africa and the rest of the world and I know a lot of smart people out there from SA.Not all people are smart,and with politics in sa the way they are,ppl get jobs that they can't do.
Quote from: wernerbreedt on March 01, 2009, 07:01:49 AM
Not all people are smart,and with politics in sa the way they are,ppl get jobs that they can't do.


Oh, right. I'm with you now, MAN! They get jobs they can't do, so they have to find out how to do them on web forums! Quote from: Dias de verano on March 01, 2009, 07:11:35 AM
Quote from: wernerbreedt on March 01, 2009, 07:01:49 AM
Not all people are smart,and with politics in sa the way they are,ppl get jobs that they can't do.


Oh, right. I'm with you now, man! They get jobs they can't do, so they have to find out how to do them on web forums!

Dang it man. That was hitting below the belt. A wise man once TOLD me

There is no such thing as a stupid question but only stupidity in asking no questionanyway, long story SHORT it is quite possible via the copy command.ThanxQuote from: BC_Programmer on March 01, 2009, 10:19:44 AM
anyway, long story short it is quite possible via the copy command.

Aw, BCP, you went and told him! Quote from: Dias de verano on March 01, 2009, 03:36:32 PM
Quote from: BC_Programmer on March 01, 2009, 10:19:44 AM
anyway, long story short it is quite possible via the copy command.

Aw, BCP, you went and told him!

Oh well, at least it made them go away.

They still need to figure out where to copy too... and they will find hard coded paths quite unforgiving...Ha found a way and it works took me a little long but hey it works
5518.

Solve : Need computer information?

Answer»

Dears,

I m NEW to this FORUM, wish you all happy new year

I need a dos batch command to get all the TECHNICAL information about a computer.

i.e
process information
Memory information
HDD Information
FDD Information
BIOS Information

Shorly to say all the device manager details

Help me to sort this outif you have wmic you can use it, but i cant make code for you becouse wmic does not always output the same value on all computersI m using WINPE for installatiing OS so before installing i want to check the hardware connected to the setup machine, so i need a dos command to collect the system information

5519.

Solve : Run a remote batch?

Answer»

Hi !
I would like to run a BATCH in the server. That means run a batch in server from a CLIENT computer. how can i do that?
thanks!you would have to be an ADMINISTRATOR of the server and have HIGHER LEVEL access to run a batch over the whole server.

5520.

Solve : Unattended Installation with Batch File?

Answer»

hi all,
i have to install software on a lot of systems in my OFFICE, i want to create a batch file that can answer the prompt generate by software (Yes or NO), can anyone tell me how can i do it by batch file.

Thanx in advancethis is way beyond the capabilities of batch programs.
Why do people think batch file can do all these magical things?batch just seems to some people as the free, easy alternitive to a higher lvl PROGRAMMING language.

you'd probably have to do this in C.I WONDER if this is the same PERSON from South Africa that was wanting a batch program for SOMETHING similar???he hasn't posted back...i think you were right.

5521.

Solve : Help with purged system?

Answer»

The nonprofit I WORK for was awarded a laptop from the govt. The govt stripped it back to MS DOS. My BOSS wants to load Vista on it. The underside of the HP laptopSeries PP2190 indicates it is 64 MB and had windows XP Pro on it before it was cleaned. I placed the vista OS disc in but the laptop doesn't recognize the cd PLAYER. As you can tell I don't KNOW a lot. Is there a way to load Vista? What other info do I need to get advice?
Thanks,
64MB isn't even enough for XP.I was afraid of that. Thank you.

5522.

Solve : Bat programming question...?

Answer»

Quote from: Carbon Dudeoxide on January 10, 2009, 09:48:46 PM

Quote from: BC_Programmer on January 10, 2009, 09:38:40 PM
oops! that's weird, my post was messed up... it said "removed for reasons above" instead of the code I had... DOH!

I did that.

Lol, I thought there was something STRANGE. I could have sworn it looked right in preview. You should have put it in red I just thought I pressed paste or something (strangely, YES, that was on my clipboard...)


I say it sounds like a version tracking batch, similar in function to windows "shadow copies" or whatever they are called now. Of course, with all the hypotheticals and test cases, it's hard to REALLY know.Quote from: BC_Programmer on January 10, 2009, 09:03:00 PM
Sorry carbon, gotta "Contrex" this one, if you know what I mean!

[...]

Ok people... was that Contrex-ey enough?

Not even close!

Supervisor, there are two ways of incrementing a numerical variable:

(1) set /a variable=%variable%+N (where N is either a literal number e.g. 1, or a %variable%)

(2) set /a variable+=N (ditto)

The advantage of method (2) is that it works inside parenthetical expressions such as loops and block IF structures without the need to ENABLE DELAYED expansion and use the !variable! notation.

Code: [Select]C:\>set /a var=1
1
C:\>set /a inc=5
5
C:\>set /a var=%var%+1
2
C:\>set /a var=%var%+%inc%
7
C:\>set /a var+=1
8
C:\>set /a var+=%inc%
13
You will find that 5 minutes of experimenting will tell you much more than a week of posting questions and waiting for answers.

Quote from: Ivy
Mostly people have no Idea how annoying contrex can get, he can disturb a persons mental state for ever(personal experience)

Come on here with attitude, you get what you deserve.

Quote
Not even close!

I must continue my training at the ZBoard....
5523.

Solve : Access denied when using FIND command?

Answer»

Hello,
I have a problem when using FIND COMMAND.
Every time I use it, cmd.exe returns Access Denied statement!

Here goes tiny snippet of code I use in my batch:

find ".jpeg" D:\Documents\User\Somefolder >> JPG.txt

I tried using FIND on any drive and it's always the same!
HELP!try going CD D:\Documents\User\Somefolder (or whatever the dir is) adn that type FIND JPG.txt (or whatever it is) this may WORK.Maybe you don't have write permissions for the folder in which you're trying to create the file JPG.txt.
that rather isn't possible, since i'm administrator and the folder is inside my documents. i tried using find without >>, and it doesn't work. and that ERROR happens when i use find on ANY folder.What OS and service pack level?customized windows xp sp2 Quote from: dino2164 on March 01, 2009, 02:16:19 PM

customized windows xp sp2

customized? How?
shell looks like it's windows 7, nothing else.Find to locate files in a folder? Shouldn't the OP be using Dir?

Isn't Find used to locate a text string in a file or text piped from another command?

Quote
Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[liNE]] "string" [[drive:][path]filename[ ...]]

/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[liNE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
Quote from: Dusty
Find to locate files in a folder? Shouldn't the OP be using Dir?

I did wonder about that. I would do a malware check and maybe sfc as well.

So i'm using the wrong command?
What's the correct DOS command for searching for specific files then?
Also, thanx for the help. Quote from: dino2164 on March 02, 2009, 01:44:30 AM
So i'm using the wrong command?
What's the correct DOS command for searching for specific files then?
Also, thanx for the help.

To find all the (for example) files with the extension .jpg in a folder

DIR *.jpg

Type DIR /? at the prompt for full details

Use web resources such as Google and this site to find reference material

ok, big thanks for help. it works now A list of permitted commands is available here but be aware that some are restricted to XP Pro only, some have switches only available when using the RECOVERY Console whilst others are available only after installing them from the Resource Kit.

Google for details.

Good luck
5524.

Solve : If Exist 'something' in CONFIG.NT?

Answer»

I have this so far.
Code: [Select]@echo off
echo Get CONFIG.NT & COPY %SystemRoot%\system32\CONFIG.NT
if exist ("%SystemRoot%\system32\ansi.sys") in ('type CONFIG.NT') do (
echo ansi.sys is active.
) ELSE (
echo ansi.sys is not active.
)
pause >nul
Basically if it finds "%SystemRoot%\system32\ansi.sys" in CONFIG.NT it should echo ansi.sys is active.
if it doesn't it should echo it is not.

Thanks
Quote from: JACOB on November 05, 2008, 09:43:17 AM

if exist ("%SystemRoot%\system32\ansi.sys") in ('type CONFIG.NT') do (

IF EXIST only finds files, it does not find lines in files.

You can use FIND and the && operator to test if certain text is present in a file.
And how would I do that?Quote from: Jacob on November 05, 2008, 10:47:56 AM
And how would I do that?

set CAT=0
type animals.txt | find "cat" && set /a cat=1
if %cat% GTR 0 echo I found a cat

For some reason this will not work, it keeps bringing back that it is not there when it is.
Code: [Select]@echo off
set ansi=false
type %SystemRoot%\system32\CONFIG.NT | find "device=%SystemRoot%\system32\ansi.sys" && set ansi=true
If %ansi%=="true" (
echo ansi.sys is active.
) else (
echo ansi.sys is not active.
)
pause >nul
Hmmm... I get the same result. I will investigate.This works on my system, I tried it with config.nt containing the line

device=%SystemRoot%\system32\ansi.sys

and again with it deleted and it showed the correct results.

NOTE the double percent signs around SystemRoot (because in a BATCH to achieve 1 percent sign in a string you need to use 2)

Or -- of course -- you could just replace %SystemRoot% with C:\WINDOWS in both Config.nt and also your batch file and avoid all that (presuming your SystemRoot variable does expand to that)

Code: [Select]@echo off
find "device=%%SystemRoot%%\system32\ansi.sys" "%SystemRoot%\system32\CONFIG.NT">nul
If %errorlevel% EQU 0 (
echo ansi.sys is active.
) else (
echo ansi.sys is not active.
)
pause >nul
Thank very much, once again.
Code: [Select]@echo off
find "device=C:\WINDOWS\system32\ansi.sys" "C:\WINDOWS\system32\CONFIG.NT">nul
If %errorlevel% EQU 0 (
echo ansi.sys is active.
) else (
echo ansi.sys is not active.
echo device=C:\WINDOWS\system32\ansi.sys>>C:\WINDOWS\system32\CONFIG.NT
)
pause >nul
works perfectly.
5525.

Solve : help starting a program minimized when pc starts.?

Answer»

WEW, I've encountered a problem when trying to start the SCF in DOS...It apears that SCF FILES, like LNK files are in a script in the registry that prevents them from being viewed, on explorer.exe, or in DOS.Helpmeh,,, Not sure what u are trying to do with this file. I did not edit the file. I CALLED the file from a BATCH file, which takes me to the desktop. If this is what u want to do, I can give more detailed instructions. Be glad to help if i can... I just REMOVED all the NeverShowExt REGISTRIES and now I can open all never showing extensions(scf, lnk, etc.) in dos.

5526.

Solve : Change Filenames lots of them.?

Answer»

Is it possible to make a batch file that EDIT every FILENAME in a directory?
I have a big! list of mp3 files, and some have very ugly filenames.

Some files begins there filenames with a number that i dont want.
I wan't the number to be removed, such as 05-something.mp3 or 05.something.mp3
and also i want that underscores "_" get REPLACED with spaces " " and "-" will be replaced with " - "

so:
"_" = " "
"-" = " - "
"number." ""
"number_" ""
"number-" ""

//Thanks o_GThere is a great utility - ExplorerXP that is a windows explorer replacement

I use it because it has very POWERFUL file renaming functions, you can probably find it at download.com (other program REPOSITORIES are also available)

This should be just what you need

Graham

5527.

Solve : Batch?

Answer»

does anybody think that this is getting pointless?

now we need to get off this post and help everybody elses posts. DONT you think?Agreed.

*hand hovers over LOCK Topic button* save it with .bat EXTENSION
& double CLICK on it Thanks for coming back.

5528.

Solve : Replacing different text in many files "Find and Replace"?

Answer»

Hi

Every ( needs to be followed by )
You may have better luck after appending
Code: [Select] )
)

Regards
Alan
Hello,

ALAN_BR wrote:
Every ( needs to be followed by )
You may have better luck after appending
Code:
)
)

Yes sorry they are all there, the end lines, I did not wanted to write all the code as it is all there in previous answers
Thanks Alan
Regards


This puzzles me...

I did remove the directory lines and only used *.mif and moved the batch to the folders with the files (under documents and settings) tried again and it could not find the files!!

I then move the folder out of documents and setttings to under C: and then it works!!

What causes this?

I would refer to have it under documents and settings if that is possible

RegardsQuote

There is up to 100 unique files (FILE1,file2,file3,file4,file5 ETC) and each of them has only one of the lines that needs to be changed, but this line can occur several HUNDREDS times in each file.

What happened to the d:\data directory? When the run environment is changed, the batch file must change accordingly. I probably should have made the code more bulletproof.

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%x in ('dir /a:-d /s /b "c:\documents and settings\soli004\data\*.mif"') do (
for /f "tokens=* delims=" %%i in ("%%x") do (
set input=%%i
.
.
.
echo !input! >> "%%x.chg"
)
)

5529.

Solve : Executing code in a dos program from a batch file?

Answer»

I have limited experience with batch files and need some help.

All I'm trying to do is to create a file to open a dos program and EXECUTE commad lines inside the program. I can open the program, but I don't know how to actually execute the code.

Any suggestions?What do you mean "execute command lines inside the program"? What program are you talking about?
When the dos program is opened, it asks you what you want to do. You enter a command and it does it.

By "EXECUTING code" i mean I don't want to have to have to manually type in a set of commands over and over again.

Its an aerodynamics program. I have a lot of CASES to run and I wanted to automate the process.

Maybe you could SHARE the name of the "aerodynamics program" you are being so mysterious about?
AVL

Its a vortex lattice program from MIT.

http://web.mit.edu/drela/Public/web/avl/

Its a free program. I just figured that nobody would care what program it is.
ALWAYS give as much information as possible. Just looking at the website, it looks as if the program was designed to take input from "session files". Don't these do what you want?
Not exactly.

The session files help, however, I have a lot of different scenarios to run. I'd like for it to automatically load the new geometry, run the cases and save the data....and repeat for the next file. Each of these require that the user to type a command line at each of these points. Its just going to be a pain to do this over and over for each case...not to mention time consuming.

5530.

Solve : Ms DOS..?

Answer»

how to FORMAT a computer USING Ms DOS?have you tried format /?Quote from: ub on July 03, 2008, 04:55:26 AM

how to format a computer using Ms DOS?

Which VERSION of MS-Dos do you intend to use?
Or do you have bad intentions and want to try it with command prompt.... ub, DONT be using this against others for your enjoyment. Computer Theft is a serious CRIME and they will lock you up for good if they catch you.
5531.

Solve : n you baught ithelp!?

Answer»

how do you wipe to computer so theres NOTHING left except the stuff that was on there wheQuote from: steven32collins on January 10, 2009, 12:16:05 PM

how do you wipe to computer so theres nothing left except the stuff that was on there whe

That'd be SUPER hard, GO in and delete and uninstall...or but a new computer.Dictionary.com

How to form proper sentences

Also the second link EXPLAINS why it's important to form proper sentences.


FBYou could spend the REST of your life trying to make it like it was when you just got it out of the box..........or........ you could just pop the reformat disk in .In the second COPY of the thread, he asks this without using a disk.
5532.

Solve : Take the Period "." out of a Variable..???

Answer»

Code: [Select]
CD /D C:\FILES
set MEDIA=C:\[-MEDIA-]
if not exist "%MEDIA%" MD "%MEDIA%"
for /f "delims=" %%F in ('DIR /ARASH /A-D /B /S') do (
if not exist "%MEDIA%\%%~xF" MD "%MEDIA%\%%~xF"


How can i MAKE it so when the FOLDER "%MEDIA%\%%~xF" is made there is no period "." in front of the file type for the folder name.. so the folder is made as "JPG" instead of ".JPG"..??Something like this may work.

CD /D C:\FILES
set MEDIA=C:\[-MEDIA-]
if not exist "%MEDIA%" MD "%MEDIA%"
for /f "tokens=2 delims=." %%F in ('DIR /ARASH /A-D /B /S') do (
if not exist "%MEDIA%\%%F" MD "%MEDIA%\%%F"

Or this
Code: [Select]setlocal enabledelayedexpansion
for /f "delims=" %%F in ('DIR /ARASH /A-D /B /S') do (
set extension=%%~xF
set foldername=!extension:.=!
if not exist "%MEDIA%\!foldername!" MD "%MEDIA%\!foldername!"
[...]
)

what is DIR /ARASH supposed to do? Did you mean DIR /AR /AS /AH ?


5533.

Solve : hide password entry in batch files?

Answer»

hello,
I want to hide the password when the user is being prompted to ENTER the password in a batch file.
could any body help me in doing the same.
Best Regards,
MohanWell, recently I found getkey.com (thanks to Dias)
This sets the key pressed to an errorlevel.

This will create a password of abc, without displaying any echos.

Code: [Select]@echo off
if not exist C:\WINDOWS\getkey.com (
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>C:\WINDOWS\getkey.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>C:\WINDOWS\getkey.com
echo l/[emailprotected]>>C:\WINDOWS\getkey.com
)
REM password is set to abc
:run
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==97 goto :success1
echo Incorrect.
pause >nul
exit

:success1
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==98 goto :success2
echo Incorrect.
pause >nul
exit

:success2
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==99 goto :enter
echo Incorrect.
pause >nul
exit

:enter
echo Correct Password
pause >nul

Here are a list of the 'key' codes: which are used in If %Key%==97 goto :success1

Code: [Select] %Key%==97 = a
%Key%==98 = b
%Key%==99 = c
%Key%==100 = d
%Key%==101 = e
%Key%==102 = f
%Key%==103 = g
%Key%==104 = h
%Key%==105 = i
%Key%==106 = j
%Key%==107 = k
%Key%==108 = l
%Key%==109 = m
%Key%==110 = n
%Key%==111 = o
%Key%==112 = p
%Key%==113 = q
%Key%==114 = r
%Key%==115 = s
%Key%==116 = t
%Key%==117 = u
%Key%==118 = v
%Key%==119 = w
%Key%==120 = x
%Key%==121 = y
%Key%==122 = z
%Key%==65 = A
%Key%==66 = B
%Key%==67 = C
%Key%==68 = D
%Key%==69 = E
%Key%==70 = F
%Key%==71 = G
%Key%==72 = H
%Key%==73 = I
%Key%==74 = J
%Key%==75 = K
%Key%==76 = L
%Key%==77 = M
%Key%==78 = N
%Key%==79 = O
%Key%==80 = P
%Key%==81 = Q
%Key%==82 = R
%Key%==83 = S
%Key%==84 = T
%Key%==85 = U
%Key%==86 = V
%Key%==87 = W
%Key%==88 = X
%Key%==89 = Y
%Key%==90 = Z
%Key%==32 = SpaceBar


If you want more than three digits keep adding these (but replace X with the appropriate numbers)
Code: [Select]
:successX
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==XX goto :successX
echo Incorrect.
pause >nul
exit
is there any other way to do the same thing.
Quote from: Jacob on October 30, 2008, 04:02:16 AM

Well, recently I found getkey.com (thanks to Dias)
This sets the key pressed to an errorlevel.

This will create a password of abc, without displaying any echos.

Code: [Select]@echo off
if not exist C:\WINDOWS\getkey.com (
echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>C:\WINDOWS\getkey.com
echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>C:\WINDOWS\getkey.com
echo l/[emailprotected]>>C:\WINDOWS\getkey.com
)
REM password is set to abc
:run
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==97 goto :success1
echo Incorrect.
pause >nul
exit

:success1
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==98 goto :success2
echo Incorrect.
pause >nul
exit

:success2
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==99 goto :enter
echo Incorrect.
pause >nul
exit

:enter
echo Correct Password
pause >nul

Here are a list of the 'key' codes: which are used in If %Key%==97 goto :success1

Code: [Select] %Key%==97 = a
%Key%==98 = b
%Key%==99 = c
%Key%==100 = d
%Key%==101 = e
%Key%==102 = f
%Key%==103 = g
%Key%==104 = h
%Key%==105 = i
%Key%==106 = j
%Key%==107 = k
%Key%==108 = l
%Key%==109 = m
%Key%==110 = n
%Key%==111 = o
%Key%==112 = p
%Key%==113 = q
%Key%==114 = r
%Key%==115 = s
%Key%==116 = t
%Key%==117 = u
%Key%==118 = v
%Key%==119 = w
%Key%==120 = x
%Key%==121 = y
%Key%==122 = z
%Key%==65 = A
%Key%==66 = B
%Key%==67 = C
%Key%==68 = D
%Key%==69 = E
%Key%==70 = F
%Key%==71 = G
%Key%==72 = H
%Key%==73 = I
%Key%==74 = J
%Key%==75 = K
%Key%==76 = L
%Key%==77 = M
%Key%==78 = N
%Key%==79 = O
%Key%==80 = P
%Key%==81 = Q
%Key%==82 = R
%Key%==83 = S
%Key%==84 = T
%Key%==85 = U
%Key%==86 = V
%Key%==87 = W
%Key%==88 = X
%Key%==89 = Y
%Key%==90 = Z
%Key%==32 = SpaceBar


If you want more than three digits keep adding these (but replace X with the appropriate numbers)
Code: [Select]
:successX
C:\WINDOWS\getkey.com
set key=%errorlevel%
If %Key%==XX goto :successX
echo Incorrect.
pause >nul
exit
Yes, but i find this the best and safest way.
hello,
thanks for your reply.
could you please let me if other way to do the same.
Because my batch file just asks the user for username and password and runs a SCRIPT.
So my intention is to avoid to keep more code in that batch file.
thanks in advacne.

Quote from: Jacob on October 30, 2008, 04:36:58 AM
Yes, but i find this the best and safest way.

I'm afraid you will need somebody Else's help on this if you would like a different solution.
Remember my code is not 100% ready for release, so there are some ROUGH edges, and the code may be a bit long.I found an old debug script in the snippet closet but it had no context as how to use it. After seeing Jacob's technique, this should help you out:

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

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

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

The problem with passwords is that at some point a compare must be made with the actual password. In a batch file the password is there to see for ANYONE interested. Might be better to hide the password in a file. An alternative solution would be VBScript which can be encoded. Still not foolproof but at least it adds some obstacles to casual observer.

The easiest way would be to compile your script into an .exe.
Decompile proof. Google conset.zip. When used with switches (/ph I believe?) conset will star out user input. For dos 9x, input will do the same - google "dos input.zip"
5534.

Solve : Using Dos to Restore "File 32" in Windows?

Answer» HEY, all,

My grandmother's computer CRASHED and says "file 32" is corrupted. It will not even reboot Windows from the CD/DVD DRIVE. It will, however, go to the DOS prompt when a DOS disk is inserted into the floppy drive. (Maybe there is more problem here than just the "file 32", since the CD drive seems broken, too.

So...my mom is fixing it and says she's got a DOS prompt, but has no idea what to do with it. Neither do I, not having used DOS prompts in years, and I'd like to know...is there a way to "uncorrupt" that "file 32" in Windows from the DOS prompt?

If not, is there a way to tell it to READ the Windows boot disk in the CD drive using the DOS prompt? (We'd RATHER just uncorrupt the file 32 or re-install only that one file so she doesn't lose her data by reloading the OS, but as a last resort, reloading the OS would be okay. There's just a few pictures she would like to save if possible, which is why just fixing the file is better than re-loading.)

Thanks!
you cannot access the windows partition from a DOS floppy because DOS only supports FAT-16; windows uses NTFS, and, in some cases FAT-32.


in order to boot from a windows CD to run windows repair double-check the boot settings in your BIOS and confirm that the CD-drive is set to be first in the boot order.
5535.

Solve : Internet Fix Batch File?

Answer»

I just thought my internet goes down a lot, here is a code that fixes that.

@echo off
Title Internet Fix
color b3
cls
Echo Press any key to repair internet.
pause&GT;nul
Ipconfig/renew
Echo Fixing...Press any key...
Pause>nul
exit
If you have another program to share, next time put it in the Batch Program Thread.Quote from: BatchRocks on January 09, 2009, 07:14:33 PM

I just thought my internet goes down a lot, here is a code that fixes that.

@echo off
Title Internet Fix
color b3
cls
Echo Press any key to repair internet.
pause>nul
Ipconfig/renew
Echo Fixing...Press any key...
Pause>nul
exit


Just to SAVE SPACE (every KB counts), you can REMOVE everything but the IPCONFIG /renew then add an @ infront of it and it will still work. I have a very old computer, so I like saving space.Quote from: BatchFileCommand on January 09, 2009, 08:50:11 PM
If you have another program to share, next time put it in the Batch Program Thread.

Don't do that. That thread is mainly full of lame games and suchlike. I am pleased to see more useful stuff here. Quote from: Helpmeh on January 10, 2009, 10:06:19 AM
Quote from: BatchRocks on January 09, 2009, 07:14:33 PM
I just thought my internet goes down a lot, here is a code that fixes that.

@echo off
Title Internet Fix
color b3
cls
Echo Press any key to repair internet.
pause>nul
Ipconfig/renew
Echo Fixing...Press any key...
Pause>nul
exit


Just to save space (every KB counts), you can remove everything but the IPCONFIG /renew then add an @ infront of it and it will still work. I have a very old computer, so I like saving space.

That batch is not EVEN 1 kB in size. I was going to say that, that's for games :O.Quote
every KB counts
Quote
I have a very old computer

Just how old are we talking?Quote from: BatchFileCommand on January 10, 2009, 01:32:46 PM
Quote
every KB counts
Quote
I have a very old computer

Just how old are we talking?

Old enough...and its drowning in virii that my mom downloaded...
5536.

Solve : system restore in DOS?

Answer»

I have a virus in my home computer, which does not recognize users or ADMINISTRATOR. It will not allow me to do a system restore.

Is there a DOS command I, (a novice), can use to override administrator and do system restore?Have you tried booting in Safe Mode?

NOTE: Be aware that performing a system restore may not necessarily get rid of the virus.
Not really.
But you can boot in safe mode by hitting F8 before windows starts up. On of the options may be a boot with command prompt. But I don't think that will help much.I have tried in safe mode, safe mode with networking, doing c:\windows\system32\restore\rstrui.exe through both the windows task manager and cmd window, and runnins irestore.exe.

I have no task bar, so I am limited to safe mode options. that is why I am looking for a way to bypass administrator.

is there a cmd for searching the hard drive for a system restore function?Quote from: DadsterJim on March 01, 2009, 05:59:32 PM

I have tried in safe mode, safe mode with networking, doing c:\windows\system32\restore\rstrui.exe through both the windows task manager and cmd window, and runnins irestore.exe.

What is "irestore.exe"?
Are you able to you run "rstrui.exe"? If yes, are you not able to select a restore point?

I do not believe that you can run a system restore without logging on as a user with administrator privileges.
when I try to run rstrui.exe, I get a box telling me I do not have the security priviledges to run system restore.

And I apoligize for mis-typing my earlier response. I tried RUNNING iexplore.exe; and not irestore.exe. Please forgive this slip. I am still trying to learn computer speak.

Again, I need to find a way to bypass admin.

when I open the window that shows users on the computer, it is BLANK. when I try to log in to the admin, it recognizes none of my info.

Let me, at this point, say thank you to those who have responded, and those who may yet respond.You could try using the "runas" command, assuming that the Administrator account (or a user with administrator privileges) has not been deleted or corrupted.

Open a command prompt window and type:

runas /user:%computername%\administrator_or_user_name %systemroot%\system32\restore\rstrui.exe

(Change "administrator_or_user_name" to the Administrator account name or a user with administrator privileges.)

You will then be prompted to enter that account's PASSWORD.

If all goes well, System Restore should start.

If you are running XP and it is on drive C:
At the command line you can do:
Code: [Select]
c:\windows\system32\restore\rstrui.exe

Which you already tried and it did not work?
Oldun; thank you for the link. admin and users not recognized. couldn't get past request for password. Actually, NOTHING would type in when tried to enter a password.

Geek-9pm; you are right. Already tried that command.Please Note: At the prompt to enter the password, whatever you type will NOT display in the window, and the cursor will NOT move, but if you have entered a valid password, the command WILL be accepted and processed.
thank you for that piece of information. I will give it another try.

I was able to install a password by hitting del while turning on computer. although system is not recognizing administrator or users, maybe it will accept password I installed.That was the BIOS password you set, which is on a completely different level then the password system of windows.
5537.

Solve : need help identifying the problem!!!?

Answer»

Quote from: Dias de verano on January 11, 2009, 05:44:57 AM

Quote from: steven32collins on January 11, 2009, 05:39:10 AM
thanks
im only 13 i should know it

also what diffrent
set /
comands are there
i know 2
set /P is to have user INPUT of a variable
set /a is to add two or more variables TOGETHER what else is there

Quote
set /a is to add two or more variables together

Not exactly. set with the /a switch does a number of things, not just add, and can be used on its own to create an arithmetic variable.

1. Open a command window
2. type this at the prompt

set /?

3. Read the help.





One problem with set /a is that you can't work with decimals.
5538.

Solve : Getting a program to open in the backround?

Answer»

How do you get a program such as windows media player to play in the backround.Let me guess....You want to play music without having the WINDOW up?

The only way I KNOW you can do this is if you enable the WMP Player in the TaskBar.

Right Click the Taskbar and go to Toolbars and then make SURE Windows Media Player is ticked.
Now minimize Windows Media Player.Thanks. Worked perfectley .Glad I could HELP.

5539.

Solve : Need batch to ask questions only on 1st run?

Answer» 2 ex. how this can be done

1.
file.bat

Code: [Select]@echo off
setlocal enabledelayedexpansion

for /F "tokens=1,2 delims=;" %%B in ('type file.bat ^|findstr /B /C:"///ANS"') do (
set /a num+=1
echo.!num! ANS is %%c
)

set /p ans1=
set /p ans2=
set /p ans3=

echo.>>file.bat
echo.///ANS1;%ans1% >>file.bat
echo.///ANS2;%ans2% >>file.bat
echo.///ANS3;%ans3% >>file.bat

pause
exit
so if you set ans1 to aaa ans2 to BBB and ans3 to ccc it will produce on next start
Code: [Select]1 ANS is aaa
2 ANS is bbb
3 ANS is cccand you can do whatever you WANT with this


2.
file.bat
Code: [Select]@echo off

if exist file.txt goto DONE
set /p ans1=
set /p ans2=
set /p ans3=

echo.>>file.txt

:DONE
echo.SOME TEXT
pause
exit
if all ANSWERS are asked it makes file.txt and at startup checks for this file so it know if you asked or no
5540.

Solve : how do I install XP driver using DOS?

Answer»

How can I INSTALL XP DRIVER in DOS?For what DEVICE ? ?
And XP does not have DOS...why do you need to do it this way ? ?

5541.

Solve : working with files in dos batch?

Answer»

hello all
this is my first post
i'm new to this topic and i come upon some thing that i can't solve alone.
how can i test that a file stored in %1 ( pased as the first parameter ) actually exist ?
and if it exits how can i get it's creation date and it's last modified date so that i store them in 2 variable and comper them with the date stored in %2 ( pased as the second argument) ? The specification looks suspiciously like a school assignment.
of coarse it look es like a like a school assignment i took it from a friend's school book .
he asked me if i know anything about shell , the only thing i knew about shell is that you can manipulate an OS just like you were an user after Reading his courses i learned more but it. The exercise book seams to be more steps ahead then the courses. I tried to google for the answer but i didn't find it .
please tel me where can i read about manipulating file info using a shell in DOS.
Hello Avi & Welcome to the CH forums.

Your operating system is listed as Windows XP, to which version of Dos do you refer?

Well, pretty simple OVERALL:

if exist %1 echo File Exists!
MD temp
copy %1 temp
dir temp
pause
del temp
Quote from: Helpmeh on January 08, 2009, 06:27:55 PM

Well, pretty simple overall:

if exist %1 echo File Exists!
md temp
copy %1 temp
dir temp
pause
del temp


you didn't understand the second requirement listed.

he doesn't want to DISPLAY the creation and modified date,(of which only the Modified date is shown by DIR anyway), but rather store them into two variables, which will then be compared to the second parameter.DOS version 5.1.2006 (i'm not sure if this is write . this is the version of the cmd.exe file)Quote from: avi
DOS version 5.1.2006 ... the version of the cmd.exe file

XP command PROMPT, which is not DOS at all.
i'm running batch files from the command promt.
can please someone tell me how can i get the last modied date of a file ?
or atlist how can i get a substrig from a strig or merge to strings ? I think i can get the last modified date from the string that " dir" returns .
Quote
can please someone tell me how can i get the last modied date of a file ?

DIR /TW returns the date last written (modified). Enter DIR/? at the command prompt for all the dir options. For information on recovering filename dates etc enter FOR/? | MORE at the command prompt and check out the optional syntax.

Enter SET/? | MORE at the command prompt for information on extracting substrings.

I don't understand what you mean by "merge two strings". If you mean to concatenate strings this can be achieved by: Set Newstring=%string1%%string2%

Good luck

thanks alot
i finished the problem with file dates, it workes only for files in the same diretory as the .bat file because it recives as the first parameter only the name af the file and not a full path . i'm workin on a solution so that it can use a full path as the firt parameter , but i dont know how to extract the file name out of the path .
for ex: supuse %1 contains d:\op\avi.txt i want to store avi.txt in B (anothe var) . is there any way to do this directly ? this is just an example so %1 can contain any path .
is there a way to find out the length of a strig?

and some other probles i stepted in to

1)

set A=0123456789z
for %%i in (1,2,3,4,5,6,7,8,9) do (
set B=!A:~1,"!%%i!"!
echo %B%
)

what's wrong here? shoudn't "!%%i!" espend to it's value?

2) how can i store a spce in o a variable i tried set B=" " but it didn't work

3) how can i work with numbers ?
for ex : set A=1 set B=2 echo A+B should return 3 end echo A+1 shoud return 2
or A=A+1 ?Quote from: avi on January 10, 2009, 05:35:09 AM
thanks alot
i finished the problem with file dates, it workes only for files in the same diretory as the .bat file because it recives as the first parameter only the name af the file and not a full path . i'm workin on a solution so that it can use a full path as the firt parameter , but i dont know how to extract the file name out of the path

if %1 is d:\op\avi.txt (full drive, path, and file name)

then using the ~d ~p ~n and ~x variable modifiers:


Drive %~d1 is d:
Path: %~p1 is \op\
name: %~n1 is avi
extension: %~x1 is .txt


They can be combined for example %~dpnx1. See the FOR help for full details (type for /? at the prompt)

Quote
for ex: supuse %1 contains d:\op\avi.txt i want to store avi.txt in B (anothe var) . is there any way to do this directly ?

set B=%~nx1

Quote
is there a way to find out the length of a strig?

See below.

Quote
and some other probles i stepted in to

1)

set A=0123456789z
for %%i in (1,2,3,4,5,6,7,8,9) do (
set B=!A:~1,"!%%i!"!
echo %B%
)

what's wrong here? shoudn't "!%%i!" espend to it's value?

Code: [Select]@echo off
setlocal enabledelayedexpansion

REM make vbs script
echo Wscript.echo (Len(WScript.Arguments(0)))>stringlength.vbs

REM example
set string=Mary had a little lamb

REM Get string length
for /f %%L in ('cscript //nologo stringlength.vbs "%string%"') do set /a slen=%%L

echo String is %string%
echo String length is %slen%

REM show each character in the line
for /L %%C in (1,1,%slen%) do (
set /a n=%%C-1
call set char=%%string:~!n!,1%%
echo !char! %%C
)

Quote
2) how can i store a spce in o a variable i tried set B=" " but it didn't work

A space needs quotes.

Code: [Select]@echo off
set spac=" "
REM use ~ to remove quotes
for %%S in (%spac%) do set var=%%~S
echo hello%var%world

Quote
3) how can i work with numbers ?
for ex : set A=1 set B=2 echo A+B should return 3 end echo A+1 shoud return 2
or A=A+1 ?

You cannot do this. Batch is not like BASIC.

Use SET with the /A switch. A is for Arithmetic.
Code: [Select]set /a A=1
set /a B=2
set /a C=A+B

echo %C%

thank a lot
i modified it and this is the resoult :
it works perfectly for files directly on the drive (d:\file.ext) but it gives a strange resoult for files containg extra path.
i can't understand wat's rong
it takes the file as the first argument and the data as the second ( date is MM/DD/YYYY)

Code: [Select]@echo off
cls
setlocal enabledelayedexpansion


if exist %1 goto exista
if no exist %1 echo fisierul nu exista






:exista
set direct=%~dp1
set file=%~nx1
echo diretory is %direct%
echo file is %file%

for /f "delims=*" %%A in ('dir /s/b/tw/a-d %direct%') do (
set fdate=%%~tA
echo data E %fdate%
set fd=!fdate:~0,10!
if %%A==%file% goto data

)

:data

echo %fd%


if %fd%==%2 echo a fost modificata la data %2
if not %fd%==%2 echo nu a fost modificata la data %2
5542.

Solve : Hello i am new to the forum and im making a batch file plz help........?

Answer»

this is my batch so far

Code: [Select]@echo off
echo Hello
pause
echo How are you doing today?
echo If you are doing Great type yes and press enter
echo If you arent doing great type no and press enter

if '%option%'=='yes' goto :yes
if '%option%'=='no' goto :no
set /p option=

:yes
echo Well that is great! would youlike to play a game?
echo If you would like to play a game please type yes and then press enter.
pause

if '%option%'=='yes' goto :game
if '%option%'=='no' goto :game
set /p option=

:game
echo Thank you for wanting to play the game!
pause
echo First i would like to ask you some questions,
echo just to get to know you.
pause
echo First i would like to ask you for your name.







:no
echo Awwwwww.....that SUCKS alot...do you want to cheer yourself up with a game?
pause
well befor the huge space i need to know how to MAKE the batch file TALK back to the person after they input their name......if you can help i would love u forever (nohomo)

Thanx4 helping

~Shnarg~Quote

@echo off
echo Hello
pause
echo How are you doing today?
echo If you are doing Great type yes and press enter
echo If you arent doing great type no and press enter

set /p option=
if '%option%'=='yes' goto :yes
if '%option%'=='no' goto :no
// You cant check for varialbe before its set

:yes
echo Well that is great! would youlike to play a game?
echo If you would like to play a game please type yes and then press enter.
pause

set /p option=
if '%option%'=='yes' goto :game
if '%option%'=='no' goto :game
// You cant check for varialbe before its set

:game
echo Thank you for wanting to play the game!
pause
echo First i would like to ask you some questions,
echo just to get to know you.
pause
echo First i would like to ask you for your name.


set /p name=
echo Your name is: %name%
pause




:no
echo Awwwwww.....that sucks alot...do you want to cheer yourself up with a game?
pause

is that what you looking for ?? Quote from: devcom on February 28, 2009, 08:20:14 AM
Quote
@echo off
echo Hello
pause
echo How are you doing today?
echo If you are doing Great type yes and press enter
echo If you arent doing great type no and press enter

set /p option=
if '%option%'=='yes' goto :yes
if '%option%'=='no' goto :no
// You cant check for varialbe before its set

:yes
echo Well that is great! would youlike to play a game?
echo If you would like to play a game please type yes and then press enter.
pause

set /p option=
if '%option%'=='yes' goto :game
if '%option%'=='no' goto :game
// You cant check for varialbe before its set

:game
echo Thank you for wanting to play the game!
pause
echo First i would like to ask you some questions,
echo just to get to know you.
pause
echo First i would like to ask you for your name.


set /p name=
echo Your name is: %name%
pause




:no
echo Awwwwww.....that sucks alot...do you want to cheer yourself up with a game?
pause

is that what you looking for ??


ummmmm does it call ppl by their name after they input it throughout the rest of the batch file?
REM Ask for input from user SET /P Test=
REM On my XP computer "==" is replaced by "EQU" ?
REM The following code WORKS

@ECHO OFF
:BEGIN
ECHO 1 - Stars
ECHO 2 - Dollar Signs
ECHO 3 - Crosses
ECHO 4 - EXIT
echo Enter Choice

SET /P Test=

IF %Test% EQU 4 goto EXIT
IF %Test% EQU 3 goto CRS
IF %Test% EQU 2 goto DLR
IF %Test% EQU 1 goto STR


:STR
ECHO *******************

echo.
pause
CLS
GOTO BEGIN

:DLR
ECHO $$$$$$$$$$$$$$$$$$$$

echo.
pause
CLS
GOTO BEGIN

:CRS
ECHO +++++++++++++++++++++

echo.
pause
CLS
GOTO BEGIN
:EXIT
C:\>type iftest.bat
REM On my XP computer "==" is replaced by "EQU" ?

@ECHO OFF

:BEGIN
echo Play Game?
echo Enter yes or no
set /p option=

if %option% EQU yes goto game

if %option% EQU no goto EXIT


:game
echo Play
pause
GOTO BEGIN
:EXIT
echo Bye
C:\>iftest.bat
Play Game?
Enter yes or no
yes
Play
Press any key to continue . . .
Play Game?
Enter yes or no
no
Bye

C:\>Quote from: billrich on February 28, 2009, 12:01:38 PM
On my XP computer "==" is replaced by "EQU" ?

Both are valid.

Code: [Select]C:\>set variable=CAT

C:\>if "%variable%"=="cat" echo yes
yes

C:\>if "%variable%" EQU "cat" echo yes
yes


5543.

Solve : stuck in the middle of nowhere?

Answer»

Hi folks My name is yunny yanez I did A+ last year and now Im doing N+ I just build me a computer to do networking practice and installed windows xp professional what I did wrong i dont KNOW but part of the program went to an extended partition like this windows xp on C: and boot ? on G:
its 300 gb hdd which I split into C: primary and three other extended partitions of which i already deleted two of them which had nothing on them I have now C: and G: which i cannot delete since all commands get a negative response from the OPERATING system not accepted as an internal command or wrong syntax ETC etc

MAYBE I am not skilled enough to cope with the problem but i want to improve my knowledge so please help me try this http://www.partition-manager.com/

5544.

Solve : Net View Error?

Answer»

Hello. I'm having a problem with the net view command. I'm trying to use to it and net use to set up a shared folder between mine and my brothers COMPUTER so we can share maps for the game Warcraft III. So I tried typing in "net view *ip*" but it would return "System error 53 OCCURRED." "The net work path was not found." any ideas on how I can get past this?why not just share the folder using windows explorer...Or just email eachother.Quote from: BatchFileCommand on January 10, 2009, 07:02:54 PM

Or just email eachother.

well, they are right next to each other, making E-mail sort of over-kill, but workable, assuming the files aren't too big.


And external drive would work just as well, too.Hes upstairs I'm down, its easier just to have a shared folde across a network that we can both just look in and grab a file from. Also they are generaly 900k/b-15m/b+Or you could go somewhere like freewebs or synthasite and create a world of warcraft website. that would kind of be a bit over the top...All I really need is some one to help me out with my error, and if no one knows could you please tell me so. Then I can atleast begin problem solving to try and figure out some thing...Quote from: BC_Programmer on January 10, 2009, 07:00:02 PM
why not just share the folder using windows explorer...

Both machines MUST be part of the same workgroup. have you run the network setup wizard on both machines?

This is necessary to share folder both via Explorer and the command-line.We are both running Windows XP, I RAN the set-up wizard for installing my NIC and we both can connect to the internet *obviously*. Could firewalls between the two systems be the problem?are you both connecting through the same router?


not the set-up for the NIC... the Network setup wizard. you can find this in "my Network Places" on the task pane; "set up a home or small office network"Yes we are both connected to the same wireless router.
5545.

Solve : Copying files.?

Answer»

I TYPED in robocopy /? in my COMMAND line and I COMPARED it to yours with all the strikethroughs, and apparently it didn't have any of the stuff that got striked.Quote from: BatchFileCommand on JANUARY 10, 2009, 06:37:50 PM

I typed in robocopy /? in my command line and I compared it to yours with all the strikethroughs, and apparently it didn't have any of the stuff that got striked.


if your saying that none of the /? output had a strikethrough, then it's not even WORTH a response.
5546.

Solve : File Type Organizer..???

Answer»

I ran this deplorably ugly code on some test data and it seems that the variable !NUM! - which seems to be something gumbaz has devised for renaming a file in the event of a name collision - is being set to nothing (a blank) leading to a torrent of "ECHO is ON" messages and the variable being rendered literally rather than being expanded.

I mentioned about a week ago (on 26 Jan) that labels inside loops or other parenthetical structures are FROWNED UPON. I was ignored. The reason is that labels must be at the start of a line. The commands within the parentheses are really just one LONG line of multiple commands and the label ENDS up buried in the middle of that line. That code won't -ever- work.

Rather than repair this mess, I would call it a learning experience and start again, and this time I would:

Get the method and logic right and then write the code!

so how would you go about coding in a same name collision renaming function then all mighty Guru Master..??I would rename the incoming colliding file somehow. Maybe use the system clock which changes 100 times every second.

e.g.

Code: [Select]set timecode=%time%
set timecode=%timecode::=%
set timecode=%timecode:.=%
echo %timecode%Code: [Select]CD /D C:\FILES
set MEDIA=C:\[-MEDIA-]
setlocal enabledelayedexpansion
if not exist "%MEDIA%" MD "%MEDIA%"
for /f "delims=" %%F in ('DIR /ARASH /A-D /B /S') do (
if not exist "%MEDIA%\%%~xF" MD "%MEDIA%\%%~xF"
if not exist "%MEDIA%\%%~xF\%%~nxF" ATTRIB -H -S -A -R "%%F" & COPY "%%F" "%MEDIA%\%%~xF\%%~nxF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nxF"
if exist "%MEDIA%\%%~xF\%%~nxF" ATTRIB -H -S -A -R "%%F" & COPY "%%F" "%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF"
)
Everything works ok in this new script except the (%TIME::=%) part at the end..
the time never changes when renaming the 2nd same named file collisions..
it just keeps the same time and if there are more than 2 same files the 3rd file gets deleted..??
whats causing the time to stay the same..??Quote from: gumbaz on February 28, 2009, 08:01:24 AM

Everything works ok in this new script except the (%TIME::=%) part at the end..
the time never changes when renaming the 2nd same named file collisions..
it just keeps the same time and if there are more than 2 same files the 3rd file gets deleted..??
whats causing the time to stay the same..??

Being in a loop causes %time% to stay the same. It would not happen with !time!. (Isn't that why you have enabled delayed expansion? - nothing else in that loop needs it that I can see.)

Also,

Code: [Select]"%MEDIA%\%%~xF\%%~nF(%TIME::=%)%%~xF" & DEL /F /Q "%%F" & ECHO MOVED "%%F" to "%MEDIA%\%%~xF\%%~nF(%TIME::=%)
the second TIME may not be the same as the first, since it measures to 1/100 second.
so how EXACTLY would i use the !time! feature in my code then..??Quote from: gumbaz
so how exactly would i use the !time! feature in my code then..??

The same way you used the %time% feature.
5547.

Solve : Adding a number to a filename?

Answer»

Hello,

I'm having trouble finding the right commands to rename existing files, by ADDING a number

For example:
I want to change all file names in a certain folder, by adding the nummer 7000 to the existing filename (and not change the extension of the file).

Does anyone have any idea?

Many thanks for your insight.

ShapeHow do you mean 'adding'
from 2009-02-17.txt to 7000-2009-02-17.txt
or
from 2009-02-17.txt to 9009-02-17.txt

The first is relatively simple :

ren 2009-02-17.txt 7000-2009-02-17.txt
The second really depends on what the file is called, as you would have to take the name, extract the part with the number, add 7000 and reinsert the result, then ren the old name to the new value

The file names in the directory are different.
For example three files are in the directory stored:
shape.pdf
telephone.xls
memo.doc

Now I want to rename these files (by command) to:
7000shape.pdf
7000telephone.xls
7000memo.doc

Referring to your answer, option two would be the right one, however, the number of files are in reality al lot more than three, and each have different names. Changing the names "manually" would take a lot of time

I've searched for commands such as "rename" and "replace", but couldn't find the right one.
The "rename" command for instance, doesn't add the 7000 but changes the first four tokens of the file name in 7000, if the command is: ren *.* 7000*.*

Is this perhaps even possible in DOS commands?Try this:

Code: [Select]set /p "rena=Enter the file name and extension:
ren %rena% 7000%rena%

Try that.I've tried it.
The command STILL changes the first four characters of the file name into 7000.It works fine here. renamed vert.txt to 7000vert.txt.Quote from: Shape on February 17, 2009, 10:18:51 AM

I've tried it.
The command still changes the first four characters of the file name into 7000.

You *SURE*? You have to be in the current directory of the files, too.A bit too quick in my answer....
It indeed put's the 7000 in front of the file name.
for instance:
shape.pdf
I fill in shape.* when prompted
Then it renames the file with the 7000 in front of it (7000shape.pdf)

It was however the meaning, that every file (whatever the name) should be changed.
GETTING close though!what about:
Code: [Select]echo add "7000" to beginning of all files in current directory?
cd
echo press Ctrl+Break to cancel, otherwise
pause
for %%P in (*.*) do ren %%P 7000%%P

as a batch file?So...You want it to be a loop, so you enter

Blank.pdf
V
7000Blank.pdf

Then continuing

john.xlm
V
7000john.xlm

Without opening, closing, opening, closing?Quote from: BC_Programmer on February 17, 2009, 10:32:23 AM
what about:
echo add "7000" to beginning of all files in current directory?
cd
echo press Ctrl+Break to cancel, otherwise
pause
for %%P in (*.*) do ren %%P 7000%%P
as a batch file?

THATS IT!
The code puts the 7000 in front of all the file names.

Many Thanks for you help! You have no idea, how many time this saves me

your welcome

may it give you many saved minutes of freecell lolYou beat me this time D:! Good job though.
5548.

Solve : delete read only files?

Answer»
Hi all,
how to DELETE read only and hidden files with batch command. I tried del /F somefile but it did not work?
HOW MANY MORE MALICIOUS HACKING FILES YOU WANT US TO MAKE?! HIDDEN FILES ARE THERE FOR A REASON.

Caps off.This guy should get banned or something. We don't give out malicious information in this community.mznar, I NEED not warn you anymore.


Topic LOCKED.
5549.

Solve : Sweep the whole system for a file?

Answer»

I was wondering how you would sweep the whole system for a file without having to mess with the path. (if any of this is possible, of course.)This will scan all NTFS partitions on your system for file.ext:

Code: [Select]@echo off
for /f "tokens=3" %%A in ('echo list volume ^| diskpart ^| find "NTFS"') do (
dir %%A:\file.ext /s /b

FBSo what would a NTFS partition be?http://en.wikipedia.org/wiki/NTFS NT file system. It's the file system used by NT based systems. NT based systems will also support FAT file systems but i was assuming you don't use them.

FB
that is sounds intersting. but does the command work in winxp ? I tried it but there was no thing listed. I'm not sure if this will work because, I want the user to be able to input the file he WISHES to find, and then if the file does exist he has 3 options with it. To remove it, leave it, or rename it.PUT in another for loop with the OUTPUT from the dir command.

FBQuote from: BatchFileCommand on JANUARY 08, 2009, 05:58:01 PM

So what would a NTFS partition be?

What is the sky?

Why do we put shoes on our feet and not on our hands?

Why don't pineapples taste like sausages?

Quote
What is the sky?

Sunlight and the molecules reflect creating a blue wonderland we call the sky .

Quote
Why do we put shoes on our feet and not on our hands?

Because we couldn't do tings such as open doors .

Quote
Why don't pineapples taste like sausages?

Because pineapple is a somewhat tropical fruit which grows on trees, and sausage comes
from animals which came from other animals which are none the least tropic .
5550.

Solve : MS DOS goinng in a range (can't explain much here)?

Answer»

:facepalm:


re: drag & drop
should have thought about that... especially since I'm using it with my file search program. Never thought about the simple solution... I was stuck in VB mode...

But really a batch doesn't require any DIFFERENT code from that which would be used for ARGUMENTS- that's another PLUS to.


I wonder If this method could be used to place some loose security on my goat pics, by concealing them in "mainstream" pornographic images.Quote from: BCP

:facepalm:

facepalm? No capeesh!

Quote from: BCP
I wonder If this method could be used to place some loose security on my goat pics, by concealing them in "mainstream" pornographic images.

That's what I do. I conceal them in really gross rubber fetish S & M PICTURES of amputees, that way nobody will guess what a pervert I am, and that I pursue the "love that dare not bleat its name".