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.

8801.

Solve : Unfamiliar with use of the @ sign at the end of a statement?

Answer»

In a DOS batch FILE I am trying to understand, I have found a statement which uses the "@" sign in a way I am not familiar with. I have look in several places and my books, but I have not found an explanation. The statement is:

type {file name}\[emailprotected]

Where {file name} is a legitimate file name and temp is a legitimate sub file name

Does anyone know what the "@8" does.

I am familiar with USING the "@" sign to suppress printing of a statement such as "@echo" to suppress the printing of "echo".

Thanks for any help,

Tom
It is a unit of measure
http://en.wikipedia.org/wiki/Arroba
It is also used in accounting.
http://en.wikipedia.org/wiki/At_sign

Also:
Quote

In Perl, @ prefixes variables which CONTAIN arrays.
In Pascal, @ is the "address of" operator
In Welsh, it is sometimes known as a malwen or malwoden (a snail).

[ @ ] (Asperand or At) This sign is used in batch files to prevent the text following it on the same line from being displayed on the screen. An example is "ECHO OFF". It is used at the start of most batch files to turn off screen echoing (displaying) for all lines following. Employing `@' with it as "@ECHO OFF", will prevent this Asperand and the words "Echo Off" from appearing on screen.

As well as the above, `@' is used by 4DOS to designate variable FUNCTIONS. "@FILEDATE" will return a file's date, as an example.

Finally, the `@ sign is employed to designate file lists in many versions of DOS. "DEL @FILENAME.lst" means that DOS will delete the files listed in "FILENAME.lst".

But @8 is note known here.
It's not used. "{file name}" is a directory. "[emailprotected]" is a file.Thanks for the quick replies.

It was used as a file name. SEARCHING deep into the referenced program I found several folders with file names such as @1, @2, @3,....

Tom
8802.

Solve : How to move a full folder??

Answer»

So, i have a big folder with other folders and files inside it.
Whats the Batch command to move it to another location?I would do this, but there may be a better way. As far as I know the move command doesn't work for a directory tree.

Code: [Select]XCOPY "[source folder here]" "[destination folder]" /E /C /R /I /K /Y
RD "[source folder]"
MOVING large Trees with DOS is not a very GOOD idea.
The likelihood of error is rather high.
Files may be in use or marked as read-only which will cause errors.

First copy, then if no errors, remove original files and folders. Better yet, use a program made to do this kind of work. Windows has a application CALL 'Sync Toy' that could be used.

Quote

SyncToy 2.1
Brief Description
SyncToy 2.1 is a free application that synchronizes files and folders between locations. Typical uses include sharing files, such as photos, with other computers and CREATING backup copies of files and folders

Quote
Files may be in use or marked as read-only which will cause errors.

The /E /C /R /I /K /Y should take care of that. As for the being in use, it would behave the same way in GUI, right?Quote from: Linux711 on April 30, 2011, 02:03:36 PM
The /E /C /R /I /K /Y should take care of that. As for the being in use, it would behave the same way in GUI, right?
No. It depends. But you can use Robocopy
Quote
While still included in Windows Vista, Xcopy has been deprecated in favor of Robocopy, a much more powerful copy tool, which is now built into the operating system.
http://en.wikipedia.org/wiki/Robocopy
8803.

Solve : Using BATCH file: Find a number inside a file and increment it?

Answer»

Quote from: Allan on May 01, 2011, 02:47:25 PM

It is what it is. LET's stay with the thread please. Thanks.

Essentially, this thread is now complete. The OP expressed a requirement which was clarified and then addressed, despite frequent attempts at INTERFERENCE, to the OP's expressed SATISFACTION.
Okay Thanks. I'll LOCK it then.
8804.

Solve : Add Created Date to Current Word File Name?

Answer»

Hi,

I've never used DOS before but figure it's the only way to RENAME hundreds of already saved word documents with the current filename and the created date appended to the end.

In work they want the following format (filename = xxxxxxxxxx_YYYYMMDD). Can anyone help as I have been going through them picking out duplicate documents and adding the created date one at a time. It's DRIVING me mad.

Many thanks,

Jo We need to know your local date format SETTINGS. How do file dates show up in DIR listings?

If they are Word documents do you still need the .doc extension for example like this?

xxxxxxxxxx_YYYYMMDD.doc
Thanks for replying. I'm not sure how to tell what format anything is in with DOS. It's a work computer and I won't be in there until tomorrow morning. I'm in the UK sorry. Is there anything else I need to find out while on the computer tomorrow?

Many thanks,I'm in the UK too. If the computer system has the UK date setting then, when you open a command prompt and type DIR the result should look like this


D:\>dir
Volume in drive D is SATA2
Volume Serial Number is E8B2-C5D7

Directory of D:\

17/04/2011 13:18 <DIR> $RECYCLE.BIN
22/07/2011 20:01 1,010,592 -list.csv
16/04/2011 21:14 <DIR> Audio-DL
16/02/2011 21:33 <DIR> Camera Videos
14/07/2011 17:49 <DIR> Cinema
24/07/2011 19:56 <DIR> DVD-Author
04/06/2011 11:18 <DIR> F-Root
13/02/2011 14:03 2,308 fraglist.luar
13/02/2011 14:03 2,388 fraglist.txt
09/07/2011 14:39 <DIR> Music
26/06/2011 12:21 <DIR> OS-Install
10/07/2011 19:41 <DIR> Railways
09/07/2011 00:07 <DIR> Tempvu
17/07/2011 21:16 <DIR> TV
17/07/2011 15:21 <DIR> Virtual Machines
12/11/2010 19:57 <DIR> wallpaper
22/05/2011 11:29 <DIR> Webspace
04/06/2011 11:19 <DIR> WindowsImageBackup
3 File(s) 1,015,288 bytes
15 Dir(s) 204,722,483,200 bytes free


That is, the file date is given in the form dd/mm/yyyy




Code: [Select]@echo off
rem Assume your %date% format is mm/dd/yyyy
for %%a in (*.doc) do (
ren "%%a" "%%~na_%date:~6,4%%date:~0,2%%date:~3,2%.doc"
)Quote from: CN-DOS on August 14, 2011, 07:08:28 AM

rem Assume your %date% format is mm/dd/yyyy

Why?

Oooooooops, in case OP doesn't know how to get create data.
Code: [Select]@echo off
rem Assume your %date% format is mm/dd/yyyy
for %%a in (*.doc) do (
call :CreateTime "%%a"
)
goto :EOF

:CreateTime
setlocal enabledelayedexpansion
for /f "skip=5" %%b in ('dir /tc %1') do (
set ct=%%b
ren %1 "%~n1_!ct:~6,4!!ct:~0,2!!ct:~3,2!.doc"
goto :eof
)
endlocalhi jaynelson,

Did you tried a filename with blank space? Like "HELLO world.doc"
8805.

Solve : python script?

Answer»

Hi
I don’t know anything about programming languages. I’m trying to run a python script from the command line (./proc.py) and I get the following MESSAGE “./proc.py is not recognized as an internal or external command, operable program or batch file. What should I do?
Quote from: belen on May 02, 2011, 08:41:03 AM

Hi
I don’t know anything about programming languages. I’m trying to run a python script from the command line (./proc.py) and I get the following message “./proc.py is not recognized as an internal or external command, operable program or batch file. What should I do?
The command
./proc.py
will not work from the command line. It is not part of the set or programs or commands that *DOS knows about. A script has to be run from its interpreter.This rule applies not only to Python, but all scripting languages.
A Python interpreter suitable for DOS can be found at:
http://www.python.org/
The CURRENT production versions are Python 2.7.1 and Python 3.2.

Once you have a suitable version installed on your PC, you can INVOKE Python from the command line and pass the script as an argument. SEE the documentation for EXAMPLES.
--------
*DOS, I mean the command line in Windows. Everybody calls it DOS and the documentation is found under DOS on this forum.
Screen Shot of shell.
8806.

Solve : How to create a loop??

Answer»

Hi,

I was wondering if someone can help me create a loop in a batch file? What I'm doing is creating a batch file that will build a SQl 2005 DB from scripts. I've got the SQL scripts in a folder on the C drive.

I've created a batch file that will look in the directory with the scripts and put the list of names of the SQL files in a cmd file called myfile.cmd. i.e.

ADR.sql
ADTC.sql
BedMap.sql
Community.sql

The script then uses that myfile.cmd to make a new cmd file with the SQLCMD appended to the SQL script name to execute and create the DB. So what you GET is if you have 30 SQL scripts in the folder on C drive the cmd file will have 30 lines in it to build the DB. i.e.

SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\ADR.sql -o C:\Logs\NightlyLog.txt
SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\ADTC.sql -o C:\Logs\NightlyLog.txt
SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\BedMap.sql -o C:\Logs\NightlyLog.txt
SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\Community.sql -o C:\Logs\NightlyLog.txt
...ETC,etc..

This works! except I can't get it to log the output. It will log the output but only if there is just one line in the cmd file.

I was thinking the logging might work if I can loop through the SQL script names one line at a time instead of having them all in one cmd file.

Can anyone help me figure out how to loop through the SQL scripts? Here is a sample of the batch file I've created. That will build the DB but won't log if ther eis an error.

@echo off
REM
REM Create the command file with the names of all the SQl scripts
REM


dir C:\Vault\Dev\DW\Database\Schema /b >C:\Nightlybuild\Loggingtest\myfile.cmd


REM
REM Add the SQLCMD to the beginning of each line
REM



for /F "delims=" %%j in (myfile.cmd) do echo.SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\%%j -o C:\Logs\NightlyLog.txt >> BuildSchema.cmd


REM
REM Delete the myfile.cmd
REM

DEL C:\Nightlybuild\Loggingtest\myfile.cmd


@exit
Code: [Select]@echo off
echo. > BuildSchema.txt
for /F "delims=" %%j in (myfile2.txt) do (
echo %%j
)
echo.
for /F "delims=" %%j in (myfile2.txt) do (

echo."SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\%%j -o C:\Logs\NightlyLog.txt" >> BuildSchema.txt
)
type BuildSchema.txt


Out:

C:>loophow.bat
ADR.sql
ADTC.sql
BedMap.sql
Community.sql


"SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\ADR.sql -o C:\Logs\NightlyLog.txt"
"SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\ADTC.sql -o C:\Logs\NightlyLog.txt"
"SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\BedMap.sql -o C:\Logs\NightlyLog.txt"
"SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\Community.sql -o C:\Logs\NightlyLog.txt"

C:>Code: [Select]@echo off
>BuildSchema.cmd set /p =SQLCMD -d DBName <nul
for /f "delims=" %%j in ('dir /b C:\Vault\Dev\DW\Database\Schema\*.sql') do (
>>BuildSchema.cmd set /p =-i C:\Vault\Dev\DW\Database\Schema\%%j <nul
)
>>BuildSchema.cmd echo -o C:\Logs\NightlyLog.txtThanks CN-DOS and DanCollins for the RESPONSE. CN-DOS I used yours it worked great!
There was one down fall. There are some 500+ tables to create and the script was well over 256 characters to make the tables so it fails. I'll have to look for a way to cut it upI notice in your first post that all the sqlcmd executions output to the same log file. How does that work? Does each new log OVERWRITE or append to the existing log?

This is just a thought, but make each log name unique. You can always concatenate the logs into a single file later.

Try writing the for loop as:

Code: [Select]for /F "delims=" %%j in (myfile.cmd) do (
set/a count+=1
echo.SQLCMD -d DBName -i C:\Vault\Dev\DW\Database\Schema\%%j -o C:\Logs\NightlyLog!count!.txt >> BuildSchema.cmd
)

Be sure to insert setlocal enabledelayedexpansion as the second line in your batch file (directly after @echo off)

Who knows, it might actually work.

8807.

Solve : Batch for create a copy of the original file from a shortcut file.?

Answer»

Batch for create a copy of the original file from a shortcut file.

A Shortcut is a pointer to the original file.

I would like a batch for select the shortcut file to transform in a copy of the original file.

Best Regards
Just curious as to why not use the full path with a regular copy or xcopy statement? Which shortcut would be dynamic in which you would want to use a shortcut with an UNKNOWN path, but a preset name?What I am trying is :

I have a shortcut file pointing to his original file.
A Shortcut is a pointer to the original file.

I would like to make a copy of the original file in the folder where the shorcut is, and then delete optionally the shortcut.

Where can I find this script ?Quote

I have a shortcut file pointing to his original file

If its not YOUR file then you are doing this over a network? With a shared path to HIS file which just happens to be a shortcut?

Guessing this is a remote system on a network SINCE if you just wanted to make an exact copy of a file you could do it through windows locally. Also guessing that this is not a one time copy since you could simply double-click on the shortcut to navigate to the file and get a copy that way if it was a 1 time copy.

If you right-click your shortcut you can select properties, and then view the target path. Then select that target path and use that target path in a batch file such as

xcopy shortcut_target_path\file_you_want.* c:\drop_file_here\*.* /s/d/y

Replace shortcut_target_path with the target path that you got from your shortcut. If there are any spaces in the path you will need to BIND it with " ". Also if you are using Windows Vista or 7, you will want to use robocopy instead of xcopy with different switches.

Trying to push a shortcut.lnk into a batch is just going to be nothing but trouble. If you declare the UNC path directly, you will be better off. http://www.uwplatt.edu/oit/terms/uncpath.html

If you run into a UNC path issue, you can always create a mapped drive to the folder location where that file resides such as X: Then use xcopy x:\file_you_want.* c:\drop_file_here\*.* /s/d/y or the robocopy equivilant if Vista or 7 at your end. And you have to bind the origin target path with " " if there are spaces.It's done Dave. In autohotkey.
I hope the next time will be more simple.
Really I am afraid.

Best Regards
8808.

Solve : Batch command help?

Answer»

Hello gurus!

I would like to ask your help on my problem.
I have an application that is residing on my c:\program files\my application\app-cmd
I need to run this, using command line and need to add some syntax before it runs. my syntax if im doing it manually, I will run this in command line c:\program files\my application\app-cmd -a -b -c seriousman.xml

I need to do this every hour in an XP machine.

I would really appreciate your help on this.
Thank you in advance and more power!

If you having Task Scheduler SERVICE enabled in your system, try this one:

Code: [Select]schtasks /create /RU %username% /sc HOURLY /mo 1 /tn MyTest /tr "cmd /c c:\program files\my application\app-cmd -a -b -c seriousman.xml"Thank you.

But I'm receiving this error...

ERROR: No mapping between account names and security IDs was done.

anything wrong in my ENVIRONMENT?

How about this one?
Code: [Select]schtasks /create /ru System /sc hourly /mo 1 /tn MyTest /tr "cmd /c c:\program files\my application\app-cmd -a -b -c seriousman.xml"

8809.

Solve : Are there any such CMD commands to reset BIOS??

Answer»

Are there any such CMD COMMANDS to reset the BIOS BACK to default settings including CHANGING the USB Legacy from disabled to enabled, or do I need MS-DOS? Does the CMD even have full control over the BIOS without a PS/2 keyboard?Back to default can be usually done by jumper setting on main board or removing the cmos battery and then replacing teh cmos battery after a few minutes for the cmos to lose its settings and default to default. Some bios's also have a feature to select to set all settings back to default.

Only interaction with bios from command prompt would require addressing it with another program such as a flash utility etc. Some are BOOTABLE floppy utilities which are not really dos and others can be run from DOS or Windows environment.I can't reset it in the BIOS because I disabled USB which means I need a PS/2 keyboard.

What bootable DOS tools are you referring to that can reset it?I'd go with the method of removing cmos battery. Its about the size of a quarter in a desktop computer. Do this with power cable unplugged in case battery pops out and lands on chip legs etc. Then wait a few minutes and then insert the battery back in the correct way. Then reconnect power cable andyou should be back to default.

This will set it back to default.

Some systems have a jumper to use or push button to reset, but if you go messing with jumpers you could mess stuff up badly, so battery removal and reinsertion is PROBABLY safest method for you.
Yes there are.
http://www.wikihow.com/Reset-Your-BIOS


the CMD debug part has worked for me.Code: [Select]@echo off
set dbgFile=%temp%\dbgTmp.txt
>"%dbgFile%" echo o 70 10
>>"%dbgFile%" echo o 71 01
>>"%dbgFile%" echo q
debug<"%dbgFile%"

8810.

Solve : run 2nd and 3rd bat file 5 min after running 1st bat file?

Answer»

Hi

I have four bat file (Win XP cmd)

1. Del
2. FBHI
3. HFI
4. min5ha

Problem 1:
del run automatically each morning as I log in. I combined them into one, when I run it run [del] then [FBHI] then closed. Do not run other two.

Problem 2:
#2, 3, 4 takes about 25min each to create 168maps as jpeg, where I do not want to wait to finish [FBHI] then run 3 and 4. HOWEVER I would like to wait for 5 min after [FBHI] started and then run other two.

Is there any way to do it in Win XP cmd.

Thanks if you have any solve for this.

saahmadbulbl
maybe you can add a TIMEOUT, if it exist on xp.How?add
timeout 300
call 2ndprogrem.battime out dosent exist in xp so use the ping trick
ping localhost -n 301 >nuLQuote from: SATexas on April 17, 2011, 05:13:56 PM

C:\test>type mainbat.bat
@echo off

call delbat.bat
echo return from delbat.bat
call FBHI.bat
echo return from FBHI.bat
echo Use sleep command for delays
rem sleep 300
sleep 25
call HFI.bat
echo return to main from HFI
call min5ha.bat
echo return to main from min5ha.bat

echo The End
echo BYE


Dear SATexas
Thank you very MUCH for your help. I modified your codes to the followings but it seems like it is not working.

After running FBHI for 1700 second the program closed itself and did not started HFI.bat or min5ha.bat or VI.bat. Did I missed anything in the code?

I don't mind if they (HFI, min5ha and VI) START one after one after 60 second in different command window.

Thank you very much

***********.
@echo off

call del.bat
echo return from delbat.bat
call FBHI.bat
echo return from FBHI.bat
echo Use sleep command for delays
rem sleep 60
sleep 25
call HFI.bat
echo return to main from HFI
call min5ha.bat
echo return to main from min5ha.bat
call VI.bat
echo return to main from VI.bat
echo The End
echo BYE
*********Still not working !!
8811.

Solve : Copy files to ddmmyyyy folder?

Answer»

Hi
want to copy 3 Folders with 168 jpeg files each

C:\Firemod\temp

to

B:\Projects\Fire Behaviour Outputs\Hourly output\ddmmyyyy

where this folder has created using the following codes

** codes**
=======================================================
@echo off
echo D = Now : WScript.Echo Right(100+Month(D),2) _ >%temp%\today.vbs
echo ^& Right(100+Day(D),2) ^& Right(Year(D),4) >>%temp%\today.vbs

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %temp%\today.vbs') do set today=%%a

del %temp%\today.vbs

echo Hi

echo saahmadbulbul, Todays date is : %today%
md %today%

echo Created a folder for you; it is in B:\Projects\Fire Behaviour Outputs\Hourly output as todays date

=======================================================

each day file name will change and I need to copy those files as a regular basis.

I do not have programming skill to write complex code. Does anyone knows how to do it in winXP cmd?


Thanks a lot if you can solve this problem.


saahmadbulbul

I also was trying to create a folder with the name as the CURRENT date. I found an article on this website TITLED "How can I make a batch file rename a file to the date or time?" I used that information to create the folder. Here's what works for me:
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do md B:\Projects\Fire Behaviour Outputs\Hourly output %%g-%%e-%%f
I used the path you had in your post in the string above. This will create a folder with the name YYYY-MM-DD (example 2011-03-28). In the original article I read they had the date as MM-DD-YYYY, but I prefer the year-month-day instead because if I have many folders, it's EASIER to sort them chronologically. The tokens for the date are %%e=month, %%f=day, & %%g=year. And if you want to add the day of the week, add %%d.
I created the following "for /f "tokens=1-5 delims=/ " %%d in ("%date%") do md c:\users\bonz\bat\%%d-%%g-%%e-%%f", and the resulting folder name is "Mon-2011-03-28"
Another thing. I noticed you are creating the folder in drive B. If this is a removable disk (floppy), you might want the bat file to check and make sure there is a disk in the drive. Such as if not exist b:\*.* echo THERE IS NO DISK IN DRIVE B.Thank you [BonzCXL] for your help
But fixed date time now the code is

========================

cd B:\Projects\Fire Behaviour Outputs\Hourly output
B:

@echo off
echo D = Now : WScript.Echo Right(Year(D),4) _ >%temp%\today.vbs
echo ^& Right(100+Month(D),2) ^& Right(100+Day(D),2) >>%temp%\today.vbs
/f "tokens=1" %%a in (
'cscript.exe //Nologo %temp%\today.vbs') do set today=%%a

del %temp%\today.vbs

echo Hi

echo saahmadbulbul, Todays date is : %today%
md %today%

echo A folder has created for you; it is in ** B:\Projects\Fire Behaviour Outputs\Hourly output as todays date

==========================



but my main problem is to copy files to that folder. not it is yyyymmyy format


Thanks if you have any help ?Thanks [donlong88] for helping me with the codes.

Now i created 2 bat files to copy the files to two different network drives B: and R:

I would like to know I can combine those two bat files into one. I wrote

@echo off
copy2B.bat
copy2R.bat

but did not work.


Thanks

Here are the codes for copy2B.bat and copy2R.bat
****************************************

copy2B
======
@echo off
CD\
cd B:\projects\Fire Behaviour Outputs\Hourly Output\%today%\HFI\
B:

rem want to copy 4 Folders with 168 jpeg files each

rem C:\Firemod\temp

rem to

rem "B:\projects\Fire Behaviour Outputs\Hourly Output\%today%"

rem where this folder has created using the following codes


echo D = Now : WScript.Echo Right(Year(D),4) _ >%temp%\today.vbs
echo ^& Right(100+Month(D),2) ^& Right(100+Day(D),2) >>%temp%\today.vbs
type %temp%\today.vbs
pause

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %temp%\today.vbs') do set today=%%a


rem del %temp%\today.vbs

echo Hi

echo Firemode user, Todays date is : %today%
pause
cd "B:\projects\Fire Behaviour Outputs\Hourly Output\"
md %today%
md %today%\FBHI
md %today%\HFI
md %today%\min5ha
md %today%\VI

cd %today%\FBHI
dir
copy C:\Firemod\temp\FBHI\*.jpg "B:\projects\Fire Behaviour Outputs\Hourly Output\%today%\FBHI\"

echo FBHI copied to B:\Fire Behaviour Outputs ...

cd %today%\HFI
dir
copy C:\Firemod\temp\HFI\*.jpg "B:\projects\Fire Behaviour Outputs\Hourly Output\%today%\HFI\"

echo HFI copied to B:\Fire Behaviour Outputs ...

cd %today%\MinutesTo5Ha
dir
copy C:\Firemod\temp\MinutesTo5Ha\*.jpg "B:\projects\Fire Behaviour Outputs\Hourly Output\%today%\min5ha\"

echo min5ha copied to B:\Fire Behaviour Outputs ...

cd %today%\VI
dir
copy C:\Firemod\temp\VI\*.jpg "B:\projects\Fire Behaviour Outputs\Hourly Output\%today%\VI\"

echo VI copied to B:\Fire Behaviour Outputs ...


rem echo Created a folder for you; it is "B:\projects\Fire Behaviour Outputs\Hourly Output\"

rem each day file name will change and I need to copy those files regular basis.

Cd\
C:


copy2R
======


@echo off
CD\
cd "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing"
R:

rem want to copy 3 Folders with 168 jpeg files each

rem C:\Firemod\temp

rem to

rem "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\%today%"

rem where this folder has created using the following codes


echo D = Now : WScript.Echo Right(Year(D),4) _ >%temp%\today.vbs
echo ^& Right(100+Month(D),2) ^& Right(100+Day(D),2) >>%temp%\today.vbs
type %temp%\today.vbs
pause

for /f "tokens=1" %%a in (
'cscript.exe //Nologo %temp%\today.vbs') do set today=%%a


rem del %temp%\today.vbs

echo Hi

echo Firemode user, Todays date is : %today%
pause
cd "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\"
md %today%
md %today%\FBHI
md %today%\HFI
md %today%\VI

cd %today%\FBHI
dir
copy C:\Firemod\temp\FBHI\*.jpg "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\%today%\FBHI\"

echo FBHI copied to R:\Fire Behaviour Briefing

cd %today%\HFI
dir
copy C:\Firemod\temp\HFI\*.jpg "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\%today%\HFI\"

echo HFI copied to R:\Fire Behaviour Briefing

cd %today%\VI
dir
copy C:\Firemod\temp\VI\*.jpg "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\%today%\VI\"

echo VI copied to R:\Fire Behaviour Briefing


rem echo Created a folder for you; it is "R:\50-SCC\05-StatePlanningSection\FireBehaviour\Fire Behaviour 2010_2011\SCC\Products\Fire Behaviour Briefing\"

rem each day file name will change and I need to copy those files regular basis.

Cd\
C:


Done . Thanks every one.

8812.

Solve : set time in batch + 10sec more!?

Answer»

hi
i want to set my time in "AT" command with +10sec more, something like that;

example:
system time=01:24
my time in batch set to=01:34

example:

at [system time + 10 sec] /interactive notepad.exe

i hope you understanding my question

SORRY FOR MY BAD ENGLISH Changing your system time is easy, but adding 10 seconds? Trying to figure out why you need to add 10 seconds from current system time. Do you want files to have date/time stamp 10 seconds in the future to what the current system time really is? Are you looking for a 10 second delay in which sleep or a bunch of pings to 127.0.0.1 can be used?i don't want 10 second delay!
i want set current time + adding 10 second more to my batch file, like:

default command:
AT [\\computername] time [/INTERACTIVE] "command"

i want:

at [system_time+10sec_more] /interactive cmd.exeQuote from: behzad-007 on AUGUST 08, 2011, 04:32:48 AM

i want set current time + adding 10 second more to my batch file, like:

Like Dave asked, why are you doing it that way, and not using a simple 10 second delay?
Quote from: Salmon Trout on August 09, 2011, 11:56:56 PM
Like Dave asked, why are you doing it that way, and not using a simple 10 second delay?

because in "AT" command you must set time, you can't use delay! But you want it to happen in 10 seconds time. So why use AT?
Quote from: behzad-007 on August 08, 2011, 04:32:48 AM
i don't want 10 second delay!
i want set current time + adding 10 second more to my batch file, like:

default command:
AT [\\computername] time [/INTERACTIVE] "command"

i want:

at [system_time+10sec_more] /interactive cmd.exe

It doesn't make sense. Why do you need the scheduler and not use a time delay as suggested? Does the AT command even support seconds? The system scheduler (GUI) does not.

Batch code does not really do date/time computes very well. All data is seen as a string, so even though you can do integer arithmetic, you run into that pesky problem of the seconds possibly carrying over to the next minute which in turn can carry over into the next hour and so forth. Pretty soon it's next year and then where are you?

VBScript can handle the date/time arithmetic and there is a CLASS for the AT scheduler.



You could always count one Mississippi, two Mississippi etc. When you get to ten Mississippi launch the missiles command. If you use military cadence, you can improve the ten second precision.Quote from: behzad-007
hi
example:
system time=01:24
my time in batch set to=01:34

Judging by this, I am not convinced he knows the difference between seconds and minutes.
Hi Sidewinder,

I agree with you. Both AT and SCHTASKS don't support seconds at all.

Yes, it's difficult to calculate data/time in batch code, especially we need consider the next hour/month/year and leap-year. But we can use Epoch. You may want to have a look at the fuctions of Ritchie Lawrence.

http://www.commandline.co.uk/lib/treeview/index.php
8813.

Solve : Batch to move files by date?

Answer»

Hi. I need some help as I don't understand how this could be done.

I want to create a batch file that I would move into my startup directory and would execute each time I log on. I am using windows 7.

I have a video collection that is ever expanding and I want to organize the collection by date create a backup on a seperate drive. Basically it is set up like this:

1. A video gets downloaded and placed into F:\Videos
2. I need it to remain in this folder for 3 months after it was downloaded or I guess I would say MODIFIED.
3. After 3 Months from the last time it was modified to the current date set the computer it would place the video in the folder F:\Videos\3+Months
4. After it finishes that loop and moves the applicable videos over I want it to check F:\Videos\3Months for any videos older than a year from the current date.
5. If it finds videos over a year since they where last modified it would move them to F:\Videos\1+Years

6. Then, with possibly a seperate batch file, I need it to copy and make the same changes to a backup drive, I:\, with the same folder structures. However not just the videos but the whole F:\ drive with all its other files included. The problem I have with this is that if a video or any other file gets moved into another directory in F:\ it will cause two of the same files on I:\. How would it be possible to mirror the drive without copying all the data over again each time?Only method I can think of is very inefficient and large in routine size. Basically EVERYTIME the startup batch is triggered it passes a current days contents into the next day, making the current day folder clean, BUT you would have to have it execute in a manner from oldest to newest to shuffle everything down without passing yesterdays content into 2 days ago folder and merging content.

You would have 30 folders for your files downloaded within the last 30 days, then 90 folders for the last 90 days, and then a greater than 90 days folder that would be the final pool of all old files. The data from folder_30 would be passed into the Folder_31 which can be a sub-folder under 90_Days and continue on its shuffle every day until it makes its way to a final dump location in which you can seal the contents into folders with dated folder names to avoid overwriting of same filenames.

Biggest problem would be that it would TAKE a long time to execute the more files you have and the larger the size. I have used a similar system for a 7-day rolling backup where on the 8th day, the information overwrites the 1st days folder contents. Never made anything this large dealing with many large files to know how slow it will run.

To keep newer worked on projects seperate from older projects to solve the need for keeping newer altered or modified projects towards the front of this large shuffle, you simply copy say Folder_2's content to Folder_1 and so you have the original old file in Folder_2 and now you have the revised copy in Folder_1. Now tomorrow or next time you logon and the startup triggers your batch it will shuffle all files 1 folder down the line in reverse order to avoid merging projects.

Moving this much content is going to give your hard drive quite a workout, so you will definately want to run daily backups to say an external drive in case you work it to its death shuffling great amounts of data daily. Hard Drives are pretty rugged, but they can wear out under EXTREME conditions!

8814.

Solve : WINRAR command line?

Answer»

How can i delete *.rar after i extracted files from it in cmd?"C:\Program Files\WinRAR\rar.exe" e D:\test\1.rar D:\test\archive\'

need switch or attribute to delete 1.rar in this lineHave you looked in the WinRar help?
There is no command line switch to delete the archive after extraction, but you can open the WinRAR extract dialog and in both GENERAL and Advanced tabs, set any options you wish and click "save options". After that if you USE WinRAR from the command line it will obey these OPTION settings.



Quote from: CIMI on May 03, 2011, 09:09:04 AM

How can i delete *.rar after i extracted files from it in cmd?
thats how
8815.

Solve : Rename files?

Answer»

An application is creating ASCII files.
Each file begins with 2011 EN the following 4 CARACTERS are variable.
I'm LOOKING for a DOS-command which can RENAME this file 2011**** into mytext_8_2011****.
I tried the copy and rename command, but it doesn't work.

For EXAMPLE : 20110807 --> mytext_8_20110807

If I do

Rename 2011*.* mytext_8_2011*.*

the result is : mytext_8_2011 and not mytext_8_20110807

The same result for COPY 2011*.* mytext_8_2011*.*


for /f "delims=" %%A in ('dir /b /a-d 2011*.*') do ren "%%A" "mytext_8_%%A"

Thank you !Code: [Select]@echo off
for %%a in (2011*.*) do (
ren "%%a" "mytext_8_%%a"
)

8816.

Solve : Winrar help?

Answer»

Hi,

I am Using Windows Xp, i trying to CREATE a new batch file which will do, compress a text file and delete after archive.
my existing batch file content is below

set path="C:\Program Files (x86)\WinRAR\";%path%
rar a -df -ep -mt2 C:\Test20110503.rar C:\Griddatafortheperiod20110503.txt
pause

I need archive file name as like the source file name(Griddatafortheperiod20110503.txt)
Current Archive file name is Test20110503.rar. please tell me how to create a archive file name as like source file name?

Thank you

ShanQuote

I need archive file name as like the source file name(Griddatafortheperiod20110503.txt)

This should LET you specify the name for both. Is this what you need?

Code: [Select]set path="C:\Program Files (x86)\WinRAR\";%path%
set /p textfile=Type the name of the file:
rar a -df -ep -mt2 C:\%textfile%.rar C:\%textfile%.txt
pause
I READ your question again, and I think I might have MISINTERPRETED your question. Do you want the batch to scan the folder for all text files and compress each one into a .rar file?Hi Linux711,

Thanks for your immediate reply... i TRIED your code its working fine for me and i got the result as i needed. thanks...

Shan
8817.

Solve : Help with bat file?

Answer»

This is my FIRST attempt to make a bat file. I'm using Windows XP and I've tried using cmd to get to the files but it keeps stopping at C:\Documents and Settings\MrPiggss\Desktop instead of going into the My Documents folder.

Basically I need to be able to delete all files within:

C:\Documents and Settings\MrPiggss\My documents\Battlefield Play4Free\WebCache

and all file and folders with:

C:\Documents and Settings\MrPiggss\My Documents\Battlefield Play4Free\mods\main

Can someone help me out with this?Why not use windows to delete the directory through my computer and or windows exployer (windows key + E)

Then select the directories you wish to delete and press the delete key?Quote from: MrPiggss on August 13, 2011, 02:29:52 PM

This is my first attempt to make a bat file. I'm using Windows XP and I've tried using cmd to get to the files but it keeps stopping at C:\Documents and Settings\MrPiggss\Desktop instead of going into the My Documents folder.

Basically I need to be able to delete all files within:

C:\Documents and Settings\MrPiggss\My documents\Battlefield Play4Free\WebCache

and all file and folders with:

C:\Documents and Settings\MrPiggss\My Documents\Battlefield Play4Free\mods\main

Can someone help me out with this?
cd WebCache

del /F *.*
cd ..
rd WebCache

@Rustys the reason I'd like a bat is because I have to clear these 2 folders every time to play a game. If I don't the game crashes. Rather than manually going through my computer yada yada yada... if I had a bat I COULD just double click it would be easier.

@DanCollins
do I need to specify the full location i.e. C:\Documents and Settings\MrPiggss\My documents\Battlefield Play4Free\WebCache or just do it as you have shown?Quote from: MrPiggss on August 13, 2011, 10:21:30 PM
DanCollins
do I need to specify the full location i.e. C:\Documents and Settings\MrPiggss\My documents\Battlefield Play4Free\WebCache or just do it as you have shown?

Code: [Select]@echo off
cd "C:\Documents and Settings\MrPiggss\My documents\Battlefield Play4Free\WebCache"

del /F *.*
cd ..
rd WebCache

cd "c:\Documents and Settings\MrPiggss\My Documents\Battlefield Play4Free\mods\main\"

del /F *.*
cd ..
rd main
The above code must be saved to a batch file, deleterm.bat. The batch file can then be executed from the COMMAND line.
(Or point to the batch file and double click.)

C:\test>deleterm.bat

p.s. Be careful when using *.* with delete. Make sure you have the correct files.
You may NAME the batch file any name you please: myfile.bat
"path" "" is necessary when there is OPEN space inside the path.
8818.

Solve : Check if file exists?

Answer»

Hi All,
I need to create a daily log file that runs down a list of files and checks to be sure that todays files are there. Each day the name of the file changes with a new date stamp added. So far I found a script to create a log file by date and I was able to get the check of a file but I can't get the date in the file name to work.

Here is what I have.....



::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create a log file containing todays date
::LogPath is the path to the folder where the log file will be saved
::LogFileName is a descriptive name that will be added after the date
::LogFileExt is the extension to be used
::First get the date into a variable. Then convert the '/' to '-' so
::the '/' won't be mistaken as a command line switch
::if the file exists, a blank line and a separator line of equal SIGNS
::will be written at the END of the file in CASE the script runs more than
::once a day.
::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal
set LogPath=C:\Scripts\
set LogFileExt=.log
set LogFileName=Daily BACKUP%LogFileExt%
::use set MyLogFile=%date:~4% instead to remove the day of the week
set MyLogFile=%date%
set MyLogFile=%MyLogFile:/=-%
set MyLogFile=%LogPath%%MyLogFile%_%LogFileName%
::Note that the quotes are REQUIRED around %MyLogFIle% in case it contains a space
If NOT Exist "%MyLogFile%" goto:noseparator
Echo.>>"%MyLogFile%"
Echo.===================>>"%MyLogFile%"
:noseparator
echo.%Date% >>"%MyLogFile%"
echo.%TIME% >>"%MyLogFile%"
:startbatch
::
@echo off
rem check to see if a file exists
if exist "\\peanuts\Applications\FTP\Archive\ABC.XYZEFT2011050420110504*" goto fileexists

goto nofile

:fileexists
echo The file ABC.XYZEFT2011050420110504* exists ya all! >>"%MyLogFile%"
rem other commands here .....
goto end



:nofile
echo the file %1 does not exist
goto end
:end

pause
=========================================

Like I said if I type out the name of the file it writes a line in the log. What I have is about 10 files in 10 places all with date stamps in the name. I am trying to figure out how to run a batch file and then open the log each day to see if any are missing.

Thanks for any help



I figured it out......


Thanks

8819.

Solve : dos/windows?

Answer»

please can SOMEONE TELL me the difference between dos and windowsYes, if by "someone" you mean "Google" - or my current favourite search ENGINE, Duck Duck Go: http://duckduckgo.com/?q=difference+between+DOS+WindowsPimp that novel!

The OP may be "one to watch"...

1. DOS



2. Windows

Quote from: Salmon Trout on August 13, 2011, 04:00:55 AM

Pimp that novel!

Just about to.
8820.

Solve : Batch file help?

Answer»

Depending on which of two physical external hard drives I connect to the same USB port on my computer that drive shows up on My Computer as either Drive F: or Drive H:.

I have composed a BATCH file that copies certain FILES to the "F: drive". However if the "H: drive" happens to be CONNECTED at the TIME, the copy process fails because the batch file is looking for the F: drive. But... I don't really care which physical drive (F: or H:) is being copied to.

I need to modify the batch file to go ahead and copy to the H drive if that one happens to be installed instead of the F drive. In pseudo code that might look like:

Is the drive connected to the USB port the F: drive ?
Go ahead and copy the specified files
Is the drive connected to the USB port the H: drive ?
Go ahead and copy the specified files


In other words, copy the specified files to the drive connected to the USB port no matter what drive letter the OS sees.

Using XP home with SP3


Thanks for your assistance.I always thought removable drive letters were assigned sequentially, so I'm not understanding why you get two different assignments. Be that as it may, you can check which drive is mounted and proceed from there:

Code: [Select]@echo off
setlocal

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| findstr /c:" F " /c:" H "') do (
xcopy <put xcopy parameters here> && goto :eof
)

Replace <put xcopy parameters here> with actual arguments. The drive letter is in the %%i variable. Leave the && goto :eof as written.

Example: xcopy c:\windows\inf %%i:\backup /s /e && goto :eof

Good luck.

PS. This snippet is specific to your request. VBScript or Powershell might be a better choice to create a generic script.

8821.

Solve : Add single comma in place of any number of spaces?

Answer»

Looking for a way to add a (SINGLE comma) in between data like below to force non comma delimited data to become comma delimited...any suggestions on how I can do this for a text document with the raw data like below in a batch ( or vb script ) so that I dont have to run this manual notepad replace 3 step process for daily data?

Deathstarr Rank 4 80 0 0
Dianniah Rank 4 80 0 0
Minnieknight Rank 4 80 0 0
Mortimur Rank 4 80 0 0
Shamadar Rank 4 80 0 0
Starrgantis Rank 4 80 0 0
Starrgazer Rank 4 80 0 0

Trying to get away from this Manual NOTEPAD " Find All Replace " Process:
(1.) Replacing ALL the (spaces) with ( , )
--- > and then in two locations I get (,,,,,,) and (,,)
(2.) I then need to replace ( ,,,,,, ) with ( , )
(3.) Then finally replace ( ,, ) with ( , )
---> So that all data is single comma delimited.

In the end I want clean comma delimited like below:

Deathstarr,Rank,4,80,0,
Dianniah,Rank,4,80,0,0,
Minnieknight,Rank,4,80,0,0,
Mortimur,Rank,4,80,0,0,
Shamadar,Rank,4,80,0,0,
Starrgantis,Rank,4,80,0,0,
Starrgazer,Rank,4,80,0,0,

Any suggestions or solutions to automate this space replacement and make it a nice comma delimited file?

If you use space(s) as the token delimiter, you can write out each line as a set of tokens with commas in between. One or more spaces will be replaced by 1 comma. I am curious why you want a trailing comma? I have included one after %%F as you can see, but I wonder why you need it.

e.g (assuming 6 tokens on each line)


Code: [Select]
if exist output.csv del output.csv
for /f "tokens=1-6 delims= " %%A in ('type input.txt') do (
echo %%A,%%B,%%C,%%D,%%E,%%F,>>output.csv
)

I started this before Dias's post, and yet notice my keen observation in the comments.... sort of, I was right about "being able to do it better" anyway... (that is, "other peeps")


Also, it removes all trailing spaces... don't think that was what you wanted...

Code: [Select]
Dim InName,OutName
Dim FSO
set FSO = CreateObject("Scripting.FileSystemObject")
if wscript.arguments.count < 2 then
wscript.echo "Spc2Comma <InputFile> <OutputFile>"
end if
InName = wscript.arguments(0)
Outname = wscript.arguments(1)

Dim InFile,OutStream
Dim InStream
Dim ReadStr
'Set InFile = FSO.GetFile(InName)

set InStream=FSO.OpenTextFile(InName,1)
Set OutStream=FSO.CreateTextFile(Outname,-1)

ReadStr = InStream.ReadAll()
ReadStr = Replace(ReadStr," ", ",")
Do Until Instr(readStr,",,") = 0
'replace two comma's with one...
ReadStr = Replace(readstr,",,",",")

Loop
Do Until Instr(readstr," ") = 0
'replace two spaces with one...
readstr = replace(readstr, " "," ")
loop


'last replace a comma and crlf combination with just a crlf...
readstr = replace(readstr,"," + Chr(13) + Chr(10) + ",",chr(13) + chr(10))
'lastly, cut off last char if it is a comma.
'this is a terrible kludge and I'm sure more vbscript able peeps could do this better...
if right(readstr,1) = "," then
wscript.echo "*censored*"
readstr = mid(readstr,1,len(readstr)-3)
end if
outStream.Write ReadStr

outstream.close
InStream.Close

Except that mine will do the grunt work in one line

Code: [Select]@echo off
set /p infile=File to process ?
set /p otfile=Output file name ?
if exist "%otfile%" del "%otfile%"
for /f "tokens=1-6 delims= " %%A in ( ' type "%infile%" ' ) do echo %%A,%%B,%%C,%%D,%%E,%%F,>>"%otfile%"
Thanks Dias & BC

And regarding the trailing comma .... this was caused by notepads replace of spaces and finding a single space in the datas formatting after the last piece of data on each line. It is not required, but also doesnt scue the output for my application.

Thanks for solving this for me so I can avoid the 3 step manual replace process, and I have saved a copy of this so that in the future I can look back and tweak it for other replacement uses.

Many thanks to both of you in your efforts! How can I do the same thing with my data set? First row is my column headings

I've been struggling with this for hours.... Any help would be greatly appreciated. Thanks in ADVANCE.

samid upn fn ln display canchpwd pwdneverexpires disabled
134-2 [emailprotected] Mike Smith 927 Mike Smith 927 yes no no Quote from: ry8200 on August 04, 2011, 01:23:26 PM

How can I do the same thing with my data set? First row is my column headings

I've been struggling with this for hours.... Any help would be greatly appreciated. Thanks in advance.

samid upn fn ln display canchpwd pwdneverexpires disabled
134-2 [emailprotected] Mike Smith 927 Mike Smith 927 yes no no

comma
« Sent to: ry8200 on: Today at 06:03:57 PM » | Reply | Quote | Delete |

Code: [Select]@echo off & setLocal EnableDELAYedeXpansion
del otfile.txt > nul
for /f "delims=" %%i in (infile.txt) do (
call :sub %%i
)
echo.
type otfile.txt
goto :eof

:sub

echo %*

:loop


echo/|set /p ="%1," >> otfile.txt

shift

if "%1"=="" (
goto :end
)
goto :loop
:end
echo. >> otfile.txt




Output:

c:\test>comma2.bat
134-2 [emailprotected] MikeSmith 927 yes no
134-2 [emailprotected] MikeSmith 927 yes no
134-2 [emailprotected] MikeSmith 927 yes no
134-2 [emailprotected] JoeLong 927 yes no no yes

134-2,[emailprotected],MikeSmith,927,yes,no,
134-2,[emailprotected],MikeSmith,927,yes,no,
134-2,[emailprotected],MikeSmith,927,yes,no,
134-2,[emailprotected],JoeLong,927,yes,no,no,yes,

c:\test>

ref:

http://stackoverflow.com/questions/4479734/echo-with-no-new-line-cr-lf

That kind of work can be done by a spreadsheet program.1. This thread has been revived by ry8200 after a gap of over two and a half years. ry8200, if you are genuine, and not Bill's sock puppet, as certain internal evidence suggests, start your own thread. Better still, read this one, where the solution was clearly described by my friend Dias de Verano, in February 2009.

2. Fred35 is, as I suspected ever since he first appeared, Billrich.

Honestly Salmon Trout - Sock puppet??? Are you kidding me... If this is how a new person is treated in this forum, then I'll take my request somewhere else. I am a real person with an issue that falls in line with this post and the previous issue that DaveLembke had; so I thought it would make sense to revive this post.

Anyway, moving on.

The new issue I'm having is two of the fields of data, called "fn" and "display" have spaces in them (for example "Display" = "John Smith D1234567"), that I need to keep, but I want to replace all the other spaces with a comma.

The data pulled from my DSQUERY is:
samid upn fn ln display canchpwd pwdneverexpires disabled
123-2 [emailprotected] John Smith D1234567 John Smith D1234567 yes no no
456-2 [emailprotected] Mike Smith U1234567 Mike Smith U1234567 yes no no

The output would need to look like this:
samid,upn,f,ln,display,canchpwd,pwdneverexpires,disabled
123-2,[emailprotected],John Smith,D1234567,John Smith D1234567,yes,no,no
456-2,[emailprotected],Mike Smith,U1234567,Mike Smith U1234567,yes,no,no Did you read what was said about starting your own thread? You have revived a thread from 2009.
Anyhow,

@echo off
setlocal enabledelayedexpansion
set InputFileName=Input.txt
set OutputFileName=output.csv
set line=1
if exist "%OutputFileName%" del "%OutputFileName%"
for /f "tokens=1-11 delims= " %%A in ('type "%InputFileName%"') do (
if !line! equ 1 (
set output=%%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H
) else (
set output=%%A,%%B,%%C %%D,%%E,%%F %%G %%H,%%I,%%J,%%K
)
echo !output! >> "%OutputFileName%"
set /a line+=1
)
echo Input:
echo.
type "%InputFileName%"
echo.
echo Output:
echo.
type "%OutputFileName%"


Input:

samid upn fn ln display canchpwd pwdneverexpires disabled
123-2 [emailprotected] John Smith D1234567 John Smith D1234567 yes no no
456-2 [emailprotected] Mike Smith U1234567 Mike Smith U1234567 yes no no

Output:

samid,upn,fn,ln,display,canchpwd,pwdneverexpires,disabled
123-2,[emailprotected],John Smith,D1234567,John Smith D1234567,yes,no,no
456-2,[emailprotected],Mike Smith,U1234567,Mike Smith U1234567,yes,no,no

8822.

Solve : show batch output in msg box!?

Answer»

hi
i want to show my final output in massage box, i don't know but something like that,

code:

@echo off
set/P drive="your drive>"
fsutil volume diskfree %drive%

output in massage box, like,
msg * "OUTPUT_OF_fsutil volume diskfree %drive%"

tnxbatch scripting does not have message boxes. VBScript does.
you can simply make your own exe with this functionality using another language. I have a program I could upload that does exactly what you want, but you will have to wait for me to get it from my home computer in a few days bc I am on vacation. If it is mandatory, I can give you some vb or c++ code.With VBScript, you could run the fsutil command, capture the output into a variable and then display a message box. With NT batch, you'd have to capture the output in a file, then push it into the message box:

This won't win any beauty contests, but it might take home the prize for Miss Congeniality:

Code: [Select]@echo off
setlocal

set /p drive=Enter Drive Letter:

for /f "tokens=* delims=" %%i in ('fsutil volume diskfree %drive%:') do (
echo %%i >> text
)

<text msg %username%
del text

At the prompt enter only the drive letter; the batch file will insert the colon.

Good luck. Nicely spotted, Sidewinder, I had forgotten about msg. I played around with it a bit

Code: [Select]@echo off
set /p drive="Enter Drive Letter: "
Echo Statistics for Drive %drive%: > text
for /f "tokens=* delims=" %%i in ('fsutil volume diskfree %drive%:') do echo %%i >> text
<text msg %username%
del text
it is so much cleaner to just write a program in c, copy it to system32, and then call it from batch by just typing MSGBOX [bla bla]Quote from: Linux711 on August 06, 2011, 08:08:00 PM

it is so much cleaner to just write a program in c, copy it to system32, and then call it from batch by just typing msgbox [bla bla]

You can do this already from VBscript
Quote from: Salmon Trout on August 07, 2011, 01:07:01 AM
You can do this already from VBscript

... and you can do a lot more things...

As I shall PROCEED to demonstrate...

Code: [Select]' Make Shell object available
Set Shell = CreateObject("Wscript.Shell")

' Force use of cscript.exe so we can use console input
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
Shell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
WScript.Quit
End If

' Get console input from user
' 1. Write prompt to console, no newline
wscript.stdout.Write "Enter drive letter: "

' 2. Get user input terminated by Enter
UserInput = Wscript.StdIn.ReadLine

' 3. Just get first character in case they type C: or similar
DriveLetter = Mid(UserInput,1,1)

' Start building string to pass to messagebox
' Force drive letter to upper case (just because we can!)
MessageString = "Drive letter is: " & UCase(DriveLetter)

' This is the string we pass to Shell for execution
FsUtilString = "fsutil volume diskfree " & DriveLetter & ":"

' Start FSUtil running
Set oExec = Shell.Exec(FsUtilString)

' While it has not yet finished...
Do While oExec.StdOut.AtEndOfStream <> True

' Get each line in turn from fsutil
FsUtilOutputLine = oExec.StdOut.ReadLine

' Split the line at the colon
SplitLineArray = Split(FsUtilOutputLine,":")

' We have split Array has 2 elements, 0 and 1
' Because there is 1 colon in each line
LineText = SplitLineArray(0)
ByteText = SplitLineArray(1)

' Force the bytes value string into a number
ByteNumb = Eval(ByteText)

' Some HANDY values demonstrated
KiloBytes = ByteNumb / 1024
MegaBytes = ByteNumb / (1024 * 1024)
GigaBytes = ByteNumb / (1024 * 1024 * 1024)

' We'll show GB in brackets after the bytes figure
' We'll reduce the large number of decimal places to just 2
GBFormat = FormatNumber(Gigabytes,2)

' Build up the string for the message box
' Insert a carriage return / line feed after each line (except the last)
' So that they will appear as separate lines in the box
MessageString=MessageString & VBcrlf & LineText & ":" & ByteText & " (" & GBFormat & " GB)"

Loop

' Retval is a dummy value in this case since we are only using 1 Button (OK button)
' Therefore we are not concerned about the return value
Retval = MsgBox(MessageString, vbOKOnly, "Disk Free and Used Space")





thanks for reply

this code is work, but i don't know vbScript language Quote from: behzad-007 on August 07, 2011, 07:13:05 AM
thanks for reply

this code is work, but i don't know vbScript language

Now is the time to start learning! I put lots of comments in there. Or you have batch code above.



You can do it in 5 lines of batch

Code: [Select]@echo off
Set /p drive=Enter Drive Letter:
fsutil volume diskfree %drive%: > text.txt
<text.txt msg %username%
del text.txt
In fact you can do it in 1 line

Code: [Select]@Set /p drive=Enter Drive Letter: & echo Drive %drive%: > text.txt & fsutil volume diskfree %drive%: >> text.txt & <text.txt msg %username% & del text.txttnx so much

5 line batch worked!
but 1 line code is not WORKING in my pc!! Quote from: behzad-007 on August 08, 2011, 03:17:48 AM
but 1 line code is not working in my pc!!
Yes it has an error I will try to fix it
8823.

Solve : Buffer = ? In MS DOS config.sys what is the maximum?

Answer»

I had a PC die on me that was running a Operating System used in CNC programming. I changed the PC and had Win 98 installed which is what was on the other. When trying to transfer files within this DOS DRIVEN software I get a Buffer size exceeded error. In Config.sys, what is the maximum number I could put in this field? Or is it hard coded. Also, is this just a string buffer?

THANKS
Richwhat number do you currently have in your BUFFERS= line? BUFFERS=75 is a common setting. This setting is for file i/o not strings.
Quote from: remullis on March 25, 2010, 07:14:38 PM

I had a PC die on me that was running a Operating System used in CNC programming. I changed the PC and had Win 98 installed which is what was on the other. When trying to transfer files within this DOS driven software I get a Buffer size exceeded error. In Config.sys, what is the maximum number I could put in this field? Or is it hard coded. Also, is this just a string buffer?

Thanks
Rich
0 to 255 the more you add,more memory is used,i have 768mb of memory on one of my computers and i have added 180 buffers and it is faster. Just edit the config.sys file example buffers=180 then save and exit you must restart your computer for this to take effect. and I am running xp pro sp2
This thread is a year old (not that the answer would make any more sense if it wasn't).180 buffers ? ? ?Nothing in config.sys changes the way Windows XP works.

In fact, No version of NT even Looks at config.sys during startup. Any perceived speed increase is only perceived and not actual.Don't spoil his fun....he may spend weeks working on another non-functional speed tweak...Quote from: patio on May 05, 2011, 07:04:59 AM
Don't spoil his fun....he may spend weeks working on another non-functional speed tweak...
Some all around speed "tips":

-If you wear unmatched socks it can increase file access times by over 50%!

-People with fillings should avoid using the mouse, and use keyboard operations where possible. Experiments done on guinea pigs have revealed that this can increase throughput by a factor of 5 compared to a guinea pig sitting on your keyboard.

-If you have a game controller plugged it, put flame stickers on it. It makes everything go faster.

-If you have more then 512MB of memory, this can slow down newer operating systems like Windows Vista, because they deal with memory in something called Blubbors*. a Blubbor takes a long time to transfer, and the more blubbors you have, the longer everything takes. Windows Vista has a minimum requirement of at least 3.51 Blubbors, but has been known to run on machines as low as a half blubbor (also known as a scaligree**). Anyway, the more blubbors the slower t hings go, and the more memory you have, the more blubbors, so if you remove memory things will go faster. No arguing with logic.


*Blubbors do not exist. If you think you are seeing a blubbor, it's a hallucination. Seek medical aid immediately.
**scaligree's were discovered in 1636 by the Algonquin native tribe in North America. It smells like daffodils.Blubbors do exist...
8824.

Solve : Batch file to login to my mail id?

Answer»

Hi All,

I was wondering if it is possible to create a batch file which opens www.yahoomail.com, enters my userid and password and logs into the email account.

Is this possible in DOS? Is it possible for US to send INPUTS to webpage through command line.
Can anybody help in this?
Salman trout, can u pls give ur useful inputs.

Thanks in advance..plz tell me about batch file
Quote

Is this possible in DOS? Is it possible for us to send inputs to webpage through command line.

Not that I'm aware of. You might TRY VBScript which has several WAYS of handling this.

One would be to fire up the browser and send keystrokes to the rendered page. This can be successful, but timing is everything and any misfire can produce unexpected results.

A second way would be to create an instance of the browser where you can script both the browser and the rendered page.

You can use this little snippet as a template which shows off the second method:

Code: [Select]Set IE = CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")

IE.Navigate "http://www.yahoomail.com"
IE.Visible = True

Do
WScript.Sleep 5000
Loop While IE.Busy

IE.Document.All.Item("login").Value = "username" 'Change username as needed
IE.Document.All.Item("passwd").Value = "password" 'Change password as needed

WshShell.SendKeys "{ENTER}"

Good luck.

@Balwinder Singh: START your own thread and please be more specific.

This is probably nothing but I'm tired of chasing shadows around every corner.
8825.

Solve : Abusing the old DOS DEBUG.COM program?

Answer»

Some OLDER articles about DOS and batch programming MENTION the program named DEBUG.COM to write short bits of code to change things.
The now is CONSIDERED an abusive practice. So If you decide to use DEBUG to try an experiment, you may want to read this recent post on ANOTHER site.
(Ab)using DEBUG
Please note the remarks about 32 bit and 64 bit Windows.
Do you agree?I'd see the Icon at the top right of the page you linked to...1. Who says it's an abusive practice?
2. I ALREADY knew 64-bit Windows won't run 16-bit stuff.
3. Why should we have any opinion at all about this?


8826.

Solve : Append file extensions to a number of files?

Answer»

Hey all!

I have a bunch of mp3 files with missing file extensions. What is the best way to append the "mp3" suffix to them?

Example 1
Say you have following files...

Quote

01 Audioslave - Revelations.mp3
02 Blur - Bang.mp3
03 Cake - Jolene.mp3
04 Doves - Pounding.mp3
05 Everlast - Ends.mp3

Now, if you for some reason want to change the suffix from "mp3" to something like, I don't know, maybe aac. You would type something like this in the Windows command line.

Code: [Select]ren *.mp3 *.aac
You hit Enter and you're done.

They should now be listed as...

Quote
01 Audioslave - Revelations.aac
02 Blur - Bang.aac
03 Cake - Jolene.aac
04 Doves - Pounding.aac
05 Everlast - Ends.aac

It's easy when they all have something in common, like the "mp3" suffix in this case. But what if they don't have anything in the name that's common to all files? You won't be able to use any combination of wildcard characters to match the files you want. Am I right?

Example 2
It's easy when they have something in common. Like this...

Quote
01 Blur - Bang
02 Blur - Repetition
03 Blur - Fool
04 Blur - Birthday
05 Blur - Jets

In this case you have "blur" as the common denominator. So you could type something like this...

Code: [Select]ren *blur* *.mp3
That should add the "mp3" suffix to all files containing the word "blur". So you get...

Quote
01 Blur - Bang.mp3
02 Blur - Repetition.mp3
03 Blur - Fool.mp3
04 Blur - Birthday.mp3
05 Blur - Jets.mp3

But what if you don't have a common denominator in all files, like in example 2?

I tried typing this...

Code: [Select]ren 01*;02*;03*;04*;05* *.mp3
But the command line only returned syntax error.

So I tried replacing the semicolon with a plus sign, like this...

Code: [Select]ren 01*+02*+03*+04*+05* *.mp3
Command line just says that the file could not be found.

Inserting spaces before and after the plus sign doesn't help either. It just gives syntax error. So there doesn't seem to be a way to cheat on this. While you may be able to select multiple files using the "file+file" format, you can't use the ASTERISK character at the same time in that same command line.

So I tried...

Code: [Select]ren 01* *.mp3
This works, but you have to repeat it for every file. So it would be like...

Code: [Select]ren 01* *.mp3
ren 02* *.mp3
ren 03* *.mp3
ren 04* *.mp3
ren 05* *.mp3
So, now I'm thinking that one may need to create a batch file. But wait a second... a batch file?... just to perform this simple task? Is that really necessary? Is there no other way around?

You would still need to write the batch file. That consumes time, and while at it you may as well go ahead and add "mp3" to the files manually, one by one, in the Windows Explorer!

So...

Thoughts? Ideas? Let me know!Quote from: Fractalogic on August 07, 2011, 11:14:59 AM
I have a bunch of mp3 files with missing file extensions. What is the best way to append the "mp3" suffix to them?

[...]

You would still need to write the batch file. That consumes time, and while at it you may as well go ahead and add "mp3" to the files manually, one by one, in the Windows Explorer!

You appear to like typing, judging by the length of your post, so maybe you would prefer to rename them all manually using Explorer, but if you are prone to the type of accident that strips files of their extensions, then the time spent writing a batch file, or a command-line one-liner that you can save as a text file and paste to the prompt, will soon be saved. In any case, you will only need to copy and paste the code below, making any alterations needed to fit your particular needs.

Code: [Select]@for /f "delims=" %A in ( ' dir /s /b /a-d "C:\My MP3 Collection\Folder in Question" ' ) do ren "%~dpnxA" "%~nA.mp3"
Note:

1. This is for the prompt.
2. If you want to use it as a batch file change the single percent signs % to double ones %% so that %A becomes %%A and %~dpnxA becomes %%~dpnxA and %~nA becomes %%~nA.
3. It operates on all files in the named folder and all files in any sub folders also. If you don't want subfolders to be affected, delete the /s switch from the DIR command in the brackets.
4. It will add the .mp3 extension to all files that do not have an extension, and it will replace any other extension with .mp3.

Quote from: Salmon Trout on August 07, 2011, 12:01:33 PM
You appear to like typing, judging by the length of your post, so maybe you would prefer to rename them all manually using Explorer, but if you are prone to the type of accident that strips files of their extensions, then the time spent writing a batch file, or a command-line one-liner that you can save as a text file and paste to the prompt, will soon be saved. In any case, you will only need to copy and paste the code below, making any alterations needed to fit your particular needs.

Code: [Select]@for /f "delims=" %A in ( ' dir /s /b /a-d "C:\My MP3 Collection\Folder in Question" ' ) do ren "%~dpnxA" "%~nA.mp3"
Note:

1. This is for the prompt.
2. If you want to use it as a batch file change the single percent signs % to double ones %% so that %A becomes %%A and %~dpnxA becomes %%~dpnxA and %~nA becomes %%~nA.
3. It operates on all files in the named folder and all files in any sub folders also. If you don't want subfolders to be affected, delete the /s switch from the DIR command in the brackets.
4. It will add the .mp3 extension to all files that do not have an extension, and it will replace any other extension with .mp3.

I sure do! That's why I'm still stuck in DOS! Duh!

I would say that my primary objective is to learn how to do things like these. I am very eager to learn as much as possible about computers in general.

I have one question. What book do I need to read to UNDERSTAND the command line you just wrote? No, seriously, what type of books cover these kind of things? Is that even a command? Or is it a script?...

How do you paste a line like that into CMD? As far as I know it's not possible. Enlighten me!Quote from: Fractalogic on August 07, 2011, 12:54:08 PM
How do you paste a line like that into CMD? As far as I know it's not possible. Enlighten me!

Get whatever you want to paste into the clipboard and then in a CMD window:

Left click the icon in the top left corner then select "Edit" from the menu that appears, then finally select "paste"

--- or alternatively ---

If you do not have QuickEdit enabled, you can right click in the window and select "Paste" from the menu that appears.
If you have QuickEdit enabled, just right click and the text will paste itself.

Select QuickEdit mode from the top left hand corner icon menu - Properties - Options - Edit Options.

Quote from: Salmon Trout on August 07, 2011, 01:10:50 PM
Get whatever you want to paste into the clipboard and then in a CMD window:

Left click the icon in the top left corner then select "Edit" from the menu that appears, then finally select "paste"

--- or alternatively ---

If you do not have QuickEdit enabled, you can right click in the window and select "Paste" from the menu that appears.
If you have QuickEdit enabled, just right click and the text will paste itself.

Select QuickEdit mode from the top left hand corner icon menu - Properties - Options - Edit Options.

Wow! Pasting in CMD really works! How about that! Thanks!

QuickEdit needs to be enabled in order to MARK and copy from CMD, right?

I just tried that command line and it worked just as expected. There are no duplicates of the "mp3" suffix, so everything is okay. Except for two PICTURE files, you know the album art kind of thing. But they are still there so I can change them back manually, it's no big deal. You did warn me that this will change the extension for all files in the folder and all sub-folders to "mp3". It was my mistake. I didn't have any sub-folders by the way, so that's just fine.

Now I would really like to know where I can learn more about this?...Quote from: Fractalogic on August 07, 2011, 01:27:40 PM
QuickEdit needs to be enabled in order to mark and copy from CMD, right?

No, it doesn't have to be enabled, it just makes it slightly quicker.

To copy from a CMD window

In each case I am referring to the menu you get when you left click the top left corner icon in the CMD window:

Without QuickEdit enabled:

Select Edit, then select Mark, then using the left mouse button, highlight (mark) the text you want to copy, then EITHER select Edit, then select Copy OR just press ENTER

QuickEdit enabled:

Using the left mouse button, highlight (mark) the text you want to copy, then EITHER select Edit, then select Copy OR just press ENTER

As you can see, QuickEdit cuts out having to go to the window menu first.

Whichever way you do this, the highlighted text reverts to unhighlighted appearance when it gets copied to the clipboard. It can then be pasted in the normal way into other windows, programs, etc.

Quote
Now I would really like to know where I can learn more about this?...

It is hard to know where to suggest - the web is full of batch tutorial websites. I did have a book years ago called "MS-DOS Command Reference" by Microsoft Press but the modern Windows batch language has evolved beyond that -

This is quite a good introductory tutorial, by Ashley J Mills at the University Of Birmingham (England), it's all over the Web in various places

https://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/win32scripting/win32scripting.html

Or Google for Windows CMD Tutorial, batch examples, etc. Be inventive. Take the initiative - when you are developing a script, instead of hitting a forum and asking "How do I add two numbers together?", it is quicker to search Google for "Win32 batch arithmetic" and study the hits you get.

My advice is don't get too tied down with batch - if you find you have a knack for it, (or if you don't!) take a look at Visual Basic Script, (VBscript) and Windows Powershell especially.





Quote from: Salmon Trout on August 07, 2011, 02:01:38 PM
Take the initiative - when you are developing a script, instead of hitting a forum and asking "How do I add two numbers together?", it is quicker to search Google for "Win32 batch arithmetic" and study the hits you get.

I didn't mean to say that you are not perfectly welcome to ASK any questions you like on here and I and others will be very happy to help!
8827.

Solve : convert text 2 binary with batch file!?

Answer»

hi
how can i convert text to BINARY with batch file?

tnxYou can't, probably. What do you mean by "text"? Do you mean you want to convert ASCII codes to binary? Why use batch for that? What are you trying to do?

tnx for reply

yes i want to convert ASCII codes to binary,
i want to know how this work and how can i create batch to convert a ASCII to something else(like text Encrypt/Decrypt).I really think you need to GO away and do a LOT of thinking about what you want to do, and maybe study some programming languages.

Why have you deleted your account with the name "behad-007" and started a new ONE? What's going on? Are you playing games with us? Is that you, Bill?

8828.

Solve : Write DIR listing appending to file from multiple depth sub directories?

Answer»

I am trying to find a way to write to file a list of all directories, sub-directories, and file names that are in those directories and sub directories without having to exclusively direct the DIR command to each physical directory of over 628 sub directories in that main directory. I am guessing there may be a way to make a FOR loop in a batch file when executed from a starting directory write to say a directory outside of that directory the appending file and folder contents without a CRC Error caused by trying to write back to location being used for DIR possibly sort of like the XCOPY CRC issue and using something similar to DIR>>Listing.txt to pass it appending to the Listing.txt file. But I am stumped on how to pass this DIR command to retrieve information for sub folders and its file contents as a wild card I guess you could call it to search and report back all without having to give it exact paths to follow deeper in and for all directories and subdirectories. Anyone have any code suggestions to make this happen?

I remember TREE way back giving info like this but was wondering if DIR can be tweaked to do this without having to grab TREE off of an old dos disk and seeing if it will behave under Windows 7 32bitI don't know if this helps...

Have you ever noticed the /S switch that DIR has?

Example:

I am interested in the folder S:\hyper-pi. Note I am in another (arbitrary) folder on another DRIVE.

1. bare listing

Code: [Select]F:\>dir s:\hyper-pi /s /b
s:\hyper-pi\hyper_pi_0.99
s:\hyper-pi\hyper_pi_0.99\data00
s:\hyper-pi\hyper_pi_0.99\data01
s:\hyper-pi\hyper_pi_0.99\data02
s:\hyper-pi\hyper_pi_0.99\data03
s:\hyper-pi\hyper_pi_0.99\FreeImage.dll
s:\hyper-pi\hyper_pi_0.99\HyperPI.exe
s:\hyper-pi\hyper_pi_0.99\hyperpi_dll.dll
s:\hyper-pi\hyper_pi_0.99\snapshots
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5
s:\hyper-pi\hyper_pi_0.99\data00\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data00\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data01\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data01\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data02\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data02\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data03\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data03\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\snapshots\hpi_20110605_092830.png
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.hlp
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.txt
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi_mod.exe
2. Full listing

Code: [Select] Volume in drive S is USB-1
Volume Serial Number is 2C51-AA7F

Directory of s:\hyper-pi

05/06/2011 09:15 <DIR> .
05/06/2011 09:15 <DIR> ..
05/06/2011 09:15 <DIR> hyper_pi_0.99
0 File(s) 0 bytes

Directory of s:\hyper-pi\hyper_pi_0.99

05/06/2011 09:15 <DIR> .
05/06/2011 09:15 <DIR> ..
05/06/2011 11:51 <DIR> data00
05/06/2011 11:51 <DIR> data01
05/06/2011 11:55 <DIR> data02
05/06/2011 11:52 <DIR> data03
10/01/2008 13:49 724,992 FreeImage.dll
13/02/2008 14:25 103,234 HyperPI.exe
12/02/2008 17:04 18,721 hyperpi_dll.dll
05/06/2011 09:28 <DIR> snapshots
05/06/2011 09:29 <DIR> super_pi_mod-1.5
3 File(s) 846,947 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data00

05/06/2011 11:51 <DIR> .
05/06/2011 11:51 <DIR> ..
05/06/2011 11:51 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data01

05/06/2011 11:51 <DIR> .
05/06/2011 11:51 <DIR> ..
05/06/2011 11:51 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data02

05/06/2011 11:55 <DIR> .
05/06/2011 11:55 <DIR> ..
05/06/2011 11:55 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data03

05/06/2011 11:52 <DIR> .
05/06/2011 11:52 <DIR> ..
05/06/2011 11:52 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\snapshots

05/06/2011 09:28 <DIR> .
05/06/2011 09:28 <DIR> ..
05/06/2011 09:28 9,786 hpi_20110605_092830.png
1 File(s) 9,786 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5

05/06/2011 09:29 <DIR> .
05/06/2011 09:29 <DIR> ..
23/09/1995 01:10 28,287 super_pi.hlp
23/09/1995 01:10 805 super_pi.txt
29/11/2005 20:16 104,960 super_pi_mod.exe
3 File(s) 134,052 bytes

Total Files Listed:
15 File(s) 151,583,305 bytes
23 Dir(s) 242,271,215,616 bytes free

You can use the /a-d switch to exclude the sub directory names (i.e. just list the files)

Code: [Select]F:\>dir s:\hyper-pi /s /b /a-d
s:\hyper-pi\hyper_pi_0.99\FreeImage.dll
s:\hyper-pi\hyper_pi_0.99\HyperPI.exe
s:\hyper-pi\hyper_pi_0.99\hyperpi_dll.dll
s:\hyper-pi\hyper_pi_0.99\data00\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data00\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data01\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data01\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data02\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data02\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\data03\pi_data.txt
s:\hyper-pi\hyper_pi_0.99\data03\pi_rec.dat2
s:\hyper-pi\hyper_pi_0.99\snapshots\hpi_20110605_092830.png
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.GID
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.hlp
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi.txt
s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5\super_pi_mod.exe
Code: [Select]F:\>dir s:\hyper-pi /s /a-d
Volume in drive S is USB-1
Volume Serial Number is 2C51-AA7F

Directory of s:\hyper-pi\hyper_pi_0.99

10/01/2008 13:49 724,992 FreeImage.dll
13/02/2008 14:25 103,234 HyperPI.exe
12/02/2008 17:04 18,721 hyperpi_dll.dll
3 File(s) 846,947 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data00

05/06/2011 11:51 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data01

05/06/2011 11:51 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data02

05/06/2011 11:55 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\data03

05/06/2011 11:52 37,648,082 pi_data.txt
05/06/2011 11:55 48 pi_rec.dat2
2 File(s) 37,648,130 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\snapshots

05/06/2011 09:28 9,786 hpi_20110605_092830.png
1 File(s) 9,786 bytes

Directory of s:\hyper-pi\hyper_pi_0.99\super_pi_mod-1.5

05/06/2011 09:29 8,628 super_pi.GID
23/09/1995 01:10 28,287 super_pi.hlp
23/09/1995 01:10 805 super_pi.txt
29/11/2005 20:16 104,960 super_pi_mod.exe
4 File(s) 142,680 bytes

Total Files Listed:
16 File(s) 151,591,933 bytes
0 Dir(s) 242,271,215,616 bytes freeYou can use the > operator to GET the whole DIR output (all the lines) to a fresh file; and >> to append the output to an existing file (if it exists, otherwise it will be created). I am not sure what you mean about CRC errors. The only thing that will happen, if you choose to redirect the DIR output to a file which is somewhere in the folder tree that you are examining, is that the output file will show up in the listing, unless you take steps (e.g. using | find /v) to exclude it. Because the file will not be CLOSED until after DIR has completed, if it is a new file it will show up in the full listing as having a size of zero bytes, and if it is a pre-existing file it will show the last size it had. But you can redirect the DIR output wherever you like.

Thanks Salmon for pointing me in the right direction. I forgot about that /S switch. Suppose next time I should /? and look at all options before posting a question

As far as the CRC error that I thought I WOULD get like xcopy, I guess I was thinking that if it was trying to write to file using > or >> while it was polling the directory that it could cause a loop back onto itself similar to xcopy which causes the CRC error. But your correct that it doesnt error out, it just shows it in listing.

8829.

Solve : Retrieve last field in each line?

Answer»

I WANT to read a LINE from a text file, and am interested in assigning the last field to a variable. How do I do this without hardcoding the position, I want the script to be flexible ENOUGH to handle varying number of columns.Is the 'text' file space delimited?We have been asked to supply script code to extract the last "field" from a line of text, but we have not been told how the fields are delimited. Dusty has already asked about this. Until this is known, it will be difficult to PROVIDE a suitably robust SOLUTION.

8830.

Solve : Output to a file?

Answer»

I am trying to output information from a batch file to a text file. I am using a batch file program which searches a single text file, line by line for certain names and if they exist, it outputs the name to the screen. I wish to also out put the name to ANOTHER text file. The program goes something like this:

For /F {conditions} DO {actions}

SET {information to NAME}

IF EXIST {conditions} ECHO %NAME% was found

IF NOT EXIST {conditions} ECHO %NAME% was not found

:: This sends the output to the screen

{remainder of loop statements}

I added a statement to send the output to a text file.

SET {information to NAME}

IF EXIST {conditions} ECHO %NAME% was found

IF EXIST {conditions} ECHO %NAME% was found > C:\NAMELIST.txt

IF NOT EXIST {conditions} ECHO %NAME% was not found

:: This sends the output to the screen

{remainder of loop statements}

This semi works. Since only one name is processed in each pass of the loop, NAMELIST.txt is rewritten with each successive pass through the loop. How can I get each name written to successive line in the file NAMELIST.txt without LOSING the information from the previous pass in the loop.
The generation of one name at a time is required by the other parts of the batch file.

Thanks for any help,

TomAll you need to do is understand the difference between the > operator and the >> operator. The FIRST one writes to a file, erasing any file that already exists with the same name. The second creates the file if it does not already exist, and APPENDS to it if it does. Just get it straight in your head when you want to create the file and when you want to append to it.

Thank you Salmon Trout for the great and fast reply.

My problem is I have not done any Basic programming since my Apple II+ / Apple IIe days. A LOT has changed and a lot I forgot.

Tom
Tomkaz, when I first started to want to output to files in a loop, I found the same problem as you. in summary, what I came up with was this:

if exist output.file del output.file
for /f %%L in (file.to.search) do (
{whatever}
if {whatever} echo {whatever} >> output.file
{whatever}
)

8831.

Solve : Registry Editing?

Answer»

Hey, I want to MAKE a batch file that changes the value of the wallpaper in Windows 7. I know it is located at: HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

Editing it manually is fine, but how do I CHANGE it with a script?You can try this. Replace the x's with a fully QUALIFIED file NAME to be used as the wallpaper.

Code: [Select]@echo off
echo Y | reg add "HKCU\Control Panel\Desktop" /V Wallpaper /d "xxxxxxx" > nul

Good luck.

How often do you do this that you need a script?

8832.

Solve : how to create pdf file in dos mode?

Answer»

How to create pdf file in dos mode, and how to print dos file on usb printer
Thanks & Regards
Manoj Jain
Ajmer
Just curious as to why you need to create a PDF in dos? Are you WANTING to capture the DOS command shell and pass it as a screenshot of it into a PDF?

Also printing a file from DOS to USB Printer can be done by redirection on a windows OS system. You have to create a network share for this printer even if no other computers will interface with it. Then create a LPT1 redirect so that its passed to the network shared printer which just happens to be USB. Then any dos programs that print to LPT1 will redirect to your USB printer through the network share.

NET USE LPT1: \\machine_name\PrinterShareName /PERSISTENT:YES


More information here: http://www.hanselman.com/blog/GettingASharedNetworkPrinterToWorkUnderDOS.aspxYou can download various free PDF creator programs. I have found one at the site below called Text to PDF Creator. You can use it from the command line. There are others which can convert various other image or document formats.

http://www.verypdf.com/txt2pdf/index.htm#dl

example batch file:

@echo off
echo Example of text to PDF conversion > Input.txt
echo. >> Input.txt
echo Today's date is %date% >> Input.txt
echo. >> Input.txt
echo The time now is %time% >> Input.txt
echo. >> Input.txt
echo SOME DUMMY TEXT >> Input.txt
echo. >> Input.txt
echo Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec venenatis varius >> Input.txt
echo interdum. Proin vitae hendrerit tellus. Phasellus aliquam mauris vitae leo >> Input.txt
echo porta et lacinia magna convallis. Pellentesque condimentum lorem eget erat >> Input.txt
echo tempor vitae tempor dolor fermentum. Sed et dui libero, a posuere nunc. Aliquam >> Input.txt
echo rhoncus, dui at porta aliquam, massa quam suscipit dolor, ut viverra diam >> Input.txt
echo ligula eu neque. Integer sit amet urna at diam vulputate mattis tempor at >> Input.txt
echo metus. Suspendisse scelerisque lacus in eros interdum aliquet. Aliquam quis >> Input.txt
echo purus sed augue pellentesque volutpat. Sed suscipit placerat est ut molestie. >> Input.txt
echo Donec commodo accumsan orci nec dictum. Nulla urna nulla, posuere suscipit >> Input.txt
echo fringilla vitae, pharetra adipiscing odio. Etiam fringilla gravida lorem, ut >> Input.txt
echo placerat quam accumsan malesuada. Nam ac viverra odio. Morbi vitae nulla odio, >> Input.txt
echo et consectetur leo. Ut tristique, tortor sit amet cursus hendrerit, neque ipsum >> Input.txt
echo consectetur felis, quis vestibulum mauris est in lorem. *CENSORED* sociis natoque >> Input.txt
echo penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut fringilla >> Input.txt
echo fringilla sapien nec consequat. Nullam et sapien nulla. >> Input.txt
"C:\Txt2PDF\txt2pdf.exe" "Input.txt" "Output.pdf" "-pfn:Arial" -pfs12 -pps7 -plm64 -prm64 -ptm64 -pbm64











Since the OP has given hardly any information I think the most helpful answer to the question "How do I create PDF files from the command line?" is probably "You need to get a PDF creator program if you haven't got one already, and study the documentation to find out if it has any command line support, and if so, what the commands and switches are. Each program is different and there is not one SINGLE way of doing THINGS that applies to all PDF creation software."

8833.

Solve : DOS command help?

Answer»

Hello,
I was wondering if somebody could help me write a simple dos script for notepad that I can run to ALLOW me to download some history on my computer.

I want the script to:
1) start firefox
2) goto tools > EmailHistory > Export history
3) (a login box pops up) enter password "password"
4) ( a directory request will pop up) select F:/Folder > ok
5) (message pops up SAYING history exported ok) select ok
6) close firefox

Thanks in advanced
Ryan.You can't do these things in "DOS". You might be able to develop a script in a Windows automation tool like AutoHotKey, and you would stand a better chance of getting your QUESTION answered in a forum devoted to that tool or a similar one.
This could PROBABLY be done in AutoIt or VBScript, but I can't help you because there is no such item "Email History" on the tools menu.Quote from: Linux711 on May 16, 2011, 11:45:46 AM

This could probably be done in AutoIt or VBScript, but I can't help you because there is no such item "Email History" on the tools menu.

I think he probably means Mozilla Thunderbird, but he hasn't been back, so we may never know. This question seems a bit hackish/script kiddieish - I mean, why not just do it in the GUI? I note he wants to use a "drive F" which could be a pen drive... It might not be his computer he wants to do the exporting on.

8834.

Solve : Opening two files at once via a .BAT file?

Answer»

I have written a fairly extensive batch file program that automates processing of meteorological data for my work. The program works WELL, but in my last step, I would like to be able to OPEN two external programs/files at once. One is an executable file (WRPLOT.exe) and the other is an excel SPREADSHEET. The way I have it right now, the WRPLOT opens and the spreadsheet won't open until WRPLOT is closed/terminated.

I've searched through the topics but did not see a solution to this. From what I did read, I'm not sure I can do this with the batch file, but I thought I'd throw this out there and see if anybody has figured out how to do it.

Let me know if you need additional information to ANSWER the question. Thank you!I think you might use this:
start cmd.exe "start WRPLOT.exe"
start cmd.exe "start anything.exe"
Use the quotes
Hope I helped youNo need for the cmd.exe

Code: [SELECT]start "" "c:\wherever\WRPLOT.EXE"
start "" "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"

Note the quotes after START and arounnd the program paths and names and the path to Excel.exe might need altering on a 64 bit machine.
Thank you, that did the trick!

Thanks for the replies!

8835.

Solve : keep batch file on top of other windows?

Answer»

Hey all,

Trying to figure out how to keep a batch file on top of other windows.

Pretty much my program runs a series of tests and outputs results on the cmd window but all the programs it opens go on top of CMD window, is there a way to refresh this screen?

I was thinking maybe have a 2ND batch file that continuously calls the previous one but that would probably require a PID or something along those lines and seems unfeasible.

Thanks,
KhasIt is not clear what you want.
Batch files are normally used for tasks that come to an end and do not need to leave a window open on the desktop. You may wish to consider a programming language for Windows other than command line batch scripts.

Yes, there is a way to do this, but you need to explain in a clear and logical way what you want to do. So you want a report to be seen on the desktop at all times? How will the report be refreshed? It is possible to write text from a batch to an object that is present on the desktop, but how the object is refreshed has to be determined.
Hi Geek-9PM

When i run my batch file it opens multiple windows which appear on top of the batch window ie open 5 instances of cmd and they will cascade but you will not be able to read any text from the initial cmd window as it is covered by the other 4.

The batch i created echos results when opening these programs but you cannot read them unless you change window to the batch file and which stage the program has ALREADY started opening more windows and hides the batch screen again.

so the aim is to somehow keep a batch window above all current and new windows until the batch has completed

hope this makes more senseMay be helpful if you could either show what you have, or write a simplified version that shows the same behavior.
It is not clear if you are debugging the batch or if you need to show the user various outputs. Batch does not of itself control where a window opens.
Not knowing what you want to show the user, it is hard to guess how a batch could do it. If you just want the user to see some reports properly aligned on the desktop, it is easier to do it in a regular presentation program like power point or even Excel. It is even possible to use HTML frames to put stuff where you wan t it on the desktop. It is not clear why you want a batch to place things in well-positioned windows. If you want batch to open another windows, there is not easy way to force a batch where to put the next window. But there are scripts that can do that. Are you familiar with Vb Script?Familiar but not too good at it, learning API at the moment.

My batch is a very low level STRESS tester so please dont get the wrong idea by it. the purpose of it is to test that a computer can run on full capacity without crashing or bluescreening.

you must understand my shyness when revealing code, its similiar to stripping *censored* in public hahaha anyway here it is

@echo off
echo _ _ _ _ _ _
echo _ _ _ _ _ _
echo _ _ _ _ _ _ _ _ _
echo _ _ _ _ _ _
echo _ _ _ _ _ _
echo.
echo.
echo 1. Start stress test 1
echo 2. Kill all processes opened by stress test 1
echo 3. Quit
echo.

set /p userinp=choose a number(1-3):
set userinp=%userinp:~0,1%

if "%userinp%"=="2" goto kill
if "%userinp%"=="3" goto end

echo.

set /p test=How many tests do you want to run?
set test=%test:~0,2%

set instance = 1

if "%userinp%"=="1" goto start


:start

set /a instance+=1

echo Starting Test %instance%

start program

echo Passed Test %instance%

if %instance%==%test% goto kill
goto start


:kill

taskkill -f -im "program" >> a.txt

del a.txt

goto end

:end
pause
exit


The parts that of interest to this post is that i want to be able to view the echos so that i can see what test they are up to and or fail on to compare with other computers etc.
im sure you know how this program operates and as you can imagine with constant calls to new programs clicking on the CMD window specially when your CPU is maxing out and RAM is filling is very difficult so keeping the window on top will be ideal.

Now I get the picture. You want the original windows, or a specific windows, to always be visible. One method is to have dual displays, but I THINK you would have tried that it you had two monitors.

Off the top of my head I don't know how you tell windows to keep on DOS box on top. But you can tell the CMD to start a program with a limited windows, or no window. Look at this:
Quote

START
Start a specified program or command in a separate window.

Syntax
START "title" [/Dpath] [options] "command" [parameters]
Key:
title : Text for the CMD window title bar (required)
path : Starting directory
command : The command, batch file or executable program to run
parameters : The parameters passed to the command
Options:
/MIN : Minimized
/MAX : Maximized
/WAIT : Start application and wait for it to terminate
/LOW : Use IDLE priority class
/NORMAL : Use NORMAL priority class
/HIGH : Use HIGH priority class
/REALTIME : Use REALTIME priority class

/B : Start application without creating a new window. In this case
^C will be ignored - leaving ^Break as the only way to
interrupt the application
/I : Ignore any changes to the current environment.

Options for 16-bit WINDOWS programs only

/SEPARATE Start in separate memory space (more robust)
/SHARED Start in shared memory space (default)

http://ss64.com/nt/start.html
Example"
start "Peek-A-Boo" /MIN "new-batch.bat "

Would tell CMD stat new-batch with a window in the task bar that says "Peek-A-Boo" but not on the screen.

That is the best I can do. For more info, see the link above.
Quote from: Geek-9pm on May 18, 2011, 10:07:17 AM
That is the best I can do.

And very good it was too.
Quote from: Geek-9pm on May 18, 2011, 10:07:17 AM
Off the top of my head I don't know how you tell windows to keep on DOS box on top.

You can't easily with anything built-in but there is a downloadable program called CMDOW which can do this among other things (move, resize, send to back, bring to front, keep on top, tile horizontally or vertically, [and untile again] cascade, [and uncascade], activate, deactivate, minimize, maximize, restore. and more!) Beware though because some antivirus programs (stupidly IMHO) flag it as suspicious apparently because it can be used to completely hide a window. SALMON: Would like to keep it native to most OS's but it seems like an awesome program

Geek: If i open all programs as /min it works although winword and powerpnt 2010 is an exception as it minimizes the first instance and the rest open non minimized.

This should be good enough though thanks for all your help!
8836.

Solve : help with taskkill?

Answer»

Hello, I have a problem if you can call it that way, I want to make a batch file that only allows some executables to run. For example I want to allow only skype.exe and YahooMessenger.exe or any executables written in a file, and the rest of executables to be taskkilled (taskkill *.*) in a loop. Is it POSSIBLE? Can someone help me with this please?
Thank you for ana further help:DYou may be able to use tasklist in batch, but it would be hard because you would have to be updating the process list always. The best way to do this would be to use VB6. Why do you want to do this?I need it to only allow certain programs to run. I want to make something like a PASSWORD prompt, and if you don't enter the password you won't be able to use programs, something like a much restricted quest ACCOUNTA google led me to find Empathy. Which has the curious limitation of only allowing a SINGLE character password.


I also found an application called "Protect EXE Beta" (on http://www.paehl.de/home.htm, dl link is lower down (direct). The site and possibly the program are in German, so YMMV on how well it works.

EDIT: another option might be to install those applications you want to restrict ACCESS to on a separate account and password protect that. That wouldn't prevent somebody from trying to launch the application manually in the other accounts though.

8837.

Solve : Find newest folder?

Answer»

Hello - I am trying to write a batch file to find the newest folder under a CERTAIN directory. I then want to cd to that dir and get a list of files. I'm having trouble with the first part....finding the newest folder. Does anybody have any tips?

Thanks,
JenI can see a way to do this in a mix of batch and C++, however I'd just keep it all in C++ with system calls. The mix of batch and C++ would be to use the C++ program to read in from a text file the output of DIR>readthis.txt and compare date/time stamps on folders to find the newest. Then dynamically write the batch file to CD to that directory. Not sure if this can be done in pure batch.I will be watching this to see if anyone can do this in batch.If you filter out the directories and sort them descending, the newest one will be the first in the list. Used last modified date (default) as the sort criteria but could be changed to creation date by adding the /tc switch:

CODE: [Select]@echo off
for /f "tokens=* delims=" %%i in ('dir /ad /b /o-d ^| find /v ". "') do (
cd %%~dpni
dir
goto :eof
)

Quote from: Sidewinder on May 20, 2011, 04:26:42 PM

If you filter out the directories and sort them descending, the newest one will be the first in the list.

Code: [Select]dir /ad /b /o-d

Using /O-D, the newest one will be the last in the list. It's /OD which sorts dates from earlier to later. /O-D sorts later to earlier. Using this, you can iterate through all the directories with FOR, assigning each name in turn to a variable. After the loop (which can be a one liner) the variable will hold the name of the last in the list, which will be the newest by date. Thus the Goto is avoided.

Does the OP wish to filter out junction POINTS?

Something like the below would just get the subfolders under a folder

Code: [Select]@echo off
for /f "tokens=1-4* delims= " %%A in ( ' dir /tc /ad /od ^| find "&LT;DIR>" ^| find /v "<JUNCTION>" ' ) do if not "%%E"==".." if not "%%E"=="." set NewestFolder=%%E
Echo Newest folder is "%NewestFolder%"


Quote from: Salmon Trout on May 21, 2011, 01:41:51 AM
Using /O-D, the newest one will be the last in the list. It's /OD which sorts dates from earlier to later. /O-D sorts later to earlier. Using this, you can iterate through all the directories with FOR, assigning each name in turn to a variable. After the loop (which can be a one liner) the variable will hold the name of the last in the list, which will be the newest by date. Thus the Goto is avoided.

Does the OP wish to filter out junction points?

Something like the below would just get the subfolders under a folder

Code: [Select]@echo off
for /f "tokens=1-4* delims= " %%A in ( ' dir /tc /ad /od ^| find "<DIR>" ^| find /v "<JUNCTION>" ' ) do if not "%%E"==".." if not "%%E"=="." set NewestFolder=%%E
Echo Newest folder is "%NewestFolder%"

Must be me. But /o-d sorts descending by date with the newest folder first while /od sorts ascending by date with the newest folder at the bottom of the list. In any case, seems like a lot of code to eliminate a goto. NT batch code has a limited instruction set, might as well use them.



I see I was preempted by another post. This might be the answer to all of CH problemsQuote from: Sidewinder on May 21, 2011, 05:44:06 AM
In any case, seems like a lot of code to eliminate a goto.

It's not just "eliminating a goto". This would do that

Code: [Select]for /f "delims=" %%A in ('dir /b /ad /od') do set lastfolder=%%A
dir %%A
My code was also eliminating junction points which may or may not be required (The OP has not replied to my question - not surprising as it's very likely Billrich) and also the . and .. entries that the full DIR listing includes.


Quote from: Sidewinder on May 21, 2011, 05:44:06 AM
In any case, seems like a lot of code to eliminate a goto. NT batch code has a limited instruction set, might as well use them.

In any case, you only needed the goto because you got the sort order around the wrong way.
Quote from: Salmon Trout on May 21, 2011, 06:52:25 AM
In any case, you only needed the goto because you got the sort order around the wrong way.

I gotta stop falling into the rabbit hole. The sort order was purposely chosen to save the time of iterating the entire directory contents. Also curious why eliminate the junction points? Could be wrong, but don't they act as links to a directory, making the directory accessible by using an alias?

Seven hours till End Of Days (local time) when all this becomes meaningless. But just in case, I'll post this for prosperity or until the next End of Days is scheduled. Quote from: Sidewinder on May 21, 2011, 08:45:25 AM
The sort order was purposely chosen to save the time of iterating the entire directory contents.

OK, I'll concede that, but it's hardly going to be a big saving. Maybe on a P133 with 64 MB of RAM (min spec for Win2k) I guess.

Quote
Also curious why eliminate the junction points? Could be wrong, but don't they act as links to a directory, making the directory accessible by using an alias?

I showed elimination of junction points from the directory listing in case it was required; if not it is a simple matter to alter the code.

Quote from: Sidewinder on May 21, 2011, 08:45:25 AM
Seven hours till End Of Days

I need some new eyeglasses, I think, because I THOUGHT that 6 pm was going to be the "Rupture", and I had gathered together materials for hernia treatment for my whole family.
Quote from: Salmon Trout on May 21, 2011, 09:07:23 AM
I need some new eyeglasses, I think, because I thought that 6 pm was going to be the "Rupture", and I had gathered together materials for hernia treatment for my whole family.

Could you do a favour for those of us in a later time zone, and post a warning to us when it starts for you? I still have to get my disguise ready.I'm having my Guinness and Single Malt Scotches in vast amounts just in case...
I started a Tab since noone will be here tomorrow.ROL at what BC said to warn the later time zones that the end is happening in their zone...lol
8838.

Solve : clipping digit from write appending to logfile?

Answer»

This is probably easy to explain, but my google search hasn't given me a reason why digits are clipped when executing for example below and the 1 is not WRITTEN to file unless there is a space between the 1 and the >> write appending to log file.

REM This example clips the 1
@echo. Write this to file 1>>Log.log

REM This example WRITES the 1
@echo. Write this to file 1 >>Log1.log

Was this a question?
You have shown that there has to a space before the redirection thing. Otherwise the last char gets clipped.

Why?
Because.

Sp from now on it with be call DaveLembke's rule. Quote from: DaveLembke on May 22, 2011, 07:09:51 PM

This is probably easy to explain, but my google search hasn't given me a reason why digits are clipped when executing for example below and the 1 is not written to file unless there is a space between the 1 and the >> write appending to log file.

REM This example clips the 1
@echo. Write this to file 1>>Log.log

REM This example writes the 1
@echo. Write this to file 1 >>Log1.log

It's because of numbered console streams.




lol....Geek-9pm


Thanks Salmon for pointing out the correct terminology of Numbered Console Streams! Now I understand what it is instead of just saying..."well you have to add a space...why I dont really know ....other than if I dont, it clips digits... so just add the space."

I wasnt satisfied with just knowing that adding a space makes it work correctly ( without knowing exactly why ) vs without a space clipped the digit, while it wouldnt bother text that is bound tight to it. I am the type of person who likes to understand "why" something behaves the way that it does ......Instead of being satisfied with "well it does it and who cares as to why and how, ...it works so just use it! "

Given the correct terminology I was able to then find more info that helps me understand this:

Stream Redirection:

The explanations regarding the less and greater than symbols aren't complete without knowing what goes where and how to manipulate them.

Handles:
0 - Standard input(normally keyboard but can be redirected from file)

1 - Standard output(Normally console but can be redirected)

2 - Standard error(Normally console but can be redirected)

3 - 9 - Undefined but semi usable, basically useless - at least in BATCH scripts.


Above we were implicitly redirecting, the less than SYMBOL implies that file contents will be sent to the standard input and the greater than symbols implies that the standard output will be sent to file.

To explicitly redirect the number of the handle must come IMMEDIATELY before the redirection symbol, no spaces allowed. This is essentially the same script as above:



echo on

1> example.txt echo echo hello
1>> example.txt echo exit
cmd 0< example.txt
del example.txt
pause

As found at: http://judago.webs.com/batchoperators.htm


8839.

Solve : Very Confused By MSDOS (Making Batch Program)?

Answer»

Okay so I'm heavily a Linux user but I'm on Windows right now. I need to build a simple batch program to connect to a webpage a set number of TIMES and save the result in a unique text file each time. If you're more curious, the reason I am trying to do this is for testing of a certain error that only occurs some of the time. I want to figure out how often it occurs, and if there's any pattern to the occurrence (as I hope that may help with fixing it).


So it's like this:

1) GRAB the URL via WGET (I downloaded it for Windows).

2) Rename the file to a unique name and move it into a /output directory.

3) Repeat this indefinitely until I exit the script.


Here's my code so far:


Quote

set UNIQUE=%UNIQUE%1
print %UNIQUE%
wget "http://www.ismywb.com/testt.php?file=http%%3A%%2F%%2Fismywbco%%3APASSWORD%%40IP%%3A2086%%2Fjson-api%%2Flimitbw%%3Fuser%%3Dpavcsbel%%26bwlimit%%3D24000"
rename "[emailprotected]=http%%3A%%2F%%2Fismywbco%%[emailprotected]%%3A2086%%2Fjson-api%%2Flimitbw%%3Fuser=pavcsbel&bwlimit=24000" result%UNIQUE%.txt
move result%UNIQUE%.txt output\result%UNIQUE%.txt

call countup.bat


What happens is it just downloads and nothing is renamed. The file sits with this horribly long name that WGET GIVES it by default.

I had it renaming earlier (can't remember what I changed) however I can't figure out how to increment in MSDOS. It just APPENDS 1s onto the end like this:

result1.txt
result11.txt
result111.txt
...

I want:
result1.txt
result2.txt
result3.txt
...


And yes I've been searching Google endlessly and not having much luck.

I hope someone here can help me who is more familiar with Batch.Is this the aversion you have?
http://www.gnu.org/software/wget/manual/wget.html
FYI thee are a number of GNU things that have been compiled for Windows.
Python is one of many.
http://www.python.org/getit/

I would like to help,
- but long files names give me vertigo.
8840.

Solve : Net use weird behavior?

Answer»

Hello All - In a batch file I am running the net USE command to map a shared folder. I then cd to that drive and cd to the newest folder, then delete the mapped drive. When I rerun this again, the first net use statement to map the drive takes me to the last folder that I cd'd to. Why does net use behave this way? Example, my share is z: \\servername.domain.com\share\8.2\8.2.0.0.1 - the first execution takes me to the \\servername.domain.com\share\8.2\8.2.0.0.1\8.2.0.0.1.32 as expected, but the next execution takes me to the \\servername.domain.com\share\8.2\8.2.0.0.1\8.2.0.0.1.32\bin folder. So I'm not understanding why I've mapped it to a certain directory but then it seems to take it to the next level and automatically put me in the last dir I was at. That's not the behavior I am looking for....


net use z: \\servername.domain.com\share\8.2\8.2.0.0.1
z:
dir
for /f "tokens=1-4* delims= " %%A in ( ' dir /tc /ad /OD ^| find "" ^| find /V "" ' ) do if not "%%E"==".." if not "%%E"=="." set NewestFolder=%%E
Echo Newest folder is "%NewestFolder%"
cd %NewestFolder%
e:
chdir %HomeDir%
net use z: /delete
Windows remembers paths... THATS why I ALWAYS CD\. and have the batch refocus on the desired root start location and destination.

8841.

Solve : Batch File for Find and replace multipal string in any file format?

Answer»

I want to create a batch file for finding and replacing a string in *.vb file.Why? Do you use VB?
Can't that be done in VB?
How to do the same in other file format LIKE .doc,.txt.exlFor a batch file, find and replace is limited to files that are some form of text format. Other formats have STRUCTURES that are not built for free replacement of text by another program.

A program such as MS word can accept a macro that OPENS a file, REPLACES text, saves the file and quits. The process can be started by a batch program or with some other agent.
You may want to read this:
How to use startup command line switches to start Word

Word is able to convert MANY file formats.
But not all kinds.

8842.

Solve : Testing for & Enumerating %~* and %*?

Answer» HI All
Finally joined the community after spending incalculable amounts of time combing through the site & forums. Thanks to all for lending your expertise.

Although I create little 'batch' scripts regularly for deployments and various other TASKS, I often 'script' for fun. Today's one of those days. I'm writing a small .cmd file for my teammates to help them understand the various variables available at run time. Instead of writing out
Code: [Select]echo %%~0 = %~0
echo %%~1 = %~1
echo %%~2 = %~2
...
echo %%~9 = %~9

rem testing arguments
echo %%0 = %0
echo %%1 = %1
echo %%2 = %2
...
echo %%9 = %9
I was hoping I could leverage FOR /L instead to do something like:
Code: [Select]for /L %%a in (0,1,9) do (
if defined %~%%a echo %%~%%a = %~%%a
if defined %%a echo %%%a
)

I don't know if I can, and how to, test whether or not %1 or %~1 have been defined via for loop.

Its silly, I know. Any ideas?Tricky, but I think Ive done it
Code: [Select]@echo off
echo %%* = %*
for /L %%a in (0,1,9) do call :test %%a %%%%a
goto :EOF

:test
set p=
call set p=%%2
if "%p%"=="" goto :EOF
echo %%%1 = %2

Anyone have any improvements ??NICE - very interesting results.

This seems to work well for testing arguments but not when enumerating %~* during run time. For instance...

I execute the following:
Code: [Select]"C:\test\script.bat" "C:\test\script.bat" two three four five six seven eight nine
Which returns:
Code: [Select]%* = "C:\test\script.bat" two three four five six seven eight nine
%0 = "C:\test\script.bat"
%1 = "C:\test\script.bat"
%2 = two
%3 = three
%4 = four
%5 = five
%6 = six
%7 = seven
%8 = eight
%9 = nine
This works great for checking arguments and the like. However in situations where you might want to strip the quotes around the argument, you would have to use %~1, %~2 etc. Unfortunately there doesn't seem to be a way to do that. Dropping %~ in front of %2 fails altogether, and adding an extra % in front of that results in a literal output: %~two %~three etc.

The batch works as is but was just hoping to add some logic for argument checking. I was hoping I could do something like this but I can't get it to work properly even after
Code: [Select]:EVALARGS
if "%~0"=="" goto :NEXT
echo %0
shift
goto :EVALARGS

According to http://www.robvanderwoude.com/if.php I should be able to use the above example or even [%~0]==[] and "%~0"=="/?" but I had trouble there.Quote from: Phylum on May 25, 2011, 11:43:34 AM
if "%~0"=="" goto :NEXT

But %0 is a special argument. and is unaffected by SHIFT, which dumps %1 and replaces it with %2 and so on until all non-null parameters are exhausted.

* You do know about ~d, ~p, ~n, ~x and the others?


However...

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /L %%a in (0,1,9) do (
call set param=%%%%a
if not "!param!"=="" (
call echo %%%%%%a is %%%%a and %%%%~%%a is %%~%%a
)
)

Called with 5 parameters

Code: [Select]C:\Test>nparams005.bat cat dog horse cheese "cake"
%0 is nparams005.bat and %~0 is nparams005.bat
%1 is cat and %~1 is cat
%2 is dog and %~2 is dog
%3 is horse and %~3 is horse
%4 is cheese and %~4 is cheese
%5 is "cake" and %~5 is cake

Hi Salmon Trout

I must have been out of my MIND when I put %~0. As foolish as it looks now, I meant %~1 through 9. Thank you for that!

Your solution works perfectly! I struggled with trying to do what you did in the if statement, very creative!

In case anyone is ever curious about argument counting without using shift
Code: [Select]set argcount=0
for %%a in (%*) do Set /A argcount+=1
8843.

Solve : Variable in FOR loop?

Answer»

Greetings. I am wanting to create a text file listing all the files in a DIRECTORY. A quick search on google provided myriad examples. The below for loop works fine. Note, I added the time stamp string in order to write the time stamp at the top of my file in my required format.

@ECHO OFF
::Create timestamp as string
SET Dt=%date:~10,4%%date:~4,2%%date:~7,2% %time%
SET str=%dt%
ECHO %str% >> c:\FileList.txt
::The below FOR loop is an exact copy of an example I found on google.
FOR /r "C:\Documents and Settings\Administrator\My Documents\My Pictures" %%X IN (*.jpg) DO (
ECHO %%X >> c:\FileList.txt
)

The above script works exactly as needed. My problem is that I want to introduce a variable within the FOR loop to hold the value of %%X. The reason is that I want to be able to manipulate it. The below is what I tried.

@ECHO OFF
:: Create timestamp as string
SETLOCAL ENABLEDELAYEDEXPANSION
SET Dt=%date:~10,4%%date:~4,2%%date:~7,2% %time%
SET str=%dt%
ECHO %str% >> c:\FileList.txt
FOR /r "C:\Documents and Settings\Administrator\My Documents\My Pictures" %%X IN (*.jpg) DO (
SET !var! = %%X
ECHO %var% >> c:\FileList.txt
)

The output of the file looks like this:
20110522 10:17:18.21
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
.....

I read a little bit about the SETLOCAL ENABLEDELAYEDEXPANSION option, but I'm not sure that I fully get it, as my limited experience is with VB. What I want to do is ECHO %var% instead of %%X, once again, because I want to be able to further manipulate it once I can get it working. I should also note I am not experienced with DOS code (or what ever it is called). I would greatly appreciate any suggestions or help. Thank you.

Greg

You need to focus on this area. Make a test batch with just this part of your work. By braking something into smaller parts, it is easier to see what happens.

Quote

FOR /r "C:\Documents and Settings\Administrator\My Documents\My Pictures" %%X IN (*.jpg) DO (
SET !var! = %%X
ECHO %var% >> c:\FileList.txt
)

Try to debug your test batch with more ECHO statements. For example, use a simple ECHO of the variable befog and after you change it. Surprise! Delayed expansion ?
A very "interesting" post from Geek.

gsnidow, due to the way the Windows NT family command interpreter (which is not "DOS", by the way) processes variable expansion in FOR structures, to set and expand variables within a loop, you need to use "delayed expansion". You set it up in a batch file by including this line somewhere before the loop

setlocal enabledelayedexpansion

The case doesn't matter - upper or lower or a mixture of the two, all are OK. Mostly it's OK to put it right at the start after the @echo off line that starts most scripts. If you leave it out then you can't use delayed expansion variables of the !var! type

Now, we come to how you use this feature within a loop, (in fact within any structure where multiple lines are enclosed in brackets)

You assign (set) the variable in the normal way, by using the set command followed immediately by an equals sign and then the variable value:

SET var=%%X

Note that there are no exclamation marks ("exclamation points") in the above line.

To read (expand) the variable within the loop you treat it like a normal variable, but with the difference that you use exclamation marks (!) and not percent signs (%):

echo !var! >> c:\FileList.txt

You can do all the usual variable processing stuff with such a variable.

Note also that once the loop has finished (after the closing bracket of the loop) you can still access the variable but you use percent signs as normal. In the script you showed above, after the loop has finished, %var% will contain the last value that !var! held. This might be useful sometimes if you want to know the last item in a list or sequence.

A point - using double colons :: as comment markers is unofficial, undocumented and unsupported, and will in certain situations (within a loop for example) break a script. Use REM or Rem or rem or ReM instead.

Another point - writing ALL the commands in UPPER CASE is not compulsory.





Thank you so much Geek and Salmon for the very helpful points. I have made it easier on myself by creating c:\test, and putting only 3 files in it, Test1.txt..Test3.txt. At Geek's suggestion, I have been working on only the problem part, which, with my new test folder, boils down to...

FOR /r "C:\test" %X IN (*.txt) DO SET var = %X

Note I am not trying to do this in a batch file now, because I want to see what is happening in the cmd window. As expected, the output of this line is...

C:\...>SET var = C:\test\Test1.txt
C:\...>SET var = C:\test\Test2.txt
C:\...>SET var = C:\test\Test3.txt

This RESULT seems to me to imply that for each iteration of the loop, it is correctly assigning the value of the current file name to the var variable. I then tried this...

FOR /r "C:\test" %X IN (*.txt) DO SET var = %X ECHO %var

My thought was that since, based on my assumption above, the variable is being correctly set, the next step would be to ECHO it. However, this is not the case, as the output is now...

C:\...>SET var = C:\test\Test1.txt ECHO %var
C:\...>SET var = C:\test\Test2.txt ECHO %var
C:\...>SET var = C:\test\Test3.txt ECHO %var

It seems that it is only appending "ECHO %var" to the variable value, along with the file name of the current iteration. I am thinking it must be possible to carry out multiple actions in the DO part of the loop, but I can't seem to get it. One question to the delayed execution: I am having trouble understanding why it is necessary if, based on my first results, it seems to be correctly assigning the variable value without it.

@Salmon - I'm going to continue to mess with it before I simply copy and paste your line of code, so I will probably have some more questions later. As for the all caps, I'm a SQL guy, and my practice is to always put key words in all caps, because it makes the code easier to read.

Once again, I very much appreciate both of your helping me as I muddle through being a newbie at this. Thank you so much.

Greg





Quote
FOR /r "C:\test" %X IN (*.txt) DO SET var = %X ECHO %var

1. You can't do this.

2. Variables have a percent sign before and after so %var won't work.

3.

Quote
As expected, the output of this line is...

C:\...>SET var = C:\test\Test1.txt
C:\...>SET var = C:\test\Test2.txt
C:\...>SET var = C:\test\Test3.txt

It was just echoing "set var = " (which is wrong; lose those spaces) and expanding %X. The variable %var% was not being set correctly. Trust me.

Quote
It was just echoing "set var = " (which is wrong; lose those spaces) and expanding %X. The variable %var% was not being set correctly. Trust me.

Ah ha, those darned spaces. All seems to be good now, so I very much appreciate the help. One last question, how do I know when to use '%' and when to use '!' to wrap my variables? Thanks again.

GregQuote from: gsnidow on May 23, 2011, 05:51:16 AM
how do I know when to use '%' and when to use '!' to wrap my variables? Thanks again.

You use % all the time except when you want to expand a variable, in a loop or other parenthetical structure (e.g. a long form IF), which you have previously set in that structure.


@Salmon - I apologize if this is a newbie question, but I don't know what you mean by expanding a variable. I read some stuff on google, but most of it was dealing with posters having issues with expanding their variables in various languages. Could you possibly put it in laymen terms? Thanks.

GregWhole waiting or Salmon Trout, here is some more reading.
http://www.robvanderwoude.com/variableexpansion.phpQuote from: gsnidow on May 23, 2011, 08:14:40 PM
I don't know what you mean by expanding a variable. Could you possibly put it in laymen terms?


OK here GOES...

You create a variable with the SET command, and when you use it in a statement, it gets "expanded" by the command interpreter cmd.exe.

set animal=cat

The command interpreter reserves some memory space for a variable called "animal" and stores the THREE characters 'cat' in that space.

later you have

echo %animal%

When the command interpreter processes this line it identifies the variable because of the percent signs and looks up the value of "animal" in its list of variables. It finds 'cat' so it replaces %animal% with cat and executes

echo cat

This process of replacing a variable's name with the value it holds is called "expansion".




Thanks for the help and explanation guys. That is a great article, and it does not seem so strange now. I very much appreciate you taking time out of your busy days to consider and respond to my questions.

Greg
8844.

Solve : read next line of source file?

Answer»

I need help to create a set of subdirectories two levels down in a root directory. I have to use a source file to read from but do not know how to get the next line of the source file.

The root directory has the following structure:
e:\26334\7327\
e:\26335\7317\
e:\26910\7690\
e:\26912\7100\
e:\26916\1414\
e:\27127\7702\
e:\28145\4726\
e:\28177\4122\
e:\28189\7125\
e:\28211\3527\
e:\28528\8236\
e:\28535\8155\
e:\28746\6291\
e:\29036\3448\
e:\29222\8231\
and so on...

I am using a source file to read from that looks like this:
23742\3524
26035\8919
26316\7814
26334\1223
26334\7327
26910\7690
27127\7702
28145\4726
28211\3527
28528\8236
28535\8155
28746\6291
29036\3448
29222\8231
29353\1669
30529\4689
30843\7460
31415\8053
and so on...

The source file is called dir-list.txt. The batch file I'm trying to create will be run from the root e:\

The following is the batch file so far:

::---
FOR /F "tokens=1 eol=^" %%G IN (dir-list.txt) DO (

::combine current directory with path returned in variable %%G
set "D1=%cd%"
set "D2=%%G"
set "DD=%D1%\%D2%"

::find destination directory
IF EXIST %DD% GOTO cd

::change directory to destination directory
:cd
PUSHD %DD%
GOTO md

::create folders in destination directory
:md
MD TEST1, TEST2, TEST3

::return to ORIGINAL directory
POPD
)
::---

This works by creating the folders TEST1, TEST2 and TEST3 under the second level down but then stops after one iteration. I need it to go through the dir-list.txt until the end. Also, I don't have any error routine for the folders that are not in the dir-list.txt or the entries in the dir-list.txt that are not found in the root directory. The root directory is on a Windows 2008 r2 machine. Thank you for any suggestions.1. You need to use delayed expansion to set and use variables in a FOR loop. Use Google to find out about this.
2. Do not start comment lines with unofficial, unsupported, deplored, BAD double colons. ( This breaks FOR loops. Use the proper REM instead.

Then see if your code works.

Thanks for the reply.
I tried it with the setlocal enabledelayedexpansion.
the following is the output of the batch file. I removed the comments.
E:\>test.bat

E:\>SETLOCAL enabledelayedexpansion

E:\>FOR /F "tokens=1 eol=^" %G IN (dir-list.txt) DO (
set "D1=E:\"
set "D2=%G"
set "DD=E:\01333\8915"
IF EXIST E:\01333\8915 GOTO cd
PUSHD E:\01333\8915
GOTO md
MD TEST1, TEST2, TEST3
POPD
)

E:\>(
set "D1=E:\"
set "D2=01333\8915"
set "DD=E:\01333\8915"
IF EXIST E:\01333\8915 GOTO cd
PUSHD E:\01333\8915
GOTO md
MD TEST1, TEST2, TEST3
POPD
)

E:\>PUSHD E:\TEMP\01333\8915

E:\01333\8915>GOTO md

E:\01333\8915>MD TEST1, TEST2, TEST3

E:\01333\8915>POPD
E:\>
--------------------------------------------

It still stops after one iteration. You showed the output but not the new code. Why? Also, why do you have gotos and labels inside a loop? (That's why you can't have double colon "comments" inside a loop, because such a comment is really a broken label, and labels break loops.) Did you actually "write" this code yourself, or did you just copy and paste bits of other batch scripts you found on the web? It would be better if you went back to the beginning and started again, studying batch script syntax carefully.
As I indicated in my post, I removed the comments and added the SETLOCAL enabledelayedexpansion, so didn't think the code was needed because beyond that, the code was the same. And yes, I wrote it all by my lonesome. I subsequently MOVED the goto out of the loop and it continues through the entire source file. But then I had trouble reinitializing the %DD% variable. It kept the same value through all iterations. So, to keep from further disrupting this great forum, I accomplished it in about 1/2 an hour in C#. SORRY, I create batch files all the time for simpler stuff and thought it would have been easy. Swim on Mister Trout! Thanks for the help.This code needs work but should help get you started. I will write more latter. Good luck

@echo off
setlocal enabledelayedexpansion
FOR /F %%i in (dir-list.txt) do (

rem combine current directory with path returned in variable %%i
set D1=%%i
echo D1=!D1!
set D2=%%i
echo D2=!D2!
set DD=!D1!/!D2!
echo DD=!DD!
echo.
)
pause
rem find destination directory
IF EXIST !DD! goto chgdir

rem change directory to destination directory
:chgdir
echo DD=!DD!
echo pushd
popd
PUSHD


echo DD=!DD!
pause
popd
dir
pause


rem create folders in destination directory

rd xTEST1, xTEST2, xTEST3

md xTEST1, xTEST2, xTEST3

rem return to original directory
POPD
echo DD=!DD!
)


C:\test>


C:\test> lexus.bat
D1=23742\3524
D2=23742\3524
DD=23742\3524/23742\3524

D1=26035\8919
D2=26035\8919
DD=26035\8919/26035\8919

D1=26316\7814
D2=26316\7814
DD=26316\7814/26316\7814

D1=26334\1223
D2=26334\1223
DD=26334\1223/26334\1223

D1=26334\7327
D2=26334\7327
DD=26334\7327/26334\7327

D1=26910\7690
D2=26910\7690
DD=26910\7690/26910\7690

D1=27127\7702
D2=27127\7702
DD=27127\7702/27127\7702

D1=28145\4726
D2=28145\4726
DD=28145\4726/28145\4726

D1=28211\3527
D2=28211\3527
DD=28211\3527/28211\3527

D1=28528\8236
D2=28528\8236
DD=28528\8236/28528\8236

D1=28535\8155
D2=28535\8155
DD=28535\8155/28535\8155

D1=28746\6291
D2=28746\6291
DD=28746\6291/28746\6291

D1=29036\3448
D2=29036\3448
DD=29036\3448/29036\3448

D1=29222\8231
D2=29222\8231
DD=29222\8231/29222\8231

D1=29353\1669
D2=29353\1669
DD=29353\1669/29353\1669

D1=30529\4689
D2=30529\4689
DD=30529\4689/30529\4689

D1=30843\7460
D2=30843\7460
DD=30843\7460/30843\7460

D1=31415\8053
D2=31415\8053
DD=31415\8053/31415\8053

Press any key to continue . . .

8845.

Solve : Need MS-DOS Latest version Download info?

Answer» HI,

where can i find the source (MS-DOS FILE) to UPGRADE the EXISTING one?

Thanks,
SravanMS-DOS is a copyrighted PRODUCT.
You have to buy it.
Quote
Microsoft MS-DOS 6 Upgrade Operating System
by Microsoft
Price: $26.99
ttp://www.amazon.com
Upgrade to version 6.22 from any earlier version 6.xx free from Microsoft

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=96cc3197-b7e5-4b31-badb-ddaac771295f
8846.

Solve : Old Computer with bad hard drive - need help with autoexec.bat?

Answer»

I have an old laptop with a bad hard drive. The laptop is an CTX Ezbook 700.
I was able to correctly install EVERYTHING - except the CD Rom Drive.

It is working in DOS 5. I made changes to the SETUP, created a new config.sys and Autoexec.bat. When it starts now, there are no obvious errors it Setup, the config.sys has no obvious errors. The autoexec tells me I have successfully
installed Drive C: (even though I specified drive d: in the autoexec file.).

When I check further, d: does not WORK c: does not produce an error
c: is there logically - but there is no actual c: drive so I cant't use that either.

Is the Problem in Setup or in the autoexec.bat or did I miss something in the Config.sys file.

I tried putting in a LINUX disk in the cd drive - but that didn't work either
t












Quote

The autoexec tells me I have successfully
installed Drive C: (even though I specified drive d: in the autoexec file.).

It SOUNDS like you are booting from a floppy? In which case A: and B: are reserved for floppy drives, then C will be the system (MS-DOS) drive if present, and if not that letter will get assigned to the CD-ROM. The autoexec massage must be from MSCDEX.


Massage.....

Post the config.sys and autoexec.bat files for review...
8847.

Solve : Taking the spaces out of file names in a batch of files?

Answer»

Hi folks,

I'm just a beginner here with MS-Dos, but recently I've learned some neat WAYS of doing things through CMD that have saved me quite some time. ONE example is a large file file rename. My job requires me to rename image files for products according to theire UPC. By using a the ren or rename function and some vlookup in excel I am able to rename a bunch of files by simply doing a directory dump and COPYING that into excel. I then match those file names (who usually have model numbers) up to the corresponding UPCs. I then RUN a copy and paste formula in excel that read something like this ="ren "&A39&" "&c39&".jpg" and copy that formula into all my cells. Now I have text in each cell that reads something like this ren W0102 COFFRET ACCESSOIRES.jpg 746775023492.jpg I then proceed to copy all my the column with all the rename formulas in text and paste it in CMD and voila, all my file are renamed. Now for my question, can I do something similar to what I have just described to take the spaces out of my file names? This would be helpful as when my original file has space I have to go through and take them out as if they were there my rename formula would not work. My files would be located in C:\Users\Eddie\Desktop\Images So is there anyway I can go into a directory and take the spaces out of each file name with a DOS script or COMMAND? Thank you for reading through that meaty bit of writing!Run the script and if you are happy with how it works remove 'echo' from the start of the 7th line.

Code: [Select]@echo off
setlocal enabledelayedexpansion
cd /d "C:\Users\Eddie\Desktop\Images"
for /f "delims=" %%A in ('dir /b *.jpg') do (
set oldfilename=%%A
set newfilename=!oldfilename: =!
echo ren "!oldfilename!" "!newfilename!"
)
echo.
echo all done
pause

8848.

Solve : Display only total files and bytes line on dir command?

Answer»

I am creating a batch file to backup certain directories. After the copy command, I want to compare the total files and bytes of the original directory to the backup directory to confirm everything worked ok. I have used the dir /s command, but that displays pages of files and folders, making the comparison on one screen impossible. What I want to do is display only the next to last line that shows the total files and bytes.

I have tried the dir /s c:\xxxxxx | FIND "File(s)", which works, however it also displays the total files/bytes for each of the folders, resulting in pages of results. I only want the final grand total of the entire directory. If there were something unique in the "string" for that line, I would be FINE, however the lines are the same, except that the sub-directories show "0 Files", where the grand total line shows shows a number instead of "0".

Does anyone know how to display only the grand total line and not each separate folder total line?

Thanks,
Quote

If there were something unique in the "string" for that line, I would be fine

There is something unique - its position in the output listing, so we can use a FOR loop to successively assign the line CONTAINING "File(s)" to a variable and when the loop is over the variable holds the final value. Just like dir /s, the code below will appear to do nothing for a while if the tree is a deep one with many files.

Code: [Select]@echo off
for /f "delims=" %%A in ( ' dir /s "D:\Folder" ^| find "File(s)" ' ) do set total=%%A
Echo Total for tree is %total%
Developed a bit...

Code: [Select]@echo off
set folder1="D:\test"
set folder2="T:\test"
for /f "delims=" %%A in ( ' dir /s %folder1% ^| find "File(s)" ' ) do set total1=%%A
for /f "delims=" %%A in ( ' dir /s %folder2% ^| find "File(s)" ' ) do set total2=%%A
for /F "tokens=1-4" %%A in ("%total1%") do (
set files1=%%A
set bytes1=%%C
)
for /F "tokens=1-4" %%A in ("%total2%") do (
set files2=%%A
set bytes2=%%C
)
Echo Folder: %folder1% Files: %files1% Bytes: %bytes1%
Echo Folder: %folder2% Files: %files2% Bytes: %bytes2%
if "%files1%"=="%files2%" (
echo Number of files: identical
) else (
echo Number of files: NOT identical
)
if "%bytes1%"=="%bytes2%" (
echo SIZE of data: identical
) else (
echo Size of data: NOT identical
)

Code: [Select]Folder: "D:\test" Files: 2043 Bytes: 165,993,132
Folder: "T:\test" Files: 2043 Bytes: 165,993,132
Number of files: identical
Size of data: identical
8849.

Solve : Detect and Eject Removable Disk in cmd?

Answer»

hi
how can i create the batch file to detect and eject removable drive automatically ?
tnxsomething like this?
http://www.911cd.net/forums//index.php?s=924b5513860a93a2c9bef812b0718a05&showtopic=13917&pid=132133&st=0&#entry132133tnx for reply,
but i want to detect usb mass drive and eject it. (something like safe REMOVE!) Quote from: rockhudson on July 28, 2011, 10:36:39 AM

Wlll not eject automatically. USB stick is safe to remove manually at any time.

That advice is reckless. Delayed write and programs that have a file open on the device will not take too kindly to your yanking the device from the port.

Could not find a script to do a safe remove but you can enter this command in a batch file which will present the GUI:

Code: [Select]RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll

There are also third PARTY programs which claim to ACCOMPLISH this. Google will be helpful here.

Good luck.

BTW: Didn't Rock Hudson die some years ago. Good to see the cemetery crowd on CH.Quote
Wlll not eject automatically. USB stick is safe to remove manually at any time.

Agreed ...shifty advice at best.Quote from: behad-007 on July 27, 2011, 02:44:33 AM
Tnx for reply,
but i want to detect usb mass drive and eject it. (something like safe remove!)

Transfusion wrote:
"Something like this?
http://www.911cd.net/forums//index.php?s=924b5513860a93a2c9bef812b0718a05&showtopic=13917&pid=132133&st=0&#entry132133"

The Transfusion method Is for a CD drive with a door. The OP,behad-007, is concerned with a USB storage device.

_______________________________________ ______

There is safely remove USB icon at the lower right.

Remove USB drive when Safely Remove Hardware icon APPEARS at the lower right.Quote from: Fred35 on July 28, 2011, 05:46:31 PM
Transfusion wrote:
"Something like this?
http://www.911cd.net/forums//index.php?s=924b5513860a93a2c9bef812b0718a05&showtopic=13917&pid=132133&st=0&#entry132133"

The Transfusion method Is for a CD drive with a door. The OP,behad-007, is concerned with a USB storage device.

_______________________________________ ______

There is safely remove USB icon at the lower right.

Remove USB drive when Safely Remove Hardware icon appears at the lower right.

_______________________________________ _____
When icon does not appear do:

RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll

http://ask-leo.com/safely_remove_hardware_where_did_the_icon_go_how_do_i_safely_remove_hardware_without_it.htmlthanks to all for reply,
this code was very helpful

RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll
8850.

Solve : Exclamation Marks [!] in DOS text files cause 'FOR /F' processing problems.?

Answer»

I'm using 'FOR /F' to change every occurrence of 'X' to 'Y' in every line of a text file.

So far so good, but problems occur if the text file contains exclamation marks [!]. Exclamation marks, and any text between them are lost.

My input file [Test-myfile.txt] contains...

Line 01 containing A but not X!
Line 02 containing A but not X!Watch this space!X
Line 03 containing X but not Y! and another xylophone.
Line 04 containing X and Y and another x and a word like axiom.
Line 05 containing Y but not X;
Line 06 containing Xxx but not Yyy:
Line 07 containing B and Z and Y~
Line 08 containing Y but not X#
Line 09 containing X and Y and another xylophone

My MS-DOS batch code [Test_Change_CharactersInStrings_110508.bat] is as follows...

@ECHO OFF
COLOR F5

REM====================================================
REMCode to change every occurrence of 'X' to 'Y' --
REMin every line of 'Test-myfile.txt'...
REM====================================================
REMNeed to check why exclamation marks [!], and any text between them are lost???
REM====================================================

@ECHO OFF > newfile.txt
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=1,2,3,4,5,6,7-15* delims= " %%a in (Test-myfile.txt) DO (
REMPAUSE
ECHO a[%%a]
REMPAUSE
ECHO b[%%b]
ECHO c[%%c]
ECHO d[%%d]
ECHO e[%%e]
ECHO f[%%f]
ECHO g[%%g]
ECHO h[%%h]
ECHO i[%%i]
ECHO j[%%j]
ECHO k[%%k]
ECHO l[%%l]
ECHO m[%%m]
ECHO n[%%n]
ECHO o[%%o]
REMSET LINE_TEXT=%%a
SET LINE_TEXT=%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o
ECHO Original line...!LINE_TEXT!
SET LINE_TEXT=!LINE_TEXT:X=Y!
ECHO Modified line...!LINE_TEXT!
ECHO !LINE_TEXT! >> newfile.txt
)
ECHO Done!
SETLOCAL DisableDelayedExpansion
ECHO Last modified line...%LINE_TEXT%
PAUSE
EXIT

After running the code, my output file [newfile.txt] contains...

Line 01 containing A but not Y
Line 02 containing A but not YY
Line 03 containing Y but not Y and another Yylophone.
Line 04 containing Y and Y and another Y and a word like aYiom.
Line 05 containing Y but not Y;
Line 06 containing YYY but not Yyy:
Line 07 containing B and Z and Y~
Line 08 containing Y but not Y#
Line 09 containing Y and Y and another Yylophone

Any ideas of how I can prevent exclamation marks, and any text between them, from being lost?
The string variable for each line is not being created correctly because with delayed expansion enabled, exclamation marks are variable delimiters and thus are ignored along with everything between them. Batch scripts get terribly fiddly when special characters ("poison characters" are embedded in strings to be processed. The worst is the ampersand but parentheses and percent signs are among the others.

What I did below is to take the set of tokens spat out by FOR /F and create a string enclosed in quotes so I could pass it as one single parameter to a CALLed subroutine where the tilde variable modifier strips off the quotes and then the X=Y substitution takes place, followed by the output to the file. No delayed expansion needed.

Consider "CALL :replace" to be equivalent to "GOSUB replace" in BASIC, and "GOTO :eof" to be equivalent to "RETURN" in BASIC. The colons are obligatory, not optional like they are when using GOTO with labels.

batch script
Code: [Select]@ECHO OFF
REM ====================================================
REM Code to change every occurrence of 'X' to 'Y' --
REM in every line of 'Test-myfile.txt'...
REM ====================================================
@ECHO OFF > newfile.txt
FOR /F "tokens=1,2,3,4,5,6,7-15* delims= " %%a in (Test-myfile.txt) DO (
call :replace "%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o"
)
ECHO Done!
pause
exit

:replace
set string1=%~1
set string2=%string1:X=Y%
echo %string2% >> newfile.txt
goto :eof

newfile.txt
Code: [Select]Line 01 containing A but not Y!
Line 02 containing A but not Y!Watch this space!Y
Line 03 containing Y but not Y! and another Yylophone.
Line 04 containing Y and Y and another Y and a word like aYiom.
Line 05 containing Y but not Y;
Line 06 containing YYY but not Yyy:
Line 07 containing B and Z and Y~
Line 08 containing Y but not Y#
Line 09 containing Y and Y and another Yylophone
ST, thank you very much for providing a solution to my problem -- I had unsuccessfully searched several websites looking for information on it before you came up with the goods.

One further point about my example is that I notice that the character substitution changes 'X' or 'x' (upper and lower case) to 'Y' (the resulting character is the case as specified). Is there a way to preserve the original case of the target character? (i.e. 'X' becomes 'Y', and 'x' becomes 'y'). Thanks in anticipation.

Incidently, ST, I tried to thank you by clicking the 'Thank Salmon Trout' button but GOT...

"An Error Has Occurred! Sorry, you can't repeat a karma action without waiting 2 hours."

Don't know what that's all about!
Give this a try

Code: [Select]@ECHO OFF
REM ====================================================
REM Code to change every occurrence of 'X' to 'Y' --
REM in every line of 'Test-myfile.txt'...
REM ====================================================
@ECHO OFF > newfile.txt
FOR /F "tokens=1,2,3,4,5,6,7-15* delims= " %%a in (Test-myfile.txt) DO (
call :replace "%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o"
)
ECHO Done!
pause
exit

:replace
set string1=%~1
set string2=
set j=0
:Loop
call set inchar=%%string1:~%j%,1%%
if "%inchar%"=="" goto ExitLoop
set outchar=%inchar%
IF "%inchar%"=="X" set outchar=Y
IF "%inchar%"=="x" set outchar=y
set "string2=%string2%%outchar%"
set /a j=%j%+1
goto Loop
:ExitLoop
echo %string2% >> newfile.txt
goto :eof
Alternative in which a one-line VBScript is created, used and destroyed; it will run slightly more slowly. Note that FOR loop metavariables are case sensitive, so %%A will not interfere with %%a. Note also that the first FOR loop can be one line.

Code: [Select]@ECHO OFF
REM ====================================================
REM Code to change every occurrence of 'X' to 'Y' --
REM in every line of 'Test-myfile.txt'...
REM ====================================================
echo wscript.echo Replace(wscript.arguments(0), wscript.arguments(1), wscript.arguments(2))>Srep.vbs
@ECHO OFF > newfile.txt
FOR /F "tokens=1,2,3,4,5,6,7-15* delims= " %%a in (Test-myfile.txt) DO call :replace "%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o"
ECHO Done!
del Srep.vbs>nul
pause
exit

:replace
set string2=%~1
for /f "delims=" %%A in ( ' cscript //nologo Srep.vbs "%string2%" "X" "Y" ' ) do set string2=%%A
for /f "delims=" %%A in ( ' cscript //nologo Srep.vbs "%string2%" "x" "y" ' ) do set string2=%%A
echo %string2% >> newfile.txt
goto :eof
ST, thanks again for the 2 solutions which you provided -- both of which preserve case sensitivity.

Am I right in assuming that the use of double-quotes in the [SET "string2=%string2%%outchar%"] statement -- in the non-VBS version -- is a way of ensuring that spaces, currently at the end of the string being processed, are not lost?Quote from: TomTheCabinBoy on May 11, 2011, 04:59:14 AM

ST, thanks again for the 2 solutions which you provided -- both of which preserve case sensitivity.

Am I right in assuming that the use of double-quotes in the [SET "string2=%string2%%outchar%"] statement -- in the non-VBS version -- is a way of ensuring that spaces, currently at the end of the string being processed, are not lost?

Yes, that is correct. The SET command used without quotes ignores trailing spaces, so to be sure that, if %outchar% should happen to be a space, it is added, the quotes are used as you saw.
[Update] I tested the batch without quotes in that line, and it seems to work just the same. I think I just assumed you needed them.
ST, you warned me, in your initial reply, that "poison characters" embedded in text strings can cause problems when PROCESSING them in batch scripts. Sure enough, when my test text file was modified to contain ampersands [&], percent signs [%], and double quotes ["], in ADDITION to the dreaded exclamation marks [!], problems were encountered. Sorry to say, all 3 of your solutions -- which worked fine for exclamation marks [!] -- failed when processing the aforementioned additional rogue characters.

I think you might be interested in a solution, I have developed, which seems to cope with all of the above "poison characters". It is based on some of your conversion code (but after many experiments with combinations of enabling/disabling delayed expansion, and in or out of sub-routines). I have commented the script as a reminder of how different methods work, or don't work, in certain situations.

My input file [Test-myfile.txt] now contains...

Code: [Select]Line 01 containing x but not X!
Line 02 containing A but not X!Watch this space!x
Line 03 containing X but not Y! and another xylophone.
Line 3A containing X and 1st percent % sign, 2nd percent % sign, and 3rd percent % sign.
Line 3B containing X and just 2 percent % signs. (Here's the 2nd percent % sign).
Line 3C containing X and 1st percent ^% sign, 2nd percent ^% sign, and 3rd percent ^% sign.
Line 3D containing X and just 2 percent ^% signs. (Here's the 2nd percent ^% sign).
Line 04 containing X and Y and another x and a word like axiom.
Line 4A containing x and an ampersand & and another & followed by one more & and a percent % sign.
Line 4B containing x and an ampersand & on its own.
Line 4C containing 2 ampersands -- this one & and this one & as well.
Line 05 containing Y but not x; also an upper-case 'X' in single quotes
Line 5A containing W but not X; also a lower-case "x" in double quotes
Line 06 containing Xxx (but not Yyy):
Line 07 containing B and Z and Y~
Line 08 containing Y but not X#
Line 09 containing X and Y and another Xylophone

My MS-DOS batch code is now as follows...

Code: [Select]@ECHO OFF
REM ====================================================
REM Code to change every occurrence of 'X' to 'Y' --
REM in every line of 'Test-myfile.txt' -- without losing --
REM 'special characters'. e.g. [!][%][&][#][~]["]['].
REM Preserving upper/lower case is selectable.
REM ====================================================

REM Display/obtain case preservation options/choice...
ECHO.
ECHO When changing 'X' to 'Y' should the original case be preserved?
ECHO.
ECHO [0] Case-preservation is not important. (Default - Quicker)
ECHO [1] Preserve original case. (Slower)
ECHO.
SET /P CASE_CHOICE=Enter option...
ECHO.
IF "%CASE_CHOICE%" EQU "1" ECHO Original case will be preserved. (Slower option)
IF "%CASE_CHOICE%" NEQ "1" ECHO Original case may not be preserved. (Quicker option)
ECHO.
PAUSE

REM Initialise a count for lines processed.
SET LINES_COUNT=0

REM Create an empty Output File.
@ECHO OFF > newfile.txt

REM One at a time, read each complete line of the Input File into a single string.
FOR /F "tokens=1* delims=" %%a in (Test-myfile.txt) DO (
REM ECHO Original line..."%%a"
REM At this point, complete string is intact.

REM Copy the complete intact string --
REM enclosing in quotes to protect special characters (most).
SET string1="%%a"
REM At this point, string1 contains the complete intact quoted string --
REM but appears to be empty/undefined if echoed.

REM For each line of the Input File, string processing requires 'EnableDelayedExpansion' --
REM which can only be executed a maximum of 16 times before reaching the --
REM 'Maximum setlocal recursion level' (despite also executing 'DisableDelayedExpansion').
REM Also, within 'EnableDelayedExpansion' %%a will lose exclamation marks --
REM fortunately we no longer need %%a (for the current line) as it has been copied to string1.
REM For these reasons, the main string processing is done in a subroutine...
CALL :REPLACE_CHARS
)

ENDLOCAL
ECHO Done!
PAUSE
EXIT

:REPLACE_CHARS

REM Increment lines processed count...
SET /A LINES_COUNT=%LINES_COUNT%+1%

REM Enable delayed environment variable expansion --
REM so that the value of certain variables can be dynamically redefined at run time --
REM using !Variable! instead of %Variable% (or a combination)...
SETLOCAL EnableDelayedExpansion

REM Display progress...
ECHO Original Line !LINES_COUNT! ...!string1!...
REM At this point, string1 still contains the complete intact quoted string.

REM Ascertain whether preservation of original case is required...
IF "!CASE_CHOICE!" EQU "1" GOTO PRESERVE_CASE

REM Original case is not required to be preserved...

REM Convert all 'X's in the string (line) to 'Y's --
REM upper and lower-case 'X's will be converted to upper-case 'Y's.
SET string2=!string1:X=Y!
GOTO WRITE_LINE

REM Original case must be preserved...

:PRESERVE_CASE

REM Initialise an index for the current character position --
REM and an empty string to construct the converted line...
set j=0
set string2=

:Loop

REM One at a time, isolate each individual character in the string (line)...
set inchar=!string1:~%j%,1%!
IF "!inchar!END"=="END" GOTO :ExitLoop

REM Copy the current character for passing to the modified string (line)...
SET outchar=!inchar!

REM Convert 'X's to 'Y's -- preserving the original case...
IF "!inchar!"=="X" set outchar=Y
IF "!inchar!"=="x" set outchar=y

REM Construct the new string (line) by concatenating the current/modified character...
SET "string2=!string2!!outchar%!"

REM Increment the index for the next character position, and repeat...
SET /A j=!j!+1%
GOTO :Loop
:ExitLoop

:WRITE_LINE

REM Strip-off the leading/trailing quotes from the processed string (line) --
REM then write it to the Output File -- ensuring no spaces are added at end of line.
ECHO !string2:~1,-1!>> newfile.txt

REM Display progress...
ECHO Modified Line !LINES_COUNT! ...!string2!...

REM Disable delayed environment variable expansion.
SETLOCAL DisableDelayedExpansion

REM Return whence we came.
GOTO :EOFQuote
REM For each line of the Input File, string processing requires 'EnableDelayedExpansion' --
REM which can only be executed a maximum of 16 times before reaching the --
REM 'Maximum setlocal recursion level' (despite also executing 'DisableDelayedExpansion').

I'm not sure what you mean by this - you only enable delayed expansion once, at any point before the loop or other structure. You don't have to re-enable it for each line that is read from a file!



Isn't this better? Sooner or later if you are doing SERIOUS textfile processing you are going to need to look at something else. Visual Basic Script is present in every Windows installation these days.

Save as a .vbs file and run with

Cscript //nologo yourname.vbs


Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const FormatSystemDefault = -2, FormatUnicode = -1, FormatASCII = 0
ReadfileName ="Input.txt"
WriteFileName="Output.txt"
Wscript.echo "Read file..."
Set InputFile = fso.openTextFile (ReadFileName, ForReading, FormatASCII)
Set OutputFile = fso.openTextFile (WriteFileName, ForWriting, FormatASCII)
Do While Not InputFile.AtEndOfStream
InputLine = InputFile.readline
Wscript.Echo "Input " & InputLine
TempLine = InputLine
TempLine = Replace(TempLine, "X", "Y")
TempLine = Replace(TempLine, "x", "y")
OutputLine = TempLine
Wscript.Echo "Output " & OutputLine
OutputFile.WriteLine(OutputLine)
Loop
InputFile.Close
Outputfile.Close
Set fso = Nothing
Set Shell = Nothing