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.

1901.

Solve : Launching all the .bat files in a folder one after the other?

Answer»

Hi,

I need to run a bunch of actions one after the other. All of them are in a different .bat file, all in the same folder. I need to create a .bat file that will take a look at the .bat files in the folder, launch the first one (alphabetically), WAIT for it to complete, then it would move that .bat file to an archive folder, then look again in the batch folder in case a new .bat file was added while the first one was working, and then launch the first batch file it finds, until the folder is empty from batch files.

I know how to launch a batch file, I know how to move a batch file from one folder to another, the part I need help with is to have a batch file look in the folder for .bat files, and launch the first one. I know how to look in the folder with the dir command, but how can I tell it to launch the first one in the list?

Also, how can I tell it that when there isn't any .bat file left in the folder it must stop?I found a way to get closer to the solution, but there is still a problem.

I should work with something like this:
Code: [Select]FOR /R Batch/ %%p IN (*.bat) DO START /B /WAIT %%p
But the problem is that since the Batch folder is located in folder that contain spaces, when it tries to launch the .bat file it's not able to because it stops looking at the first space it finds, so it tries to launch "E:Documents" instead of E:Documents and Settings/..."

So I tried replacing %%p with "%%p"

But now instead of giving me an error message it writes in the dos windows this:
Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
Anyone would have a solution for that?I found the solution!!

It's because when you put your variable between "" it things that this is the title, so you just need to put whatever title you want in front of your variable.

Like this:
Code: [Select]FOR /R Batch/ %%p IN (*.bat) DO START /B /WAIT "TITLE" "%%p" Quote

put whatever title you want in front of your variable.

Such as an empty string (2 quote marks)



Code: [Select]FOR /R Batch/ %%p IN (*.bat) DO START /B /WAIT "" "%%p" Quote from: FausseFugue on July 02, 2008, 02:24:52 PM
I found the solution!!

Maybe I'm just tired but I fail to SEE how this single line of code is the solution to the original request.

Quote
FOR /R Batch/ %%p IN (*.bat) DO START /B /WAIT "" "%%p"

Where exactly is the logic that would:
Quote
then look again in the batch folder in case a new .bat file was added while the first one was working, and then launch the first batch file it finds, until the folder is empty from batch files.

Where is the logic that would:
Quote
then it would move that .bat file to an archive folder

Why is recursion used when all the batch files are in the same folder?

Why is start used instead of call?

Just curious.

Hi Sidewinder,

Actually I said that I found the solution because I found the solution to the part I mentionned was problematic in the first message, the rest I already knew how to do it.

About the part where it looks again in the folder, I need to figure it out, I don't know how to ask with bat code "is the folder empty from .bat files?".

Here is the full code I'm using, with the part where it moves the file:

Code: [Select]ECHO OFF

CD /d "%~dp0"


FOR /R Batch/ %%p IN (*.bat) DO (
START /B /WAIT "TITLE" "%%p"
MOVE /Y "%%p" "Batch Archive/")
About the call instead of start, I didn't know about the call command, I'm gonna look into that.

And about the recursion used... what is recursion exactly?

Thanks,This bit  of doggeral  may help you out. It rechecks the directory contents and uses redirection to INDICATE the directory is empty.

Code: [Select]echo off
cd /d c:\batch

:loop
for /f "tokens=* delims=" %%v in ('dir *.bat /b 2^>^&1') do (
if "%%p"=="File Not Found" goto :eof
call "%%p"
move /y "%%p" c:\batch\archive
)
goto loop

Feel free to change the directory names.

Recursion is a function that calls itself. Used in your posted code, it refers to walking down the directory tree, including all files and all FOLDERS within all folders. Example executing dir c:\ /a /s at a command prompt will list every file and folder on the c: drive. Some Windows commands have a switch for recursion where in most script languages the user must write the logic themselves.

 Thanks Sidewinder,

I'll check you code when I have a minute.

About the recursion, did you mean this line of code?:
Code: [Select]CD /d "%~dp0"
If that's what you meant, I'm using this because I'm launch the .bat file from a javascript. And it's actually the javascript that is creating the .bat file. And the problem with launching a .bat file from a javascript is that for some REASON the .bat file doesn't know where to place the current directory when it starts, so I need to tell it to use it's own directory.

Or maybe you meant the fact that my code didn't only look inside the Batch folder but also in subfolder, if that's what you meant, then, I did it that way because I didn't know how to do it another way. But I checked you code fast and it seems to solve that!

Thanks!Actually the recursion is in this statement (the R switch specifically):

Quote
FOR /R Batch/ %%p IN

The for command has more than a few variations. Check out for /? for details.

 Thanks for the help Sidewinder,

I checked the help on this site for the for command. It really help me understand what was going on. I had took the line of code I was using someplace else but I didn't know exactly what all those letters were for, but now it's much clearer. All my code seems good now. My little software is working perfectly.

Thank you!
1902.

Solve : Batch File Hangs After Program Launch?

Answer»

So the BATCH FILE launches a (.exe) and then does nothing unless I close that program. I KNOW I can make a batch file wait until the program is closed before it proceeds, but what WOULD cause this? Is there a way to force the file to PROCEED?Use the start command for example:

start Notepad

Type start /? at the prompt to see all the options.
Thanks. That works.

1903.

Solve : Standardizing Taskkill/Restart Script?

Answer»

This is something I am trying to figure out on my freetime, however it is work related.

What I want to do is have one script complete a set of tasks instead of having to manage multiply scripts ...


VSUSERVER
RBOXSERVER
VENGINE1
VENGINE2 ... etc, usually no more then six

Currently I have a script that runs on VENGINE# that will kill a running task named VENGINE, rename a file and then restarts, it is set to go off at about 4:00am, this same script can ALSO be run manually during BUSINESS hours and if it isn't around 4am it will not rename the file. This script is calling a VBS file that passes the enter key as when the application restarts if it has jobs to process it will prompt the user to re-enable the runs by clicking Yes.  In this environment, we have about 4 VSUSERVER's, an RBOXSERVER for each. and in most case about 6 VENGINE's for each VSUSERVER

What I want to do, I only want to have to manage 4 Scripts by having a script on the VSUSERVER that will kill the VENGINE process, rename the needed file like above, restart the application. By renaming the file, pressing enter shouldn't be needed. I know in dos taskkill will allow you to kill a remote process by its image name, but is there anything to allow you to restart a process remotely?

For those that like reading, below is my current code, if not possible, but you see something I am doing that would be easier a different way, by all means let me know if I can simplify something.

DOS is the primary thing I have been learning, but even my knowledge in that is extremely limit. Learning VB is something I've wanted to do, but finding the time with everything else is extremely time consuming, but please let me know your thoughts, thank you in advance.


In the execution folder I currently have a CHOICE.EXE, and a file called SLEEP.EXE

Code: [Select]Echo Off
Echo.
Echo.

set M=%DATE:~4,2%
set D=%DATE:~7,2%
set Y=%DATE:~10,4%

Set ini=

Set log=C:\vision\batlog
md %log%


Set IVDIR=
Set Root=

Set timetest1=4:30:00.00
Set timetest2=4:38:59.99

Rem ----------------------------------------------------------------------
Rem Samuel Simpson - 12-18-2007 - Issues/Support ... Create Facets Case, thanks
Rem Created to kill the Vengine process and restart it without user interaction
Rem Needs Choice.exe, Sleep.exe as well as passkey.wsf
Rem ----------------------------------------------------------------------

Echo.
Echo.

Rem ----------------------------------------------------------------------
Rem CHECK for VEngine install

if Exist "C:\Vision\Bin\VEngine.exe" Set IVDIR=C:\Vision\Bin\& Set Root=C:& Set log=C:\vision\batlog\restartlog.txt & Set ini=C:\vision\etc\VEstate.ini & MD C:\vision\batlog
rem Echo %IVDIR% & Echo %Root% & Echo %log% & Echo %ini% & Pause
if Exist "D:\Vision\Bin\VEngine.exe" Set IVDIR=D:\Vision\Bin\& Set Root=D:& Set log=D:\vision\batlog\restartlog.txt & Set ini=D:\vision\etc\VEstate.ini & MD D:\vision\batlog
rem Echo %IVDIR% & Echo %Root% & Echo %log% & Echo %ini% & Pause

Rem ----------------------------------------------------------------------

Echo. >>%log%
Echo ----------------------------------------------------------------- >>%log%
Echo %M%/%D%/%Y% %Time% Script Started. >>%log%

Rem Kill VEngine process if running.
Rem Echo Pause before kill for test & Pause
taskkill /F /IM VENGINE.EXE

Rem ----------------------------------------------------------------------
Rem This part of the file will take the VEstate file and rename it with a date stamp,
Rem only if there is not a file already renamed for that day.

:renameloop
if /I %time% GEQ %timetest1% goto next1
goto bypass
:next1
if /I %time% LEQ %timetest2% goto next2
goto bypass
:next2
cls
Echo Sleeping for 10 Seconds, please hold
Sleep 10
if not exist "%ini%.%M%%D%%Y%" rename "%ini%" "VEstate.ini.%M%%D%%Y%" & goto continue1
goto bypass
:continue1
if exist "D:\vision\etc\VEstate.ini.%M%%D%%Y%" Echo    %M%/%D%/%Y% %Time% Renamed VEstate.ini >>%log% & Echo %M%/%D%/%Y% %Time% Renamed VEstate.ini & goto continue2
goto renameloop

:bypass
Echo    %M%/%D%/%Y% %Time% Bypassed renaming VEstate.ini >>%log%
Echo %M%/%D%/%Y% %Time% Bypassed renaming VEstate.ini

Echo.
Echo.

Rem ----------------------------------------------------------------------

:Continue2
Echo.
Echo Please Hold
Title Restarting VEngine

choice /c1 /t:1,02 /n > nul

If Errorlevel 2 Pause & Echo Possible ERROR, Please try manual restart
If ErrorLevel 1 Goto StartVE
Goto End

Rem ----------------------------------------------------------------------
:StartVE
Echo.
cls
%Root%
if Exist %IVDIR%\VEngine.exe Start %IVDIR%\VEngine.exe & Goto Completed
Goto Failed
:Completed

Echo %M%/%D%/%Y% %Time% Restarting Vengine process >>%log%
Title Passing Key Press {Enter}
start passkey.wsf & goto END

Rem ----------------------------------------------------------------------
:End
exit

:Failed
Echo %M%/%D%/%Y% %Time% Restarting Vengine process Failed >>%log%
Start notepad %log% & Goto End
Passkey.wsf
Code: [Select]<package>

   <job id="vbs">

      <script language="VBScript">

         set WshShell = WScript.CreateObject("WScript.Shell")

WScript.Sleep 4000
         
WshShell.AppActivate ("VENGINE")

         WshShell.SendKeys "{Enter}"

      </script>

   </job>
</package>


1904.

Solve : Help with batch file please?

Answer»

Hi all, i am TRYING to create a bat file that simply runs gpupdate /force and then answers no (automatically) to logoff and closes automatically, i PRESUME this might be a common question but wondered if anyone can help me with the SCRIPTING for this.
currently have

ECHO ON
gpupdate /force
EXIT

many thanks what is the problem with your's.

try this:
Code: [Select]ECHO OFF
ECHO REFRESHING POLICY
ECHO.
GPUPDATE /force
end

The problem is that i need it to automatically say no to logoff and need it to exit after that.
It's ALMOST like i need the code to (n) enter then exit so it closes the DOS screen.
I need this for a vpn solution so it turns off the local firewall and drags the group policy down before logging into the vpn connection,simply cause we are having issues with time outs due to certain ports dropping on the local machines firewall.

Thank you though. Not all programs can take input from the pipe, but this may be worth a try:

Code: [Select]ECHO ON
echo N | gpupdate /force
EXIT

Good luck. 

1905.

Solve : issue with NETBEUI?

Answer»

I am trying to make a boot usb thumb DRIVE for use with ghosting and other things. So far I have it working up until I try and use the net command to map a network drive and then I GET an error message

ERROR 3659 Unable to load netbeui.

here is what I have so far.
Code: [Select]echo off
set pci0=
set pci1=
set pci2=

pciscan niclist.map
if errorlevel 1 goto _err1
if "%pci0%" == "" goto _none

device.com %cdrom%\pci\net\protman.dos /I:%cdrom%\pci\net\%pci0%
device.com %cdrom%\pci\net\dis_pkt.dos
device.com %cdrom%\pci\net\%pci0%\%pci0%.dos
%cdrom%\pci\net\netbind.com
IF %nchoice% == yes GOTO YES
CD\
ghost.bat
goto _end

:_err1
echo *** PCIScan returned an error...
echo Can not detect NIC. Please CHECK your system...
pause
goto _end

:_none
echo *** PCIScan did not locate your NIC:
echo Please CONTACT the developer of this
echo disc to have the NIC ADDED to the NICLIST.MAP file.
echo Here's a list of devices in your system.
echo.
pciscan -v
pause
goto _end

:YES
CD\
CD PCI\net

net start
Net USE Z: \\[computer name]\[drive]

pause
CD\
nghost.bat
goto _end

:_end

any ideas on what could be causing the error?

1906.

Solve : determine file status..?

Answer»

Hello Everyone
Wish someone can help me to fix this issue

my Problem is .. I have a batch file which is running for every 15min and every time checks if the specified file exists in the given path or not ..

but, its not checking if the file is a 100% copied file or not .. 

which means in real time.. when some one is copying  a new file with same name in to the same folder.. the its taking arround 2-5min to copy the file 

suppose the batch file is called in this duration.. the batch file is just checking if the file exists or not
but batch file donot know if the file is 100% copied file or not .. so my batch file is failing after executing few steps
so before proceeding to the next steps i want to check if the file copy is in progress or is it completed , or the file is 100% copied file
 
It means user is trying to copy the file into the directory and my batch file is trying to read the data from the copying file

how should I tell my batch file to findout if the file is completely copied file or copy in progress file

wish some one can suggest me the way in which I need to move Quote

so my batch file is failing after executing few steps
so before proceeding to the next steps i want to check if the file copy is in progress or is it completed

How is it failing? If you are getting a message on the console, you can process that message and take directed action.

Need more specific information. Its reading the file name  and the file exists but the file copy is in progress.
but my next line of the code says.. if file exists.. .started reading the data from file..
but as the file is not copied completely.. its failing when it is trying to read data from the file.

The whole problem occurs only when batch file gets executed when the file copy is  to the destination folder is in progress

how should I find out that file copy is completed or not

is there any way to findout ? Quote
Its reading the file name  and the file exists but the file copy is in progress.
but my next line of the code says.. if file exists.. .started reading the data from file..
but as the file is not copied completely.. its failing when it is trying to read data from the file.

What program are you USING to read from the file? I'm surprised the OS would allow opening a file that is opened for output by another process. Perhaps you could take action based on an error code produced by your program.

 I am writing in the batch file and using the batch file in SSIS package Quote
my Problem is .. I have a batch file which is running for every 15min and every time checks if the specified file exists in the given path or not ..

but, its not checking if the file is a 100% copied file or not ..

which means in real time.. when some one is copying  a new file with same name in to the same folder.. the its taking arround 2-5min to copy the file

Are you referring to SQL Server Integration Services? Is this on a network? Part of the problem may be that the copy is OVERWRITING the previous version. The NTFS index may reflect the attributes of the old file which might explain why the file exist test gives a false POSITIVE result.

Any chance you could move the copy to the SSIS batch file? You could then check if the copy was successful and run SSIS.

The Windows copy command runs INSIDE the command shell. Only under certain conditions would you be able to see if the copy command was in progress and even then it would not be with batch language.

You might also have the script that does the copy set an parameter in a file as to whether a copy operation was in progress or not. You SSIS batch file could query this parameter to determine if SSIS runs.

Good luck
1907.

Solve : Help: How Do I - Make A Spinning cursor & % 0-100 complete timer?

Answer»

This is for a Batch file:

I would LIKE to know what info is needed to make a spinning cursor this is for downloading...

echo.
echo Next STEP: Get SVN data
"%JFSVNBINDIR%\svn.exe" checkout http://wii-softchip.googlecode.com/svn/trunk/ wii-softchip
"%JFSVNBINDIR%\svnversion.exe" wii-softchip>%TEMP%\SOFTCHIPSVN.VER
set /P JFSOFTCHIPSVNVER=<%TEMP%\SOFTCHIPSVN.VER

So somewhere in there I would like to put a % completed timer or something...

And a Spinning Cursor processing data please wait... " Spinning Cursor Here"

How do I do This? I want both in different places but still need to know howto....

Thanks for any help or a link on howto make this GodSpeedThe cursor is a Windows contraption of which the command shell (READ: batch code) knows nothing about.

Progress bars are notoriously difficult to CALCULATE, however VBScript can use Internet Explorer to display either a simple dialog box or one with an animated GIF.

This ARTICLE from the Scripting Guys should explain all.

Good luck.

1908.

Solve : User Input??

Answer»

I'm trying to make a batch file that copies my firefox bookmarks to my desktop. I'd like to be able to use this with any computer, so I'm trying to find a way to either autodetect which user is logged in, or have an input area in the batch file for me to type a username.

So far this is my code:

Code: [SELECT]ECHO OFF
Title Copying Firefox Bookmarks
ECHO Are you sure you WISH to copy Firefox's bookmarks?
ECHO Y/N?
SET /p play=
IF %play% EQU y GOTO start
IF %play% EQU n EXIT
:start
ECHO This program is currently set to copy bookmarks for user: (username) to the desktop.
ECHO To change this, edit this code and change "(username)" to the correct username.
PAUSE
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
XCOPY "C:\Documents and Settings\(username)\Application Data\Mozilla\Firefox\Profiles\e0nu0mbl.default\bookmarks.html" "C:\Documents and Settings\(username)\Desktop"
PING localhost n -10 >nul
CLS
ECHO Bookmarks have been copied.
PING localhost n -10 >nul
PAUSE
Note that where it says (username) it actually has my username.
I'm trying to find a way to make SOMETHING like "Please Input Username: _" that will automatically alter the copy/save locations.

Anyone got something that will help?

By the way, I might want an approval thing that says something like

"Files will be copied to C:\Documents and Settings\(username)\Desktop, is this okay?
Y/N"

That last bit isn't necessary, but I would like it. You can use the variable name %username% which will resolve to the current user.

Quote

I'd like to be able to use this with any computer

The e0nu0mbl.default directory is unique to your machine. Other machines will have different values. You may have to extract the subfolder names from C:\Documents and Settings\Username\Application Data\Mozilla\Firefox\Profiles to compute the actual profile directory name.

 

Cool, thanks  What is the need for this?
Code: [Select]ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul Quote from: JACOB on November 15, 2008, 10:28:19 AM
What is the need for this?
Code: [Select]ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks.
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks..
PING localhost n -.5 >nul
CLS
ECHO Copying Bookmarks...
PING localhost n -.5 >nul

Makes a cool light show for when you're stoned?

Quote from: Dias de verano on November 15, 2008, 11:47:19 AM
Makes a cool light show for when you're stoned?
LOL, sounds great.
1909.

Solve : Escape characters in for loop delimiter?

Answer»

Hi,

I've searched everywhere without luck for the answer to how to escape a double quote as a delimiter in the for /F "tokens=1* delims=:\=" etc command syntax. All the delimiters currently listed are valid and work, but the " is also used as a delimiter in the input file, and I can't figure out how to include it in my delimiters.

Thanks, in ADVANCE,
KarenI tried using the escape character (^) but the for command choked and spit it back out. Any chance you can use %~ notation to remove the quotes from a token.

This would be easier if we could see your code and a sample of the data.

 Here is the script:

for /F "usebackq tokens=1-6 delims=:\=" %%A in (
`findstr /C:"\"ORACLE_HOME\"=" c:\temp\tns_loc.txt`
) do (
 set drvltr=%%B
REM set drvltr=%drvltr:~2,1% (this didn't work. the " confuses it)
 set dir4=%%F
 echo %%B %%C %%D %%E %%F
 echo %%B %drvltr%
 echo %%F %dir4%
)

Here is the record in the file:
"ORACLE_HOME"="C:\\oracle\\product\\10.2.0\\client_1"

Here is the current output:
"C oracle product 10.2.0 client_1"
"C        <--- Notice, %drvltr% is blank
client_1" client_1"

The first token is ignored. The second token comes up as "C and the sixth token comes up as client_1". I need to find a way to strip the ", and the set var doesn't work. So, I thought if I could specify the " as a delimiter, I could remove it that way. However, because the double quote is used to contain the tokens option syntax, I have to escape it somehow. I tried doubling up on the double quote "", but that made no difference. The normal escape character \ is already specified as a delimiter and it's working fine.
Okay. I've decided I'm losing my mind. The following code works consistently and properly when you execute it from the command line:
set drvltr="C
set drvltr2=%drvltr:~1%
set drv
drvltr="C
drvltr2=C

When I run the same code in a bat file two times in a row (with no changes at all):
Execution one: (new session)
C:\temp>(
set drvltr="C
 set drvltr2=~1
 set dir4=client_1"
 echo "C oracle product 10.2.0 client_1"
 echo "C
 echo client_1"
)
"C oracle product 10.2.0 client_1"
"C
client_1"

C:\temp>set dr
drvltr="C
drvltr2=~1




Execution two: (same session)
C:\temp>(
set drvltr="C
 set drvltr2=C
 set dir4=client_1"
 echo "C oracle product 10.2.0 client_1"
 echo "C ~1
 echo client_1" client_1"
)
"C oracle product 10.2.0 client_1"
"C ~1
client_1" client_1"

C:\temp>set dr
drvltr="C
drvltr2=C


Why would it take two executions to result in the variable having the proper value? I figured it out, finally:

I moved the second set and the echo statements out of the for loop:

for /F "usebackq tokens=1-6 delims=:\=" %%A in (
`findstr /C:"\"ORACLE_HOME\"=" c:\temp\tns_loc.txt`) do (
 set drvltr=%%B
 set dir4=%%F
)

 set drvltr2=%drvltr:~1%

 echo %%B %%C %%D %%E %%F
 echo %%B %drvltr2%
 echo %%F %dir4%

However, since the possiblity exists that this file will have more than one oracle_home record in it and I need to process both, I have to find some way to manage this. Perhaps by executing a sub-routine outside the loop and then returning into the loop?


Sometimes it's easier to break down the task rather than do everything at once.

Code: [Select]echo off
for /F "tokens=1-2 delims==" %%A in ('findstr "ORACLE_HOME" c:\temp\tns_loc.txt') do (
echo drive: %%~dB
echo path: %%~pB
echo file: %%~nB
for /f "tokens=1-5 delims=\" %%I in ("%%~B") do (
echo drive: %%I
echo top level: %%J
echo subfolder: %%K
echo subfolder: %%L
echo file: %%M
)
)

Good luck. 
Here is the final code: It works on single and multiple records in the file.


REM retrieve all subkeys for the ORACLE installation from the
REM Windows registry and subset entries with "ORACLE_HOME"
REM to a temp file

 regedit /e c:\temp\tns_location.txt  "HKEY_LOCAL_MACHINE\Software\ORACLE"
 find "ORACLE_HOME" c:\temp\tns_location.txt > c:\temp\tns_loc.txt

REM there are header rows in the file
REM read through the rows in the resulting file until we reach the row that has data in it
REM test the record to see if it has data
REM parse the record for the data values we seek

for /F "tokens=1-4 delims=/- " %%S in ('date/T') do set DATE=%%V%%T%%U

echo %DATE%

echo "for loop"

for /F "usebackq tokens=1-6 delims=:\=" %%A in (
`findstr /C:"\"ORACLE_HOME\"=" c:\temp\tns_loc.txt`) do (
 set drvltr=%%B
 set dir1=%%C
 set dir2=%%D
 set dir3=%%E
 set dir4=%%F

 echo %%B %%C %%D %%E %%F
 echo %drvltr% %dir1% %dir2% %dir3% %dir4%
 )

 set drvltr2=%drvltr:~1%:
 echo %drvltr2% %dir1% %dir2% %dir3% %dir4%
 set ORACLE_HOME=%drvltr2%\%dir1%\%dir2%\%dir3%\%dir4%
 ECHO %ORACLE_HOME%
 cd %ORACLE_HOME%\NETWORK\ADMIN
 copy tnsnames.ora tnsnames.ora.bkp%DATE%
 copy c:\temp\tnsnames.ora %ORACLE_HOME%\NETWORK\ADMIN

:eofWhy not use the = as the delimiter and dequote each token using the ~ modifier?

Since the 2nd token appears to be a valid path you can use the ~d ~p ~n modifiers
to get the drive letter, path and folder name if you want those

Code: [Select]for /f "tokens=1,2 delims==" %%S in (token.txt) do (
    echo token 1 is          %%S
    echo token 2 is          %%T
    echo dequoted token 1 is %%~S
    echo dequoted token 2 is %%~T
    echo drive letter  is    %%~dT
    echo path is             %%~pT
    echo name is             %%~NT
    )

Token.txt

Code: [Select]"ORACLE_HOME"="C:\\oracle\\product\\10.2.0\\client_1"
Code output

Code: [Select]token 1 is          "ORACLE_HOME"
token 2 is          "C:\\oracle\\product\\10.2.0\\client_1"
dequoted token 1 is ORACLE_HOME
dequoted token 2 is C:\\oracle\\product\\10.2.0\\client_1
drive letter  is    C:
path is             \oracle\product\10.2.0\
name is             client_1

Well, actually, client_1 is the  lowest folder in the path name, but that's not a huge ISSUE.

I guess EITHER way would work. But I was slogging through this without any help to speak of, and that's what I came up with. Quote from: kscarroll54 on November 14, 2008, 12:07:35 PM

Well, actually, client_1 is the  lowest folder in the path name, but that's not a huge issue.

It is the folder name, the last element in the full path, and is extracted using the ~n variable modifier, which is called the "name" modifier in the FOR documentation.
1910.

Solve : icacls command in Windows Vista?

Answer»

Hi All,

I've RECENTLY got a new computer with WINDOWS Vista on it and had some problems accessing the files I transferred  from my old computer (Windows XP).

Though I could change the ownership of all the transferred folder along with all of the files and sub-folders within it, this didn't grant my username (which is defined as Administrator) permission to access these files, and that has to be done separately for each file. As there are a LARGE number of files, that is hardly a practical solution.

I was suggested to run command PROMPT as an administrator and after browsing to the relevant folder type:
icacls . /grant USER:(OI)(CI)(F) /L /T /Q
(Where USER is my username) . I did that, but I keep getting that "USER:(OI)(CI)(F)" is an 'invalid parameter' .

Any idea why? (I of course changed 'user' to my username, and even tried 'Users' so it will apply to all the users of the computer)

Thank you for any suggestions!!

R.Just issue the file or folder NAME as a wild card (using *) and it will work.

Run Dos as administrator
 To do so click start, type "cmd", right click on the icon that appears on the top and click on 'Run as administrator. This way you'll have DOS running for the administrator. From there here is an example of icacls command with a wildcard:
If the file name is " VirusesAndSpyware" or the folder name is "Spyware terminator" just go:

icacls  Viru*  /grant  John15:f 
(With "John15" being the name of the administrator you logged on the computer with when you booted windows)

The second case, with the folder being "spyware terminator" could go:

icacls  spyw*  /grant  john15:f


By the way, remember you have to take ownership 1st, before doing the icacls command. To do so, still at the dos prompt, if the file is VirusesAndSpyware, you go:

takeown  /f  Viru* /a  /r
or for the directory "spyware terminator":
takeown  /f  Spy* /a  /r

Enjoy.

1911.

Solve : Does For loop have a "return code"??

Answer»

I haven't been able to find anything online, but I'm using a for loop to step through records in a file. Is there a variable I can set/test to tell me when I've run out of records?

Alternatively, my problem is being caused by the necessity to go out of the loop to execute some code and then come back into the loop.  If there's a way to do that, I would appreciate knowing it.FOR %variable IN (set) DO command [command-parameters]

When the FOR command finishes, that means that set has been exhausted. (I.E. every element has been examined).

for /f "delims=," %%R in (record.txt) do (
    some command
    some other command
    etc.
    )
REM When you get here, there ain't no records left in the file.

What do you mean about going out of the loop to execute some code and then coming back? Please post some example code.

 In the event that anyone cares, here is the code that is finally working. It works whether there is one record or more than one record in the file:
(I wrote this to push tnsnames.ora updates to DESKTOPS without knowing what the path would be to the appropriate folder)

REM retrieve all subkeys for the ORACLE INSTALLATION from the
REM Windows registry and subset entries with "ORACLE_HOME"
REM to a temp file

 regedit /e C:\temp\tns_location.txt  "HKEY_LOCAL_MACHINE\Software\ORACLE"
 find "ORACLE_HOME" c:\temp\tns_location.txt > c:\temp\tns_loc.txt

REM there are header rows in the file
REM read through the rows in the resulting file until we reach the row that has data in it
REM test the record to see if it has data
REM parse the record for the data values we seek

for /F "tokens=1-4 delims=/- " %%S in ('date/T') do set DATE=%%V%%T%%U

echo %DATE%

echo "for loop"

for /F "usebackq tokens=1-6 delims=:\=" %%A in (
`FINDSTR /C:"\"ORACLE_HOME\"=" c:\temp\tns_loc.txt`) do (
 set drvltr=%%B
 set dir1=%%C
 set dir2=%%D
 set dir3=%%E
 set dir4=%%F

 echo %%B %%C %%D %%E %%F
 echo %drvltr% %dir1% %dir2% %dir3% %dir4%
 )

 set drvltr2=%drvltr:~1%:
 echo %drvltr2% %dir1% %dir2% %dir3% %dir4%
 set ORACLE_HOME=%drvltr2%\%dir1%\%dir2%\%dir3%\%dir4%
 ECHO %ORACLE_HOME%
 cd %ORACLE_HOME%\NETWORK\ADMIN
 copy tnsnames.ora tnsnames.ora.bkp%DATE%
 copy c:\temp\tnsnames.ora %ORACLE_HOME%\NETWORK\ADMIN

:eof

1912.

Solve : Linux to Windows porting - Need information on batch scripts?

Answer»

Hi,

I ma trying to port my application from Linux to Windows environment. I have used many shell scripts and makefiles for my system building.

I WANT to know whether every operation done in shell scripts can be ported to a windows batch file. The kind of operations I am looking for are

1. USING for, while loops
2. Declaring functions and local variables
3. Need to know whether the settings (env. variables) made from a batch file is sustained in a cmd window. For example, if i start a cmd window and run a batch file, whether the settings made from the batch files remains after batch file execution.

Regards,
Lakshmy
1. Using for, while loops

Batch language has a for command which allows operations over a collection, or thru an iteration. The first operates like a foreach/next loop; the second operates like a for x = y to z by c. There is a goto command to force an early exit from a loop.

2. Declaring functions and local variables

There are no functions in batch code. The closest would be either internal or external subroutines which are executed by a call mechanism. PARAMETERS are passed by reference. Variables are global (SEE #3 below).

3. Need to know whether the settings (env. variables) made from a batch file is sustained in a cmd window. For example, if i start a cmd window and run a batch file, whether the settings made from the batch files remains after batch file execution.

Variables are sustained for the life of the command window session unless otherwise localized by a setlocal statement. Variables created after the setlocal statement live until a endlocal statement is encountered or the batch file ends, whichever comes first. Batch files cannot makes permanent changes to the environment.

Hope this helps. 

1913.

Solve : Log For xcopy batch file?

Answer»

Hi All,

I want to have a log of the below batch script i wrote and can't SEEM to find a way to create it.

start /wait /b xcopy "z:\*.id" "c:\notes\data" /d /L /y >> "C:\Documents and Settings\Administrator\Desktop\ID_Log.txt"

echo. |time |find "current" >> log
echo. |date |find "current" >> log


I have managed to get the FILES that are copied into a log file, but i would like have the output of the batch file with a date stamp saved into a log file.

please keep in mind this is my first ever attempt to WRITING a batch script, i am open to any suggestions. Perhpas my approach is WRONG or there is a better way of doing this.

Thanks in advance for any assistance or tips.Using start /wait is only helpful when the started task runs in it's own window and there is a need for the batch file to wait. Otherwise, running commands in-line accomplishes the same thing without wasting resources or adding complexity.

Code: [Select]xcopy "z:\*.id" "c:\notes\data" /d /L /y >> "C:\Documents and Settings\Administrator\Desktop\ID_Log.txt"

echo. |time |find "current" >> "C:\Documents and Settings\Administrator\Desktop\ID_Log.txt"
echo. |date |find "current" >> "C:\Documents and Settings\Administrator\Desktop\ID_Log.txt"

Note that the XCOPY will append the log to any existing log. If you wish to create a new log each time you run your file, REPLACE >> with > on the XCOPY line.

Good luck. 

1914.

Solve : command to find the file size?

Answer»

Hii
Can some tell me how to write code for the below requirement in a BATCH file

 1>get the current size of  file.
 2> hold the current size in a variable
 3> wait for few secs
 4>again get the file size and hold in another variable 
 5> now compare the both the variables
 6> if size is same proceed else repeat the loop


I want to write this code in a batch file can some tell me how to write this

echo off
set filename=D:\folder\subfolder\filename.ext
set seconds=60
for %%S in ("%filename%") do set /a filesize1=%%~zS
:loop
ping -n %seconds% 127.0.0.1 >nul
for %%S in ("%filename%") do set /a filesize2=%%~zS
if "%filesize1%" NEQ "%filesize2%" GOTO loop

Hi
Thanks for the reply but can plz explain me what
ping -n %seconds% 127.0.0.1 >nul
line is doing ..
do I need to change this when  I move from one system to another
I very new to batch files hence.. Quote from: Fire_Hope on November 13, 2008, 11:50:46 AM

plz explain me what
ping -n %seconds% 127.0.0.1 >nul
line is doing ..

It uses the ping command to create a time delay.

use ping /? to find out about the command.

Quote
do I need to change this when  I move from one system to another

No.
Hii
I tried the code which you mentioned
but its giving me error as Missing Operand.
and when I turned on the Echo
its showing me the following lines

C:\>set /a filesize2=
Missing operand.

C:\>if "" NEQ "" goto loop

can you tell me where the problem is ??the drive letter, path, filename are pointing to a non existent file.

So.. can't I use this code to find the file info on another system(not a LOCAL drive) , 'coz the location at which I have the file is not local
I am accessing the file like this
 \\mystoragebox\webpages\info\data.txt

when I tried with some thing in my D Drive or so .. its working but when I try for the path i mentioned, its failing

how should I make it working for the file on remote box



1915.

Solve : Using FINDSTR to search for " in a file?

Answer»

I am running through debugging some code and I have come across several scripts that are in use where there is an issue with some of the VARIABLE declarations are missing a ". It is a proprietary scripting language based on BASIC, and I am using Windows XP's FINDSTR command to find all of the lines of code that contain ". Here is where I am so far:

quotefinder.bat:
Code: [SELECT]findstr /N /G:quote.txt \\remote\c-drive\testenvironment\%1 >temp.txt
quote.txt:
Code: [Select]"
This is returning temp.txt containing every line that contains any ". How would I go about elminating all of the lines that have an even number of " so that I can only see the lines that have an odd number of ", which would show me where the " errors are happening? Right now I am thinking about creating a file:

quoteclose.txt:
Code: [Select]".*"
If I understand CORRECTLY, this will give me all of the lines that contain PAIRS of quotes, and if so, I should be able to add this to quotefinder.bat:

Code: [Select]findstr /N /G:quoteclose.txt \\remote\c-drive\testenvironment\%1 >temp2.txt
And then from there work out my best OPTION to compare the two files and remove all lines duplicated from the two. I don't expect to have to use this batch file often, however, it will probably be run on more script files than I can even count at the moment as a debugging tool if I can get this working.
Try as I might, I couldn't figure out where batch code would store the match count. Decided to give you a VBScript solution instead:

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

Set fso = CreateObject("Scripting.FileSystemObject")
Set objRE = CreateObject("VBScript.RegExp")
objRE.Global     = True
objRE.IgnoreCase = True
objRE.Pattern    = "\" & Chr(34)

Set f = fso.OpenTextFile("\\remote\c-drive\testenvironment\filename.ext", ForReading)
Set k = fso.OpenTextFile("c:\temp2.txt", ForWriting, True)

Do While f.AtEndOfStream = False
str = f.ReadLine
Set colMatches = objRE.Execute(str)
If colMatches.Count Mod 2 = 1 Then k.WriteLine str
Loop
f.Close
k.Close

Save the file with a vbs extension and run from a command prompt as cscript scriptname.vbs. You may have to adjust the paths and file names.

Good luck. OK, it looks like that VBS gives me most of what I needed. Now what I need is what to add to this script so the output shows me what line numbers on the input file I need to look at. I haven't used much VBS, and the system I am maintaining is rather archaic, so most tools that are at my disposal are homebrew. This being one of those instances where a syntax checker would be nice...  I tried to make the output look like the findstr output.

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

Set fso = CreateObject("Scripting.FileSystemObject")
Set objRE = CreateObject("VBScript.RegExp")
objRE.Global     = True
objRE.IgnoreCase = True
objRE.Pattern    = "\" & Chr(34)

Set f = fso.OpenTextFile("\\remote\c-drive\testenvironment\filename.ext", ForReading)
Set k = fso.OpenTextFile("c:\temp2.txt", ForWriting, True)

lines = 0
Do While f.AtEndOfStream = False
str = f.ReadLine
lines = lines + 1
Set colMatches = objRE.Execute(str)
If colMatches.Count Mod 2 = 1 Then k.WriteLine lines & ":" & str
Loop
f.Close
k.Close

Good luck.

1916.

Solve : batch file - append, backup and some checks?

Answer»

The code was tested with the file BLURBS you posted. I may have goofed the NUMBERS on the set STATEMENTS but you can adjust them.

Previously I misstated that the numbers on the set statements represent offset,position. Actually they represent offset,LENGTH with offset being zero-based. Sorry for any confusion.

Code: [Select]:log
  for /f "tokens=* delims=" %%i in (%1) do (
set pfx=%1
set pfx=!pfx:~0,3!
set str=%%i

if /i !pfx! EQU soc set id=!str:~12,6!
if /i !pfx! EQU inv set id=!str:~26,25!

if not defined holdid set holdid=
if not !id! EQU !holdid! (
echo !id! >> log.txt
set holdid=!id!
)
)
exit

I assume you've searched the database extension on the NET. Even simple text files can be accessed with the Jet Provider (OLEDB).

Good luck. 

1917.

Solve : com1 communication?

Answer»

hi there, i am trying to get 2 computers to talk to each other via com1 in dos...

at this stage i am just trying to verify that communication has been sent....

to send something to com1 i am trying

Code: [Select]
copy test.txt &GT; COM1 :


which "appears" to be working (SENDING ) , i have hooked up the other machine with some serial port monitoring software and i get no response, or no recognition that something has been sent on com1

i was WONDERING was there anyway in dos to confirm that something has been received on the second machine via com1 ?

thanks

Which version of Dos are you using?

Your OS is listed as Win XP, if you are trying to output to the Com ports using the Command Prompt window I don't think you will be successful.   For security reasons NT operating systems protect ports.   As you will know the Command Prompt screen is just another window running in the Windows system, true dos does not exist in NT based systems.

You might be ABLE to run PortTalk, see here..

Good luck.

Edit: & welcome to the CH forums.When you say DOS, do you mean DOS 6.2 (or earlier) or are you running windows

If running 6.22, it comes with a handy utility called Interlnk / Intersvr which sets up the external machine as a drive (or drives)

I assume you know to join them with the right type of cable (null-modem or crossover I think they are) -- I always USED the parallel port

Graham

1918.

Solve : Detect a Program Has Started?

Answer»

Is there a DOS command that detects if a program has started?

I'm attempting to perfect a program that automatically closes Internet Explorer whenever it opens. This isn't for harmful use, don't worry. I use Mozilla Firefox, and get sick of spyware that I can't seem to delete opening up Internet Explorer.

Anyway, so far I have this:

Code: [Select]ECHO OFF
:start
tskill iexplore
ping localhost -n 5 >nul
CLS
ping localhost -n 10 >nul
GOTO start

As you can see, it has to work fairly frequently to be effective. If anyone has a code that detects when a program initiates, please post it here.

Many thanks,

-Jake

Note: Not sure if this makes a difference, but I have this set up so that it doesn't open a visible window while its running. I'm thinking something along the lines of using the "IF" command to detect if Internet Explorer is running, and then terminating it.

So how can I make it look for the iexplore.exe process? Use tasklist


TASKLIST [/S system [/U username [/P [password]]]]
         [/M [module] | /SVC | /V] [/FI FILTER] [/FO format] [/NH]

DESCRIPTION:
    This command line tool displays a list of application(s) and
    associated task(s)/process(es) currently running on either a local or
    remote system.

Parameter List:
   /S     system           Specifies the remote system to connect to.

   /U     [domain\]user    Specifies the user context under which
                           the command should execute.

   /P     [password]       Specifies the password for the given
                           user context. Prompts for input if omitted.

   /M     [module]         Lists all tasks that have DLL modules loaded
                           in them that match the given pattern name.
                           If the module name is not specified,
                           displays all modules loaded by each task.

   /SVC                    Displays services in each process.

   /V                      Specifies that the verbose information
                           is to be displayed.

   /FI    filter           Displays a set of tasks that match a
                           given criteria specified by the filter.

   /FO    format           Specifies the output format.
                           Valid values: "TABLE", "LIST", "CSV".

   /NH                     Specifies that the "Column Header" should
                           not be displayed in the output.
                           Valid only for "TABLE" and "CSV" formats.

   /?                      Displays this HELP/usage.

Filters:
    Filter Name     Valid Operators           Valid Value(s)
    -----------     ---------------           --------------
    STATUS          eq, ne                    RUNNING | NOT RESPONDING
    IMAGENAME       eq, ne                    Image name
    PID             eq, ne, gt, lt, ge, le    PID value
    SESSION         eq, ne, gt, lt, ge, le    Session NUMBER
    SESSIONNAME     eq, ne                    Session name
    CPUTIME         eq, ne, gt, lt, ge, le    CPU time in the format
                                              of hh:mm:ss.
                                              hh - hours,
                                              mm - minutes, ss - seconds
    MEMUSAGE        eq, ne, gt, lt, ge, le    Memory usage in KB
    USERNAME        eq, ne                    User name in [domain\]user
                                              format
    SERVICES        eq, ne                    Service name
    WINDOWTITLE     eq, ne                    Window title
    MODULES         eq, ne                    DLL name

Examples:
    TASKLIST
    TASKLIST /M
    TASKLIST /V
    TASKLIST /SVC
    TASKLIST /M wbem*
    TASKLIST /S system /FO LIST
    TASKLIST /S system /U domain\username /FO CSV /NH
    TASKLIST /S system /U username /P password /FO TABLE /NH
    TASKLIST /FI "USERNAME ne NT AUTHORITY\SYSTEM" /FI "STATUS eq running"


If you need more specific help, I'll give it later. But I'm at school right now.

1919.

Solve : Users Temp folder (local settings) change depending when logging on to server.?

Answer»

Depending on when a user logging on to the server the user gets an ID number and this number gets into the temp folder as a subfolder name, EXAMPLE:
"C:\Documents and Settings\%username%\Local Settings\Temp\1" (if the user is the first one to logging in to the server) Next user will get "ID 2" etc. When user is logging on and off during the day this ID number will change every time they LOGGED in. I have a batch file that is searching this users folder and I have to check the temp folder and its subfolder (or going via the taskmanager in the user WINDOW) then edit the batch file to get the correct folder in the "Local Settings\temp"

Is there a way to do this without editing the batch every time?

COPY C:\"Documents and Settings"\%username%\"Local Settings"\Temp\1\Map*.* (sometimes it can be "1" or "2" or "3" etc, depending on when logging in and how many users are logged in for the moment)

RegardsCould there be another solution to it?
Is it possible to copy all file names that has the ~Map*.* under the usernames temp folder and its subfolders?

Copy C:\"Documents and Settings"\%username%\"Local Settings"\Temp\"INCLUDING subfolders"\that has filenames with ~Map*.*

Is this possible?

Regards

1920.

Solve : How to write Ping Commands to output file?

Answer»

Help I need to write PING and TRACERT to an output FILE.
However when I run my Batch file the output is on a SINGLE line

cd\

echo This is a comment >> logfile.txt
echo The DATE today is %date% >> logfile.txt
echo The time now is %time% >> logfile.txt
echo  >> logfile.txt
echo off
ping 155.45.116.250 >> logfile.txt
ping xxx.xx.xxx.123 >> logfile.txt
tracert xxx.xx.xxx.123 >> logfile.txt
tracert xxx.xx.xxx.234 >> logfile.txt
tracert xxx.xx.xxx.234 >> logfile.txt
exit

Does anyone know how to do this.
Any information will be appreciated.
To get a BLANK line use Code: [SELECT]echo. after each command to seperate them out.

FB Code: [Select]cd\

echo This is a comment >> logfile.txt
echo The date today is %date% >> logfile.txt
echo The time now is %time% >> logfile.txt
echo.  >> logfile.txt
echo off
ping 155.45.116.250 >> logfile.txt
ping xxx.xx.xxx.123 >> logfile.txt
tracert xxx.xx.xxx.123 >> logfile.txt
tracert xxx.xx.xxx.234 >> logfile.txt
tracert xxx.xx.xxx.234 >> logfile.txt
exit

There is nothing wrong with your code. As per the previous post, I added a dot to the
echo.  >> logfile.txt line.

Quote

However when I run my Batch file the output is on a single line

What are you using to view your output file?
1921.

Solve : How to open DOS 6 DoubleSpace floppies on Windows XP??

Answer»

I have some old, compressed AutoCad files on floppies by MS-DOS 6 DoubleSpace. Is there a WAY to open these files with Windows XP? All I can get is a "Read This"message. I found some original DOS 6.22 INSTALLATION floppies. Is there a way to INSTALL the original DOS program so that it does not screw up my COMPUTER? I have a remote hard drive that I can USE. Thanks.
 
WJW

1922.

Solve : Can a batch file be made into a custom toolbar button??

Answer»

I would LIKE one of the batch FILE I use most of added in my “windows EXPLORER” as a button that can be add to my Custom TOOLBAR. Can this be done?
I’m using XP.

Can ANYONE help?
 Double post.  Please use your other thread.

1923.

Solve : copy from drive with password?

Answer»

Hi everyone - I'm new to batch files and need some help copying files from a folder that has a password associated with it.

I am trying to copy all files from an ftp://FTP://SFTP.URL.COM to a \\dir\project\folder

I have tried cd to the ftp site but that doesn't work.  Any ideas?  Can I pass a user name and password with it?  will xcopy work once I get in?

Any help is appreciated!In addition to your batch file, it might be easier to setup a FTP script. FTP is a shell program with it's own INSTRUCTION set.

Quote

Can I pass a user name and password with it?  will xcopy work once I get in?

Name and password, Yes. XCOPY, No.

This link may help you out.

Good luck. Wow!  That is very helpful!  So now I have a script that launches the FTP script to get all the files in the directory and then DELETES everything.  But...what if a user posts a new file while I am getting the others?  Is there a way to delete the FTP files only if they have a TIMESTAMP before I started the get? Quote
But...what if a user posts a new file while I am getting the others?  Is there a way to delete the FTP files only if they have a timestamp before I started the get?

You might need a smarter FTP client than the one Windows provides.

Do all the files have the same extension? If so you may be able to change the extension of all the AVAILABLE files, use MGET *.ext to download all the files with the new extention, then use mdelete *.ext to delete the files. Any file not named with the new extension would not get processed until the next cycle.

You might also get a dir list from the remote computer, then download and delete each file by name.

Good luck.
1924.

Solve : HELP: move files into folders based on file prefix?

Answer»

I've got a directory of 7,000 images organized into 300 groups based on numerical prefixes in ONE FOLDER:

0001-file_a.jpg
0001-file_b.jpg
0001-file_c.jpg

0002-file_a.jpg

0003-file_a.jpg
0003-file_b.jpg

I NEED to get all these files into a folder structure based on their prefix i.e. all the 0001 jpg's into an 0001 folder

any ideas? MUCH APPRECIATED!!!!!!!!!!!

--- revision
I know the folders can be made/named quickly using any folder creating program, but curious if this can be done EASILY in dos also. Moving the files into the directories is the main obstacle. Thanks!This may help you out:

Code: [Select]echo off
setlocal enabledelayedexpansion
for /F "tokens=* delims=" %%x in ('dir /b *.jpg') do (
set fldr=%%x
set fldr=!fldr:~0,4!
if not exist !fldr! md !fldr!
copy %%x !fldr!
)

Batch file should be run from same directory where the jpg files are. Note: as a precaution used copy instead of move. If you're satisfied with the results you can delete the jpg files with del *.jpg

Paths can be  added to the code as appropriate. 
THANK YOU THANK YOU THANK YOU

that was awesome.

All in total, you just saved me from manually organizing over 33,000 DOCUMENTS.

1925.

Solve : Standard commands lost after running batch file?

Answer»

After running a BATCH file I find that I can not USE STANDARD commands like xcopy or help.What was the batch file?

What Operating System?Two very good QUESTIONS, there, Dude, and may I suggest a third?

What do you see when you type PATH at the command prompt?

1926.

Solve : checking a user input is empty?

Answer»

Hello,
I have written this small batch file to ask the username
It should not allow him to go further if he dont provide username.
I have written this to do the same.
but its not working.
could you please let me know where i made the mistake.

echo off
:uname
SET /P username=Please enter your username:

IF %username% == "" GOTO uname
echo entered usernameYou made 2 mistakes

1. in 3rd line there should be quotes around %username%
2. in 4th  line there should be percent signs around username

Like this

echo off
:uname
SET /P username=Please enter your username:
IF "%username%"=="" GOTO uname
echo entered %username%I have modified the bat file to correct the two mistakes.
Still it is not prompting me if i dont provide any input. i am just typing enter button.
Then bat file execution is getting completed. But it should prompt me to enter username.
I am using Windows 2000.

echo off
:uname
SET /P username=Please enter your username:

IF "%username%" == "" GOTO uname
echo entered %username%

Quote from: Dias de verano on NOVEMBER 06, 2008, 12:18:46 AM

You made 2 mistakes

1. in 3rd line there should be quotes around %username%
2. in 4th  line there should be percent signs around username

Like this

echo off
:uname
SET /P username=Please enter your username:
IF "%username%"=="" GOTO uname
echo entered %username%
you need to reset the %username% vaule otherwise it'll remember what you entered last time:

Code: [Select]set username=
set /p username=Please enter username:

FBHello,
Still same problem.
Have you checked it in your machine.
thanks in advance.

Quote from: fireballs on November 06, 2008, 01:22:15 AM
you need to reset the %username% vaule otherwise it'll remember what you entered last time:

Code: [Select]set username=
set /p username=Please enter username:

FB
run your script without the Code: [Select] echo off at the beginning and the problem will most likely be obvious.

FBThe username variable is defined by the system and is unlikely ever to be blank.

Try using another variable name:

Code: [Select]echo off
setlocal
:uname
SET /P uname=Please enter your username:

IF .%uname%==. GOTO uname
echo entered %uname%
endlocal

 thank you very much for your response.
Its working perfectly.
But could you please tell what does the . used in if condition, setlocal convays?
i am beginner to DOS.
thanks in advance.

Quote from: Sidewinder on November 06, 2008, 04:18:22 AM
The username variable is defined by the system and is unlikely ever to be blank.

Try using another variable name:

Code: [Select]echo off
setlocal
:uname
SET /P uname=Please enter your username:

IF .%uname%==. GOTO uname
echo entered %uname%
endlocal

 
Quote
But could you please tell what does the . used in if condition

The dot keeps the if condition balanced. If uname is blank, the if condition compares dot to dot. There is no WAY to directly compare nulls in batch code. Note: the dot is arbitrary, you can use any character; I PREFER dots because they are lower case.

Quote
setlocal convays

setlocal and it's evil twin endlocal, RESTRICT the life of variables. In this case uname starts blank with each execution of your code.

  Quote from: Sidewinder
I prefer dots because they are lower case.

Don't understand what you mean. Dots are neither lower or upper case. Only the letters of the alphabet have "case".
Possibly he means you do not have to hold shift to get them?
But, I am also unsure of what he means.Anyway, there are lots of ways to get around the "comparing nulls" problem.


quotes are most common I think

if "%variable1%"=="%variable2%"

square brackets

if [%variable1%]==[%variable2%]

Or a single dot...

I think using quotes as a rule makes sense, as it also takes care of the chance a variable might contain spaces. Quote from: gregory on November 09, 2008, 02:45:41 AM
I think using quotes as a rule makes sense, as it also takes care of the chance a variable might contain spaces.

Indeed.

Code: [Select]S:\>set var=hello world

S:\>echo %var%
hello world

S:\>if %var%==hello world echo Yes
world==hello was unexpected at this time.

S:\>if {%var%}=={hello world} echo Yes
world}=={hello was unexpected at this time.

S:\>if "%var%"=="hello world" echo Yes
Yes

S:\>
1927.

Solve : DOS BatchFile for deleting file by size in many sub directories?

Answer»

I need help on this batch file...
I have a mainSub directory with many sub directories and sub-sub directories. I need to delete all the files less than 500 bites in this mainSub directory and in all the sub and sub-sub directories it contains.
I wrote a code as follows:

FOR %%F IN (C:\MaAbey\ *.*)s DO (
IF %%~zF LSS 500 DEL %%F
)
pause

This could delete all  the files less than 500 bites in MaAbey mainSub directory but not in its sub and sub-sub directories.

Please help me to adjust the code to delete all the files in all the sub, sub-sub directories which are less the 500 bites.

Thank you

Mahindause dir /s . check dir /? for more info.
another way, download findutils (see my sig) and use the GNU find command
Code: [Select]c:\test> find c:\tmp -type f -size -500c  -delete
WARNING - YOU ARE SHOOTING BLIND

The first line of your code is so WRONG.
Firstly you must remove the lower case 's' - DOS will not like it.
Then you will lose all the vital *.ini files, and ANYTHING else in your CURRENT DRIVE AND DIRECTORY ! !
I show in the code box below your version followed by a corrected version :-
Code: [Select]FOR %%F IN (C:\MaAbey\ *.*)s DO (
FOR %%F IN (C:\MaAbey\*.*) DO (

The corrected version will only process the files within C:\MaAbey\
Your version will try (and fail) to delete the ENTIRE folder with all its contents,
then it will actually delete all small files that are located in WHATEVER is your current directory and drive.

DO NOT USE DEL IF YOU DO NOT KNOW WHAT YOU ARE DELLING.

I strongly recommend that you replace "DEL %%F" with
Quote

DIR %%F >> To_Zap.txt
and/or
Quote
ECHO %%F >> To_Zap.txt
That will give a file, To_Zap.txt, which you can scrutinise at your leisure to decide if the potential victims should be subjected to DEL, or if there are further mistakes to be corrected before you need to reinstall WINDOWS ! !

I will not address the mechanisms for recursion through the sub-directories, I can safely leave that to others.  My priority is to warn/guide you so that you do not destroy vital files.

Regards
Alan
Thanks Alan and thanks ...0g74

I am using windows xp and sometimes work with the dos command prompt. So, ..0g74's UNIX like codes cannot be used I think?

Alan, thanks for the advise, I know exactly what is this SubMain directory. They are data files specially created to test the code. The 's' was a mistake, in my code ran it was not there.

I adjust the code with /S switch. But I could not get any good result to my question. It ask before deleting entire MaAbey directory 'are you sure, confirm, Y/N'. I NEVER wanted to delete entire directory.

for %%F IN (C:\MaAbey\*.* /s) DO (if %%~zF LSS 100 DEL %F) pause
pause

Quote from: mabeykoon on June 15, 2009, 02:38:51 PM
I am using windows xp and sometimes work with the dos command prompt. So, ..0g74's UNIX like codes cannot be used I think?
no you are wrong. The better and more useful find command in Unix has been ported to windows through GNU.
1928.

Solve : Noob in need of help with a bat file?

Answer»

Hi, I am trying to WRITE a batch file that will find an old file/folder, delete it, and then REPLACE it with a new file/folder? Below is what I have so far, please help:

ECHO OFF

SETLOCAL

 

SET targetPath=C:\scripts\scripts

SET targetFiles=*.doc

SET aMonthBefore=20090609

 

FOR /f %%z IN ('dir /b %targetPath%\%targetFiles%') DO (

  FOR /f "tokens=1-4 delims=/ " %%a IN ('dir %targetPath%\%%z') DO (

    IF "%%c%%a%%b" LSS "9" (

      FOR /f "tokens=1-4 delims=(" %%1 IN ("%%c%%a%%b") DO (

        IF "%%2"=="" (

          IF %%c%%a%%b LSS %aMonthBefore% (

            ECHO Detect file older than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b

          ) ELSE (

            ECHO Defect file newer than %aMonthBefore% ::::: -- %%z -- %%c%%a%%b

          )

        )

      )

    )

  )

)
to find and delete an old file, you can use GNU find for windows. (See my sig, search for findutils)
eg
Code: [Select]c:\test > find c:\test -type f -NAME "file_to_delete" -delete
there are other options also, like find how many days old, etc..

1929.

Solve : usb and cd rom drivers in MS-DOS ????

Answer»

OK now that i have a real copy of ms-dos on my old pc. I need to set up the drivers for the USB flash drive and the CD ROM. i have the drivers on the F: drive. I need help with the Autoexec.bat file and the config.sys file. i have read the Q&A on autoexec. and config. files. but im am still not sure about how to realy set them up ther are some exsampels that mostly show with windows, i dont have windows on it. So im left with some other quistons. like how meny devices can i use? is ther an order i need to make sure the dvices are LISTED.

Packard bell model #P160119601, the motherboard is Agna-6wmm7, it uses PC-100 ram 64 megs, hard drive is a WD Caviar 84AA (set with 4 partions C: D: E: F: all portions or about 2gig in size), The OS is  MS-DOS 6.22.  It has a floppy 3.5 and a DVD ROM.

Thank you for any help one can send my way.Just a thought sence the drives im trying to set up are not external, i should not have to change my autoexec.com. just the config.sys. if im right on that?    I'm not sure about the flash drives, but you can find a driver for CD-ROM/DVD-ROM drives here:


ftp://ftp.ehu.es/cidirb/2000/speedsys/oakcdrom.sys


This is the Driver I usually use when running DOS or windows 3.1.

you'll need to modify both config.sys and autoexec.bat.


config.sys. add this after DEVICE=HIMEM.SYS:
Code: [Select]DEVICEHIGH=C:\DOS\OAKCDROM.SYS /D:OAKCD

autoexec.bat- plop this line at the bottom:

Code: [Select]MSCDEX /D:OAKCD
(obviously I am assuming OAKCDROM.SYS was placed in the DOS directory).



Flash drives, I'm afraid, I've never used successfully via DOS.
this did not work i droped the code where you asked and this is the code i put in
  Code: [Select]DEVICEHIGH=F:\OAKCDROM.SYS /G:OAKCD
the driver is on my f: drive and i want to make the cdrom drive G:

i also added this to my autoexec.bat
Code: [Select]MSCDEX /G:OAKCD
But i am thinking that it is my config sys that is not right. Here is what it looks like after i add the code
Code: [Select]DEVICE=C:\DOS\SETVER.EXE
DEVICE=C:\DOS\HIMEM.SYS
DEVICEHIGH=F:\OAKCDROM.SYS /G:OAKCD
DOS=HIGH
COUNTRY=044,,C:\DOS\COUNTRY.SYS
DEVICE=C:\DOS\DISPLAY.SYS CON=(EGA,,1)
FILES=30
Now i have seen some other code with a umd after the dos=high  ok i am realy starting to fell dum now. i wen back and checked my config.sys and the reason it did not work is that i had missed spelled DEVICEHIGH i had spelled it DEVISEHIGH.

So now that i have fixed that. The driver is loading but i get
"Illegal option 'g'
usage: MSCDEX [/E/K/S/V] [/D:driver> ... ] [/L:] [/M:]"

any thoughts? becouse i found this post on a defrent site i will just post the content as a quote Quote

I finally got it to work!! I have the following files on my boot disk:

himem.sys
ramrd.sys
usbaspi.sys
di1000dd.sys

And my config.sys is as follows:

dos=high, umb
lastdrive=z
device=himem.sys
device=ramfd.sys
devicehigh=usbaspi.sys /w /v
devicehigh=di1000dd.sys /dG

The file just above assigns my PNY 128MB thumb drive to the G: drive, and I can then access it through DOS. I don't have anything in my autoexec.bat file (don't really need it since I'm not accessing an external cd-rom.

will adding the lastdrive=z line in my config.sys  fix itwell i have tried a few things.  just putting the lastdrive=z dose nothing. lol  I even tried put all of the code from the above post in. and though it did install the usb driver.  it did not find my device. i still do not get drive letters for my cd rom. the driver for the CD ROM loads but with no drive letter i still can not access it.you cannot change the /D:OAKCD to /G:, since /D stands for "devicename" which allows MSCDEX to find it.

HOWEVER, if you want to give it a letter, simply change the mscdex line:

Code: [Select]MSCDEX /D:OAKCD /L:F

you can find more switches for MSCDEX here:

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




Also- I'll add that this is only for the CD-ROM, since I haven't really done much more then dabble with USB drives in DOS. However if you can acquire the files the other poster refers to you can get your Flash drive working as well.Thank you that helped alot. i now have a working cd rom still working on the usb though.  when i do ge the usb up and running i will be sure to post it here. Quote from: Hannix1969 on June 07, 2009, 12:45:18 PM
Thank you that helped alot. i now have a working cd rom still working on the usb though.  when i do ge the usb up and running i will be sure to post it here.

Your WELCOME, and good luck! I will be curious to hear how it is accomplished!  http://www.georgpotthast.de/usb/oh you, spoiling the thrill of the chase!  SORRY BC...won't happen again anytime soon.....
Heck you gave up the OakRom drivers ! !
That was considered the Motherlode back in the Day...

          Fair enough! Why, I often see people taking the CD-ROM drivers from some random boot-up disk, and it's that horrible contraption implemented by win98! I mean, how many drivers do you need for a CD-ROM drive?

If the manufacturer doesn't have a DOS driver (my samsung DVD burner came with DOS drivers) I'll use oakcdrom.LOL thank you Patio i had almost given up when i came back here to check the post. i had tried many other drivers.  and was even able to get the device to show up in dos but still not able to get in to them. i have down loaded the zip from the site you sagested.  hope to try it out tonight.
BC i personal think that you and Patio should be able to add thouse two items to the Totorals. I think it would be a great help to people like me.
 thank you both i have learned allot from all of this. and i can tell i have a lot more to learn. ill let you know how it works for me Patio and thanks again.lol OK when i start Dosusb program it finds my usb ports.  i edited my config.sys to load the driver Code: [Select]DEVICE=C:\DOS\USBDISK.SYS i restarted my PC. when it restarts it loads the usb thumb drive to a point that it finds but it says you must start dosusb first.

 how do i start dosusb before config.sys loads the driver? or did i do a me and leave out some code that should be in there? do i need to put a line of code in my autoexec.bat as well like i did with the cdrom?     i did try the devload app that came with it but I am lost on how to use devload. 

Well i did say i would let you know how it went. and as you can see i have made a mess of it lol
1930.

Solve : insufficient memory?

Answer»

Hello all--  greetings from South africa

I am writing some addins to some old dos programs that i USE in
my small factory.

I am using a pentium 4 and windows XP

I am getting a message "insufficient memory" .

There is however plenty of memory
 
Can anyone suggest a work around??

REGARDS ntambomvuAt what point do you get the error message? 

Are these batch files?

What kind of code are you writing?You could be running out of the 640k base memory... Are there any TSR's or other services for these dos programs that are eating up too much base memory.

run MEM at dos prompt and report back the figures shown

You can have tons of extended Ram like 2GB, but if you pull down your base memory too low then you can run into this situation with some dos programs. Newer programs use Windows OS with extended Ram, but if the programs were intended to address base memory addresses then you could be in this situation if not addressing extended memory.

Is this a Windows Alert or a DOS Program Alert to the memory insufficient. Also have these programs run before without problems or is this a new configuration?

Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\dlembke>mem


    655360 bytes total conventional memory
    655360 bytes available to MS-DOS
    599072 largest executable program size

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

C:\DOCUME~1\dlembke>
You should see something like this and "Largest Executable Program Size" is the key here...should be in the 580k ->640k range otherwise DOS programs may complain. The more the better and if less than 590k I would be looking for a way to get back 10k if say 580k

***Also run a virus scan to make sure system is clean...if an old floppy had a TSR virus on it it could also cause this low base memory issue.Many many thanks for the reply-- i thought that being a dos question that i would
be battling for an answer - but i was wrong- youir input is appreciated

> Are there any TSR's or other services

I really dont know - ?? how can i find out?

Running mem give the same answers as your screen shot except that
in my case the 

599072 largest executable program size
is 633,???  ( not quite 640 but more that your 599 >


>Is this a Windows Alert or a DOS Program Alert to the memory insufficient.

I am programming in dbase 4 ver 2 for dos and the error is being reported
by the dos program ( not by windows)



Also have these programs run before without problems or is this a new configuration?

No This is new code ---(while i  have many other programs in the same language- this is the first time I have seen this message) the message appears about half way through a data capture screen that uses many  say get statements and the complete entry page is 4 screens long- so I thinh that the page may be heavy for dos


***Also run a virus scan to make sure system is clean

I was AVG regularly and no problems reported?

Answers to further questions in you mail are

>batch files ---- not these are .prg files


> I am running dbase 4 ver 2 and the code is very basic data-capturing
stuff.
Well If you have 633k base then TSRs are not a concern. TSRs generally eat up base memory, but you have plenty.

You may be grabbing too much info and exceeding the buffer --> Quote

message appears about half way through a data capture screen that uses many  say get statements and the complete entry page is 4 screens long- so I thinh that the page may be heavy for dos
  Can you chunk it out a little into smaller portions for it to handle and piece the 2 halves together to get the entirety of it? Is there any static information for a good stop/start flag location in the page that can be used to tell it to grab the first piece of info until it hit that flag, then write to file, then grab and append the 2nd half to the end of that file, you then can open that file and use that any way that you need.
DBASE 4 is likely to understand neither Windows XP, nor the COMMAND.COM and CMD.EXE imitations of "proper" MSDOS.

In the good old days Bill GATES said that 640 KBytes was more than enough memory.
Ancient software is likely to interpret a GByte of memory as implausibly large, and decide it is a negative number because all memory has been used up.

There are error conditions that are new with XP, and were unknown with MSDOS.
Perhaps DBASE 4 gives a reasonable explanation of errors it is familiar with,
and anything else is covered by a "catch-all" of "insufficient memory".

Regards
Alan
This would probably mean that he would have to get say DOSBOX, since getting the actual thing would bring the same errors. DOSBOX is a substitute for the actual DOS, since its programmed to work in Windows.

You can probably run Dbase 4 in DOSBOX. Here's the link for DB:
http://www.dosbox.com/download.php?main=1

Hope this helps
,Nick(macdad-)Thank you very much-- you guys ( Dolls??) have been very helpful--

It is nearly 10Pm here so i will be forging onward with theis tomorrow__

I will post the results

best regards Fred
( big grin)Is Himem.sys enabled in your config.sys file ? ?Worth checking, but since XP doesn't normally use Config.sys at initialization as well as autoexec.bat I am not sure if that will HELP or not...on the DOSBOX it would definately help to have himem set for max base mem.Thanks for all the input

I found that the easiest thing was to break the code into blocks
and put a "read" statement before the line that caused the error and it
seems top be running well.

About DOSBOX--- I am interested but am a little scared of trying to fix something
that is not broken !!

What is dosbox actually? i

Is it a replacement of the old dos 6.22?

If i install it am I likely to have errors with the dos programs that i am using?

As I use Dbase on a network will it be nessessary to have dosbox on all the
workstations or is it ok only to use it for programming

regards fred

(By the way -- anyone who still uses dos probably also hates being ripped off with inkjet printer cartridge replacement costs. Well i think i have licked the problems of refilling- interested to know- just LET me know. No costs nothing you cant do in your garage

regards)


 DosBox is a sort of Port for Windows/Emulator of the actual MS-DOS.

DosBox shouldn't bring up the same errors, its designed for Windows which should allow it to handle the large amounts of RAM.
1931.

Solve : Expire Batch - Date comparison?

Answer»

I want to have a hard coded date in a BATCH file that checks system date to verify if batch should be run.

If system Date is past EXPIRED Date then fail. Is this possible? Do I need to convert date to something else?

Code: [Select]Echo OFF

set M=%DATE:~4,2%
set D=%DATE:~7,2%
set Y=%DATE:~10,4%

set ExpiredDATE=06/18/2009

if %ExpiredDATE% GTR %M%/%D%/%Y% ECHo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" Expired & pause & EXIT

Echo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" If Date gtr expireddate failed?
Pause
THANKS for the help.


EDIT:I think I totally brainfarted and figured this out. I will post if I need help. Blah its been a long day. Ok ... sorry for the second post. I changed the code to this but it still expires. What am I doing wrong with DATE?

Code: [Select]Echo OFF

set M=%DATE:~4,2%
set D=%DATE:~7,2%
set Y=%DATE:~10,4%

set ExpiredDATE=06/14/2010

if %M%/%D%/%Y% GTR %ExpiredDATE% ECHo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" Expired & pause & EXIT

Echo Date:"%M%/%D%/%Y%" ^& ExpiredDATE:"%ExpiredDATE%" If Date gtr expireddate failed?
PauseCompare dates using YYYYMMDD format.

Cool. That appears to work.

Do you know why that works and MMDDYYYY doesn't? Thanks for the help. You may have your Date Format set to: YYYYMMDD

Depending upon where you LIVE, the Date format is different. Quote from: nothlit on JUNE 16, 2009, 07:21:49 AM

Do you know why that works and MMDDYYYY doesn't? Thanks for the help.

The IF command does not compare dates, it simply looks at two values and returns True or False.

IF 06/16/2009 GTR 06/14/2010 will always return True (06162009 is GTR 06142010)

IF 2009/06/16 GTR 2010/06/14 will always return False while the system date value is less than the hard coded date value (20090616 is LSS 20100614)

(Edit in italics.)

You're welcome.

D.
1932.

Solve : AUTOEXEC.BAT Fail to launch?

Answer»

Hi all,

I' aware AUTOEXEC.BAT isn't run as per win98 now in winXP, however..... I have a good question I hope u genius's can answer (enough sucking up ??)

I have just purchased a second hand Compaq Presario 2500 P4 2.4 Ghz running XP Home SP3 as a fresh install. As with all my puters, the first thing I do is to create a Norton GHOST Image of the entire C: Drive as back-up for when I truly kill it by playing around too much.

Problem is the AUTOEXC.BAT does NOT run when the system is cold booted into a GHOST boot floppy as it does (from the same floppy) on all my other systems. Every time it boots it runs PC-DOS then sits at an "A:" prompt and goes no-where.

I must type "autoexec" at which time it loads all the mouse drivers on the floppy, and executes the Norton Ghost program in the DOS environment just fine.

I have read about autoexec.nt etc till my eyes are bleeding, but found nothing helpful about booting from a floppy into a DOS environment using an XP Computer.

The reason I need this is as Norton Ghost runs very well in the DOS environment but needs help loading drivers for USB storage and DVD burners etc in order to place the GHOST Image somewhere large enough.

I guess my question is simply "How can a puter NOT run an Autoexec.bat file when that puter is cold booted into a floppy containing that autoexec.bat file ?"

You guys probably have a simple answer, so I'm ready to raise my hand and slap my forehead any time

Cheers from Melbourne,

Snapperhead.

on floppy disk when you run the PATH command do you see it pointing to autoexec.bat ( when booted from floppy )... Have you edited the general boot disk that Ghost creates that broke it or it never worked correctly?Originally there was DOS.

Later it grew a G.U.I option - it was possible to invoke Windows, such as Windows 98

Windows XP is NOT an option supported by DOS.
Windows XP is entered by starting the computer.
Windows XP supports multiple instances of command line options (CMD.EXE etc.)
It does not work the other way round.

You can boot-up with MSDOS if your floppy disc has more than an autoexec.bat file.
It needs to be a complete DOS BOOT disc which old computers would recognize.
That will give you DOS, but it will not be possible from that DOS to then launch Windows.
That DOS will not even be able to read C:\ if it is NTFS format.

Your ALTERNATIVE is to make the computer dual boot, but that is a whole new ball game that will take far more than this forum thread ! !

Regards
Alan
Their problem has nothing to do with Windows since it is in PC-DOS in which the problem is occurring at A: which is booting, but it is not following through with autoexec.bat

Quote
Every time it boots it runs PC-DOS then sits at an "A:" prompt and goes no-where.
I havent played anough with PC-DOS to know of the differences. With Ghost I have always created the bootable floppy and was good to go. I later migrated that bootable floppy to a Bootable CD by using Roxio Easy CD Creator 5 to convert the Floppy to Bootable CD to support systems without a floppy drive or (healthy floppy drive that hasnt choked on a hairball )

My bootable Floppy has the Ghost software with NDIS2 Network Drivers for Intel Pro 100 Chipset NICs and runs with no problem. Any system can be supported by plugging in a spare Intel Pro 100 NIC into a FREE PCI slot vs having to have a floppy created for each build to support different Network Adapter drivers etc. Once booted I can deploy images via Peer-to-Peer from my image server to the bare system with no OS and have the system up and running in like 15 minutes for a 8GB image.
Why not post the file ? ?Hey good idea Patio... Maybe the autoexec.bat file has a typo...


as for Quote
when I truly kill it by playing around too much.
could suggest that the floppy has been altered.There's not much to a Ghost boot floppy....somethings missing though.Thanx for your reply's guys....... Great to see people actualy reading posts on a forum for once (which is why it's called a forum - not a notice BOARD)

I will endevour to post the file and a screen shot or two asap.

The boot floppy I am using is the one made by Norton Ghost, and is used on all my system creations, with no hassle at all. I even created a new one, but alas to no avail.

The only difference here is that the laptop is using XP Home and not XP Pro.

Late LAST night I tampered with the AUTOEXEC.BAT file's properties, and changed it to run in 'compatabiliy mode' with win98, and behold... IT WORKED !!!

But it's still a weird way to do things, given the need to load some drivers later for accessing my Ghost Server over the wireless network etc etc.

Will post some detail post cafiene.

Cheers,

S.
1933.

Solve : Idea for a batch file HELP!!!!?

Answer»

I would like to try a infinite monkey theorem out. Using a batch file to randomly choose from the 26 letters of the alphabet. When the word banana is spelt the batch file pauses. Any one have any ideas? please anything would help!!!!!!!you can generate a list of lower case letters using for loop. for random function, you can use %RANDOM%.

alternatively, you can use a programming language with functions that deal with random generation. here's a Python implementation
Code: [Select]import random
import string
import sys
letters = string.lowercase #lowercase letters a-z
text=sys.argv[1]
word=[] #list to contain the letters
while 1:   #infinite loop
    word.append(random.sample(letters,1)[0]) #store each letter into array
    if len(word)== len(text) :
        if ''.join(word) == text:
            raw_input("Found : %s" % text)            #pause when found.
        else:
            print "Generated word: ",''.join(word)
            word=[]
usage: c:\test> python test.py "banana"

if you are interested, here's an executable you can use, if you don't want to download Python.

output:
Code: [Select]C:\test>test.exe banana | more
Generated word:  rpjjpp
Generated word:  cclexr
Generated word:  clqafz
Generated word:  ewhilx
Generated word:  jzwhco
Generated word:  ghjlst
Generated word:  xsdpff
Generated word:  lklfhq
Generated word:  lnolsx
Generated word:  rpptyy
Generated word:  jevwvi
Generated word:  walddh
Generated word:  pekxbz
.....
echo off
:loop
if %let%==banana goto stop
if %num%=6 set let=&set /a word+=1
set /a num+=1
set rnd=%random%
if %rnd% gtr 26000 goto loop
if %rnd% gtr 25000 set let=%let%z& goto loop
if %rnd% gtr 24000 set let=%let%y& goto loop
if %rnd% gtr 23000 set let=%let%x& goto loop
if %rnd% gtr 22000 set let=%let%w& goto loop
if %rnd% gtr 21000 set let=%let%v& goto loop
if %rnd% gtr 20000 set let=%let%u& goto loop
if %rnd% gtr 19000 set let=%let%t& goto loop
if %rnd% gtr 18000 set let=%let%s& goto loop
if %rnd% gtr 17000 set let=%let%r& goto loop
if %rnd% gtr 16000 set let=%let%Q& goto loop
if %rnd% gtr 15000 set let=%let%p& goto loop
if %rnd% gtr 14000 set let=%let%o& goto loop
if %rnd% gtr 13000 set let=%let%n& goto loop
if %rnd% gtr 12000 set let=%let%m& goto loop
if %rnd% gtr 11000 set let=%let%l& goto loop
if %rnd% gtr 10000 set let=%let%k& goto loop
if %rnd% gtr 9000 set let=%let%j& goto loop
if %rnd% gtr 8000 set let=%let%i& goto loop
if %rnd% gtr 7000 set let=%let%H& goto loop
if %rnd% gtr 6000 set let=%let%g& goto loop
if %rnd% gtr 5000 set let=%let%f& goto loop
if %rnd% gtr 4000 set let=%let%e& goto loop
if %rnd% gtr 3000 set let=%let%d& goto loop
if %rnd% gtr 2000 set let=%let%c& goto loop
if %rnd% gtr 1000 set let=%let%b& goto loop
set let=%let%a
goto loop
:stop
echo done!
echo %word%
pause >nul

that should do it...I had to make that on my dsi so I had to write everything, no copypasta.
Helpmeh i put that in to notepad and made a bat from it and its not working please tell me what i need to do. and how i can understand how you made that. pleasetry running the batch file from the command prompt and tell me what it says. (btw, I can't test it as I am STILL on my DSi.)3 Quote from: Helpmeh on June 14, 2009, 06:18:31 AM

echo off
:loop
if %let%==banana goto stop
if %num%=6 set let=&set /a word+=1
set /a num+=1
set rnd=%random%
if %rnd% gtr 26000 goto loop
if %rnd% gtr 25000 set let=%let%z& goto loop
if %rnd% gtr 24000 set let=%let%y& goto loop
if %rnd% gtr 23000 set let=%let%x& goto loop
if %rnd% gtr 22000 set let=%let%w& goto loop
if %rnd% gtr 21000 set let=%let%v& goto loop
if %rnd% gtr 20000 set let=%let%u& goto loop
if %rnd% gtr 19000 set let=%let%t& goto loop
if %rnd% gtr 18000 set let=%let%s& goto loop
if %rnd% gtr 17000 set let=%let%r& goto loop
if %rnd% gtr 16000 set let=%let%q& goto loop
if %rnd% gtr 15000 set let=%let%p& goto loop
if %rnd% gtr 14000 set let=%let%o& goto loop
if %rnd% gtr 13000 set let=%let%n& goto loop
if %rnd% gtr 12000 set let=%let%m& goto loop
if %rnd% gtr 11000 set let=%let%l& goto loop
if %rnd% gtr 10000 set let=%let%k& goto loop
if %rnd% gtr 9000 set let=%let%j& goto loop
if %rnd% gtr 8000 set let=%let%i& goto loop
if %rnd% gtr 7000 set let=%let%h& goto loop
if %rnd% gtr 6000 set let=%let%g& goto loop
if %rnd% gtr 5000 set let=%let%f& goto loop
if %rnd% gtr 4000 set let=%let%e& goto loop
if %rnd% gtr 3000 set let=%let%d& goto loop
if %rnd% gtr 2000 set let=%let%c& goto loop
if %rnd% gtr 1000 set let=%let%b& goto loop
set let=%let%a
goto loop
:stop
echo done!
echo %word%
pause >nul

that should do it...I had to make that on my dsi so I had to write everything, no copypasta.

will %rnd% ever be less than 1000? also what if %rnd% is exactly 1000, 2000, 3000 etc..gh0std0g74 you got this to work? I can't get it going and don't know why is there any other way ? or maybe some links someone could give me to help learn how ? Quote from: gh0std0g74 on June 14, 2009, 07:04:31 AM
will %rnd% ever be less than 1000? also what if %rnd% is exactly 1000, 2000, 3000 etc..
%rnd% can be less than 1000, and if it is, then %let% will be %let%a. If it is 1000, 2000, etc. then it will be the lower letter, as it is gtr not geq.
OP, please use my suggestion of running it from the command prompt, so we can find any error you may have.This here looks like it may take a while before it actually hits with Match for BANANA a counter from AAAAAA to ZZZZZZ would probably hit it sooner counter only really needing to be from AAAAAA to BANANA since everything from BANANB, and BANANC.... to ZZZZZZ is thrown out. Also if random the same combinations can become recreated wasting time. There is a slight chance it could hit BANANA sooner than a counter, but I think the counter would win in counting to BANANA sooner than a random character generation.

Depending on what you have for hardware ( CPU etc ) this could take a while on a Pentium 4 vs a Quad Core etc.

Only STATING this from my project not to long ago to create every combination of A to ZZZZ using FOR A to ZZZZ in a Perl Script that GhostDog helped me with, and write to file for another project and it took a while on a Pentium 4.

I then played with 5 and 6 combination counters and it took about 13 hours to run 6 characters A to ZZZZZZ and write appended to list.txt every combination on the 3Ghz P4 in using Perl and cores were almost 100% the whole time on HT processor.Replacing anything before the if command with if %rnd% geq 15000 goto loop should decrease time. A bit at least...

OP, open the command prompt and drag the batch file into the window and PRESS enter. If it gives an error, you will see it, then you should post it here.
1934.

Solve : Batch file for deletion of 45 days old log files from multiple directories?

Answer»

Dear All
    PLEASE help me creating a Batch FILE for deletion of LOG files which are 45 days old &AMP; files are spread across many directories.

Thanks & regards
Jasbir Singhif you can download findutils (see my sig first link),
Code: [SELECT]c:\test> find_gnu.exe c:\test -type f -name "*.log" -mtime +45 -delete

1935.

Solve : Append text at the end of a file?

Answer»

Hi All

I need to append the a string at the end of the file. The string should be in the last LINE. Assume a file contains the lastword as -Last. I need to add a string like New. Now when i append it is appending like -LastNew. But I need to append the string in the next line like
"Last
New"

Now if i use "echo." This will append like this
"Last

New"

A line BREAK is there in between the last line and the appended string. How can I do that with out a line break.

Thanks in advancehave you tried : echo line&GT;>file.txt ?
C:\>type  anecho.bat
Quote

echo off
echo.  > file.txt

echo with a period provides a BLANK line  >>  file.txt

echo.  >> file.txt

echo see a blank line was inserted  >>  file.txt

Output :

C:\> anecho.bat

C:\>type file.txt

with a period provides a blank line

see a blank line was inserted

C:\>
1936.

Solve : add a .bat file to right click contents menu?

Answer»

add a .bat file to  right click  contents menu
=======================================
hi
is there a WAY to  add a .bat file to  right click  contents menu?
if its so  give me the exact  string for .reg file
thanksNot sure what you mean. What Right Click menu? What would its purpose be?I believe he means on the "New" Item under the File menu, he wants to add a Create new Batch File:


VIEW this:
http://windowsxp.mvps.org/shellnewadd.htm

[attachment deleted by admin]Intriguing....I never thought of that...

TweakUI, the Windows XP Powertoy, can do it.
http://www.microsoft.com/windowsxp/Downloads/powertoys/Xppowertoys.mspx
http://download.microsoft.com/download/f/c/a/fca6767b-9ed9-45a6-b352-839afb2a2679/TweakUiPowertoySetup.exe


If you're looking for a way to do it via the Registry, don't. It's not worth it.Thought about bringing that up, and yea...registry is not worth it for such a simple operation.thanks guys
links above were really  helpfulyou can USE this anyway:

Code: [Select]Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.bat\ShellNew]
"Data"="echo off"
"ItemName"="%SystemRoot%\\system32\\notepad.exe,-470"
i have it like this and it works
Quote

you can use this anyway:

Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.bat\ShellNew]
"Data"="echo off"
"ItemName"="%SystemRoot%\\system32\\notepad.exe,-470"

i have it like this and it works

sorry devcom
i  copied your CODES in  a reg  key   and execute it but i dont have  it in  my  right click why?
should i  restart my  win xp?

i  dont want  .bat in  my  new
i want to  add one program.bat  in  my  right clickok, so you need to look for app ShellExView, this should help you

Code: [Select]http://www.nirsoft.net/utils/shexview.htmldo you mean to add FILES to a right click menu like this?

yes BatchFileBasics
i  need it  to  be avtive both  on  folders and files
thanks if you  van  make a script i will  be greatfullwell this is for the "all' files but not folders:
and you save it in notepad as "anything.REG"
Code: [Select]Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Name of command\command]
="\"c:\\path of file\\file.bat\" \"%1\""

replace "Name of command" with what you want the right click descipt to be.
but leave alone the "command" at the end

Code: [Select]="\"c:\\path of file\\file.bat\" \"%1\""
adds the key to the registry.
your normal file would be c:\path of file\file.bat
but all the \ mean to not count as a new command\line

regularly it is :
Code: [Select]"c:\path of file\file.bat\" "%1"
but you need the slashes so:
Code: [Select]"\"c:\\path of file\\file.bat\" \"%1\"
it worked thanks my  dear BatchFileBasics
i  have  my.bat file in  my right click options now
i am  satisfied now
thank you  againyou are all welcome to whom gave me a thanked up.


and mioo_sara, welcome to the forums I know this is an older post, but i tired and have one issue. When i right click a blank area, there is no "Create New BAT" like registry specified. It simply added an option for when i right click an file. Has anyone got this to work on the right click menu or the "File>new" menu?

Here is my REG file:
Code: [Select]Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Create New BAT\command]
="\"C:\\Documents and Settings\\mhofmann\\My Documents\\Test\\file.bat\" \"%1\""


Thanks for the help!
1937.

Solve : Need Help with renaming thousands of files?

Answer»

oh

i am not used to with this forum

You can see his name appears in BLACK, and the WORD "GUEST" UNDERNEATH.
Quote

Pain has left the forum.

Line of the Month Award ! !

1938.

Solve : Trying to get back to Windows?

Answer»

Long story- I'll try to make it short. I got a virus, many scans didn't get rid of it. Couldn't load Safe Mode, was told to go into msconfig and tell it to load into Safe Mode under the Boot.ini section... at which point my computer ceased to load Windows. Period. It can't seem to load Safe mode at all. Every time it's told to load Windows in the last working manner, as far as I can tell, it tries to follow the Boot.ini, hits Safe Mode and simply... restarts. Over and over. Each Safe Mode OPTION.... restart. Load Windows with last working Config?... restart. AUGH.

Using a portable floppy drive (B:\) with a boot disk which I had to manually tell it to load. No questions/prompts appeared when I got it to load DOS using this. So now I am in DOS, at a C: prompt and completely lost a frustrated. Bootcfg doesn't WORK. dir shows only two things, SYSTEM~1 (a DIR) and WL_SET~2 which is an exe file.

This is an XP computer, without a boot CD - the install STUFF for XP is actually on a partition on the hard drive. I have an extra external hard drive hooked up to the computer, which was labled J: in Windows, and does not have an installed OS. That Hard drive is merely my storage drive for files, and I believe it is coming up as D:\ in DOS.

All I want is to be able to get back into Windows so I can get what files I need/want off the system before reformatting.

There is ONE file in the Windows\Temp that may be the virus which I was going to attempt to delete. I know it isn't a vital file, but in Windows it says it's "in use" even when it shouldn't be.

Yes, I ran a half dozen virus and malware scans. Did no good. Most said my computer was clean as a whistle. Hijackthis wasn't even coming up with anything odd according to their analysis. I'm not a complete newbie to computers, but my DOS time & experience is pretty small- I started into computers limited before Win95, but didn't have much actual use till Win95 and later.

Not sure of the computer's STATS other then it is dual core, 1 or 2 gig ram, XP and was fully updated (all service packs & "important" updates) as of the day before Thanksgiving when it went wiggy. One hard drive installed, the second external hard drive is USB-connected. I still have the USB floppy and Boot disk handy, I also have a borrowed XP install cd on hand.

Edited: No Recovery Console was installed, as I didn't expect Safe Mode to cause this bizzare loop. I should've listened to that little voice that questioned my husband's wisdom about the Boot.ini in the first place. Is this a desktop PC? Do you have another computer you can use?

If you have another computer, you can simply hook up your hard drive you want to save files off of to your other computer and see how that goes. (But I don't know if  your virus would infect other computer so be careful) Quote from: 2x3i5x on December 03, 2009, 11:33:34 AM

Is this a desktop PC? Do you have another computer you can use?

If you have another computer, you can simply hook up your hard drive you want to save files off of to your other computer and see how that goes. (But I don't know if  your virus would infect other computer so be careful)

It is a desktop, and the external hard drive I have is actually an internal with a special case- it's easy to swap HD's with it. I've been using my husband's computer since mine went down.

That was the one reason I haven't tried that- I am afraid the virus might spread and then both computers would be SOL. It is a trojan, and while my computer had Windows on it was continually producing empty files into the Temp folder. AVG was the only virus/malware program that was picking it up, ad only on it's Alert- it did not pick it up on a computer full scan. Semantic, Trend Micro.... nothing. Frustrating!attach you hard drive to your husbands computer and copy all your important files.

get around the files carefully so that you may not hit the virus 

I think you will only have document files to save from your hard drive

you can prevent all the executable files from clicking while you take files from you hard drive.

also install a reliable antivirus  like Rising Antivirus or something else on your husband computer before connecting the hard drive into it.

if you still afraid, then first take all the important data from your hard drive to a CD or something else from the C drive of your husbands drive


Between I never save data on C drive as windows may be damaged anytime so I advise other of the same too.
1939.

Solve : Command Prompt (CMD); Two issues about DIR command?

Answer»

Quote from: BatchFileBasics on November 26, 2009, 04:16:24 PM

thats the problem, you can't use for loops in the command prompt without a script.

That is not so; at the prompt you just use one % sign in the loop variables (instead of two)

Code: [Select]
S:\Test>for /f "tokens=1,2,3,4,5 delims=\" %a in ('dir /ad /s /b') do echo %a\%b\%c\%d\%e

S:\Test\Batch\Older\custom-path
S:\Test\Other\Auto-it\
S:\Test\Other\Basic\
S:\Test\Other\beep\
S:\Test\Other\cURL\
S:\Test\Other\FTP\
S:\Test\Other\FUS-Repair\
S:\Test\Other\getmail\
S:\Test\Other\ghacker\
S:\Test\Other\hta\
S:\Test\Other\kix\
S:\Test\Other\Mirakagi\
S:\Test\Other\NATW\
S:\Test\Other\PopClient\
S:\Test\Other\Portable-Ubuntu\
S:\Test\Other\Python\
S:\Test\Other\reg\
S:\Test\Other\Ruby\
S:\Test\Other\textview\
S:\Test\Other\UnxUtils\
S:\Test\Other\virtual disk\
S:\Test\Other\wget_GUI\
S:\Test\Other\winmsg\
S:\Test\Other\winWget\
S:\Test\Other\wmv-avi\
S:\Test\Other\Zerodir\
S:\Test\Other\Auto-it\Auto-it3
S:\Test\Other\Auto-it\Checkbox
S:\Test\Other\Auto-it\MsgBox
S:\Test\Other\Auto-it\Auto-it3
S:\Test\Other\Auto-it\Auto-it3hello?I tried with:

Code: [Select]echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
instead of

Code: [Select]echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b
pause
But EVEN this doesn't do anything.  You are doing something wrong. We do not know what, since you don't give enough INFORMATION.

Quote from: Salmon Trout on November 29, 2009, 05:50:07 AM
You are doing something wrong. We do not know what, since you don't give enough information.

I have tried to use the both codes - of COURSE NOT at the same time. I have pasted them to notepad, each time i saved them as .bat. Firstly used second code but since it doesn't work, I used first one but doesn't work too - two .doc files are still not created. What I wish to have in .doc files is DESCRIBED in my first and second post.You LEFT the > filename.doc off the end.
If you meant this:

Code: [Select]echo off
for /f "tokens=4,5 delims=\" %%a in ('dir /ad /s /b') do echo %%a\%%b > filename.doc
pause
It does give me the .doc file but just one instead of two and with terrible results inside - completely different from what I was asking  I think you are going to have to learn some batch scriptingWhy nobody wants to tell me what should I do, in my situation, described in first and third post?
1940.

Solve : Search Files on multiple servers?

Answer»

Hi wbrost

I know for sure that file is in G DRIVE which is already mapped. But there are 40 ODD servers to search from. If i keep this batch file in another seperate server and run this. how do i go about EDITING your batch file. PLEASE help wbrost. anyone please help

1941.

Solve : find files?

Answer»

I have the following batch file which i have managed to come upto. find below

set "file=\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr
\testing.txt"
set "ANSWER="
if exist "%file%" (
echo found the file on server servernameA
echo found the file on server servernameA >>"file.log"
set /P "answer=Delete the file? [y/N] :"
)
if /i "%answer%"=="y" del "%file%"

I NEED to change the functionality of the above script to SEARCH a file if the path is not specified. We have 2 drive on about 40 servers, so lets assume we want to search a file that could exist ANYWHERE either in c drive or g drive. could even be in sub folders. the script should find
this file and ask before deleting. please help

1942.

Solve : change uppercase to lowercase?

Answer»

I have an html file that's quiet large, nearly 7000 lines.

It has thousands of URLs pointing to a WEBSERVER that (for a strange reason) doesn't support UPPERCASE URLs...

How do I change all the tags www.SOMESITE.com/DIR/FILE1.HTM>, www.SOMESITE.com/DIR/FILE2.HTM> and so on to URLs with only lowercase letters?

I've tried using regex in Notepad++ but can't find the appropriate expression...so I thought that a batch file might do?Any Linux or Unix user will tell you that it's not a "strange reason". Windows is case-insensitive. But the Internet is not BUILT on Windows.

see if this works

Code: [Select]rem echo off
setlocal enabledelayedexpansion
if exist Output.html del Output.html
for /f "delims=" %%L in (Input.html) do (
    set line=%%L
 
    set line=!line:A=a!
    set line=!line:B=b!
set line=!line:C=c!
set line=!line:D=d!
set line=!line:E=e!
set line=!line:F=f!
set line=!line:G=g!
set line=!line:H=h!
set line=!line:I=i!
set line=!line:J=j!
set line=!line:K=k!
set line=!line:L=l!
set line=!line:M=m!
set line=!line:N=n!
set line=!line:O=o!
set line=!line:P=p!
set line=!line:Q=q!
set line=!line:R=r!
set line=!line:S=s!
set line=!line:T=t!
set line=!line:U=u!
set line=!line:V=v!
set line=!line:W=w!
set line=!line:X=x!
set line=!line:Y=y!
set line=!line:Z=z!
   
echo [I] %%L
echo [O] !line!
    echo.!line! >> Output.html
    )
   
    Quote from: swede on December 02, 2009, 07:36:58 AM

so I thought that a batch file might do?
batch is never the first choice for an appropriate tool to do parsing of files. Tools like Perl,Python, gawk,sed are designed to parse files easily, among other things they can do. If you can, try to use them, otherwise, if you really want to stick to "batch", you can use vbscript, which natively installed on your system.

Code: [Select]Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile = objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
ISFOUND = InStr(strLine,"HREF")
If IsFound > 0 Then
s=Mid(strLine,IsFound + Len("HREF=" & """"))
whereIsQuote = InStr(s,""""& ">")
strUrl = LCase(Mid(s,1,whereIsQuote))
WScript.Echo Mid(strLine,1, IsFound-1) & "HREF=" & """" & strUrl & Mid(s,whereIsQuote+1)
Else
WScript.Echo strLine
End If
Loop

output
Code: [Select]C:\test>more file
<html>

lskhdfl
dsf
<p> .,,,,, </P>
dfj
some tages ... <A HREF="www.SOMESITE.com/DIR/FILE1.HTM"> somesite </A>

aslfjf asjldf <B> sdfhl </B> <A HREF="www.SOMESITE.com/DIR/FILE2.HTM"> some OTHER site </A> ...asdf

</html>

C:\test>cscript /nologo test.vbs file
<html>

lskhdfl
dsf
<p> .,,,,, </P>
dfj
some tages ... <A HREF="www.somesite.com/dir/file1.htm"> somesite </A>

aslfjf asjldf <B> sdfhl </B> <A HREF="www.somesite.com/dir/file2.htm"> some OTHER site </A> ...asdf

</html>
Quote from: Salmon Trout on December 02, 2009, 10:23:52 AM
see if this works
it works, but it will change all other caps that needs to be caps. Quote from: gh0std0g74 on December 02, 2009, 06:02:15 PM
it works, but it will change all other caps that needs to be caps.
What NEEDS to be capitalized? Quote from: Helpmeh on December 02, 2009, 06:13:01 PM
What NEEDS to be capitalized?
actual words that should appear capitalized when you view the page. EG, Every first words of paragraphs of text, or every word after a full stop etc. OP just wants to change the URL to small caps, not the whole html page. Quote from: gh0std0g74 on December 02, 2009, 06:48:41 PM
actual words that should appear capitalized when you view the page. Eg, Every first words of paragraphs of text, or every word after a full stop etc. OP just wants to change the URL to small caps, not the whole html page.
Wow...I feel kinda stupid, so I shal rephrase, is there any CODE that requires case?Can we ask the OP how did he get a list of URLs that were in upper case. Or who put upper case in links in a web page. You would thin that the error would have been corrected and the time of data entry.
But sometimes a URL may have some part that has to be upper case. Not everybody puts the names of things in lower case.Safari auto-decapitalizes btw.  Quote from: Helpmeh on December 02, 2009, 07:14:14 PM
Wow...I feel kinda stupid, so I shal rephrase, is there any CODE that requires case?
don't understand. What "CODE" are you taking about? you should give examples to your query as much as possible Quote from: gh0std0g74 on December 02, 2009, 06:02:15 PM
it works, but it will change all other caps that needs to be caps.

I know, and I was thinking up a VBS script that was broadly ALONG the lines of your contribution.

1943.

Solve : move can't find specified file?

Answer»

when i run the following the move command, it says 'the system cannot find the file specified'
rem ****************
echo move %%1 "..\extra" >> ask_em.bat
 
rem ****************but the following line works just fine
echo if errorlevel 1 if not errorlevel 2 echo moved %%1 >> ask_em.bat

this one calls manage.bat

echo off
:init
echo *********************************************
echo again y/n
choice /c:yn
if errorlevel 2 if not errorlevel 3 goto outofit
rem if errorlevel 1 if not errorlevel 2 goto init
call "manage.bat" *.*
goto init
:outofit


****************   this is manage.bat
echo off
if exist "..\extra\flagyes.txt" goto main
md "..\extra"
echo here > "..\extra\flagyes.txt"
:main
echo echo {m}ove/ {s}tay file> ask_em.bat
echo echo. >> ask_em.bat
echo echo %%1 >> ask_em.bat
echo echo. >> ask_em.bat
echo choice /c:ms >> ask_em.bat
echo echo. >> ask_em.bat
echo if errorlevel 2 if not errorlevel 3 goto outofit >> ask_em.bat
rem ****************this one doesn't work
rem echo move %%1 "..\extra" >> ask_em.bat
rem ****************but the following line works just fine
rem echo if errorlevel 1 if not errorlevel 2 echo moved %%1 >> ask_em.bat
echo :outofit >> ask_em.bat
for %%i in (%1) do call ask_em.bat %%i
:outofit
del ask_em.bat
quotes need escaping (by doubling them)

try this

echo move %%1 ""..\extra"" >> ask_em.batthxs tried the double quotes, doesn't seem to change anything, even no quotes doesn't affect anything.
i must be losing something some where cause when i run the following it doesn't lose the file.

echo if errorlevel 1 if not errorlevel 2 echo moved %%1 >> ask_em.bat

when run, this one spits out the correct name for %%1

but when i run
echo move %%1 ""..\extra"" >> ask_em.bat
or
echo move %%1 "..\extra" >> ask_em.bat
or even
echo move %%1 ..\extra >> ask_em.bat
it TELLS me: **the system cannot find the file specified file**
i'm startin to thinke echoing the line to ask_em.bat is whats messing me up. do i need special characters in front of the individual % in the line thats echoed to ask_em.bat? Quote from: jprime hope on December 02, 2009, 06:14:01 AM

do i need special characters in front of the individual % in the line thats echoed to ask_em.bat?

Sorry I should have spotted that! To echo a percent sign you do need a special character in front of each one. The special character is a percent sign. Thus %%a becomes %%%%a

this line in manage.bat:
echo move %%%%1 "..\extra" >> "..\extra\ask_em.bat"
produces an ask_em.bat line--** move %%1 "..\extra" **

this line in manage.bat:
echo move %%%1 "..\extra" >> "..\extra\ask_em.bat"
produces an ask_em.bat line--**move %*.* "..\extra"

this line in manage.bat:
echo move %%1 "..\extra" >> "..\extra\ask_em.bat"
produces an ask_em.bat line--**move %1 "..\extra"

but all give--   the system cannot find..........
it's like dos is losing the VALUE of %%1 by the time it goes to echo it to ask_em.batit seems if i echo %1 instead of moving %1, dos doesn't lose the name

this works---------------------echo %1

but this doen't -----------------move %1 "..\extra"

and the following
'insert own code here' >> "..\extra\ask_em.bat"
sends the stuff preceding the '>'  without a prob when i'm trying to build ask_em.batGod I am slow today.

You made a fundamental error.

In a batch file you only use two percent signs with a letter or number like this %%A for a loop variable.

You are passing a parameter from 1 batch file to another. You use one percent sign in front of a number so you need %1.

Start from that and see how you go.

By the way that is a crazy way to do the task.

Also, each time you run it, it moves both batch files into ..\extra

what exactly are you tring to do here?





i know my code is lame, but i was trying to thin down my tunes (> 8000) and just wanted something to display the name, give me a choice to move or not move it to an over flow directory. would be redundantly, grateful for any n all suggestions on how else to do it. 
i must be missing something here
this statement works
echo if errorlevel 1 if not errorlevel 2 echo move %%1 >> "..\extra\ask_em.bat"
but this does not
echo if errorlevel 1 if not errorlevel 2 move %%1 "..\extra" >> "..\extra\ask_em.bat"

the first one will display the name, the second gives the 'can not find error'. by USING the word echo in front it will at least print the name ( i understand i'm not moving anything, just displaying the name) but least it doesn't lose the name.
  You want to display 8000 filenames and ask to move each one?

no just to go thru n list the files one at a time, giving me the option to move it to n extra/overflow directory. then my player will have less files to deal wit, espicially redundant or extra files, i have some times 3,4 or more files of the same song, some times exactly the same length, sometimes only longer or shorter by a few bytes,. n since even some differant tunes, can be the same length, i can't sort by length or title for that manner, as some of the same files can have names that DIFFER by a single character. but be the same tune. i thought buy reducing the total #'s i would hopefully reduce the time, speeding things up, not the playing (which is fine) but the managing of them. Why don't you just use Windows Explorer, which was made for this kind of job?
have used it 4 this, but it was so sloowwww that way, .  i thought since i like dos anyway n wanted to expand my dos relm understanding the same time, i could design it so it would feed me the files one a time, then by one button press i could send it to overflowland n move on to the next. i figured this would be faster then Explorer. i mean with 8000> maybe 8500> files to process in Explorer, all i could see was tedium beyound understanding.
also, can't stand the computer getting the better of me by gum. And since i want to understand what is happening here (knowledge is power), i will prob keep plodding along so that i may use this some future, if it's usable that isI agree. I'll try to think of some tips so WATCH this space.
1944.

Solve : Unspecfied path?

Answer»

set "FILE=\\servernameA\C$\dferert\tretevf\erwerew\yuyur\gtytr\testing.txt"
set "answer="
if exist "%file%" (
echo found the file on server servernameA
echo found the file on server servernameA >>"file.log"
set /p "answer=Delete the file? [y/N] :"
)
if /i "%answer%"=="y" DEL "%file%"

To the above batch file, i need to change it as follows

What if the file path is unspecified i.e file COULD be anywhere on c drive or we have another drive called G. how to add this to above script. please help

please help or guide me

1945.

Solve : Parse two string lists?

Answer»

Hi there,

I have a problem that I can't seem to be able to resolve.  The batch file that I am working on expects to get 4 parameters, two of which are lists of strings:

IPADDRESS=172.16.0.1
SERVICENAME=Service1,Service2
BINPATH="C:\Programs Files\Company Name\Product Name\bin.exe"
DISPLAYNAME="DisplayName 1","DisplayName 2""

I need to call the following command line in a for loop, such that on the first iteration it would use the first string in the comma delimited list in the SERVICENAME and the first string in the comma delimited list in the DISPLAYNAME string list.

First iteration:

sc \\172.16.0.1 create "Service1" binPath= "C:\Programs Files\Company Name\Product Name\bin.exe" DisplayName= "Display Name 1" obj= "NT Authority\Network Service" start= demand

Second iteration:
sc \\172.16.0.1 create "Service2" binPath= "C:\Programs Files\Company Name\Product Name\bin.exe" DisplayName= "Display Name 2" obj= "NT Authority\Network Service" start= demand

Here is my sample SCRIPT that does not quite work the way I want it to:

FOR %%a in (%SERVICENAME%) do (FOR %%c in (%DISPLAYNAME%) do (
   FOR /F "tokens=1 delims=," %%b in ("%%a") do ( set srvnm=%%b & FOR /F "tokens=1 delims=," %%d in ("%%c") do (echo %%b %%d))))

This displays:

Service1 "Display Name 1"
Service1 "Display Name 2"
Service2 "Display Name 1"
Service2 "Display Name 2"

I also have tried the following, but it doesn't work:

FOR %%a in (%DISPLAYNAME%) do (
   FOR /F "tokens=1 delims=," %%b in ("%%a") do (echo %srvnm% %%b))

Service2 "Display Name 1"
Service2 "Display Name 2"


Thank you in advance.
NataliaBecause you can use an arithmetic (number) variable for the tokens= value, you can step through the delimited tokens by incrementing the variable with set /a in a loop

Code: [Select]echo off
set SERVICENAME=Service1,Service2,Service3,Service4,Service5,Service6
set DISPLAYNAME="DisplayName 1","DisplayName 2","DisplayName 3","DisplayName 4","DisplayName 5","DisplayName 6"

REM add end markers
set mySERVICENAME=%SERVICENAME%,eof
set myDISPLAYNAME=%DISPLAYNAME%,eof

REM Temporarily remove quotes around "Displayname N"
set myDISPLAYNAME=%myDISPLAYNAME:"=%

set ITER=1

:loop

                for /f "tokens=%iter% delims=," %%A in ("%mySERVICENAME%") do set var1=%%A
                if %var1%==eof goto done
                for /f "tokens=%iter% delims=," %%B in ("%myDISPLAYNAME%") do set var2="%%B"
                if %var2%=="eof" goto done

                echo [Iteration=%iter%] %var1% %var2%
               
                set /a iter+=1
                REM alternative format
                REM set /a iter=%iter%+1

goto loop

:done

echo.
echo Finished

output

Code: [Select][Iteration=1] Service1 "DisplayName 1"
[Iteration=2] Service2 "DisplayName 2"
[Iteration=3] Service3 "DisplayName 3"
[Iteration=4] Service4 "DisplayName 4"
[Iteration=5] Service5 "DisplayName 5"
[Iteration=6] Service6 "DisplayName 6"How are you passing the 4 parameters?
Quote from: Salmon Trout on December 01, 2009, 03:40:45 PM

How are you passing the 4 parameters?

Look at his post.
The parameters have to be done as literal items, on the command line. With quotation makes, with commas. Exactly as he posted.
This is a candidate for a shell script or a VBS or something more that just pure batch commands.   
BTW, Nothing was said about error recovery. If he has more than a four or five servers, it is going to be a mess when an error happens. And the do happen. Quote from: Geek-9pm on December 01, 2009, 03:59:36 PM
Look at his post.
The parameters have to be done as literal items, on the command line. With quotation makes, with commas. Exactly as he posted.

That was what I was hoping. Incidentally "he" signs "his" post "Natalia", so I think I may have read it a BIT more carefully than you did
Thank your for your solution, Salmon. :-)   Let me give it a try.  To answer your question, the 4 parameters are being passed from an executable that invokes the script as command line argument to the script. (%1, %2, %3, %4, %0 is reserved to indicate the test mode operation.)

To answer Geek-9pm's concern about error handling, it was omitted intentionally in order to clearly state the problem space.  The error handling does exist in the script. :-)

Thanks,
Natalia
LOL, on the "his" comment.  Got me laughing :-)I am reminded of the old story about the Englishman travelling in Ireland who is unsure how to get to a certain town. He asks an elderly LOCAL who says "Ah sure, begorrah, if I wanted to get to there, I wouldn't be startin' from here!".

Natalia, if you look through this forum, you will see many threads in which somebody asks for a batch solution to a problem. An answer is given, but also people jump in saying "Don't bother with batch, use Visual Basic Script/Perl/Python/Awk/GNU grep/sed, (or whatever)", because those methods are somehow "better" or more "elegant" or "efficient". This may be so, but I think what sometimes escapes these code warriors is that in many cases the person asking the question is not requesting a code snippet that SOLVES a problem, text-book fashion, or a lesson in some other scripting language, but rather a solution is desired to enable them to finish a larger batch script that they have already spent some time and effort writing. Often other solutions are impossible because of restrictions on third party installations and/or use of VBScript.

OK the sermon is over. Natalia, I notice that in your comma separated lists, that "DisplayName N" is quoted, but ServiceN is not. I removed the quotes from DisplayName, and put them back again, because of a problem I had (XP SP3) with a strange error message to do with oddly named files not being found if the variable was used with quotes as the dataset in a FOR command.



1946.

Solve : Force user to enter correct file format [YYYYMMDD.txt]?

Answer»

I dont think so. It's not printing the %RESULT% and keeps going back to '
set /p variable="Please input filename (YYYYMMDD.txt) ?"' because "%result%" has an empty value.

Are you using the code inside a larger batch file, possibly in a loop?

No its not in a loop at all. I've tried it by itself also, and the same happens, I can't get the result variable to display.

Here is the whole of my code below:
echo off

:BEGIN
SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):

IF EXIST "%variable2%" echo This Directory has been Found.
IF EXIST "%variable2%" GOTO FileBegin

IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists:
IF NOT EXIST "%variable2%" goto Begin
:BEGINEND

:FileBegin

Echo Outstring="incorrect">dval.VBS
Echo StrDate=Wscript.arguments(0)>>dval.vbs
Echo y = Mid(StrDate,1,4)>>dval.vbs
Echo m = Mid(StrDate,5,2)>>dval.vbs
Echo d = Mid(StrDate,7,2)>>dval.vbs
Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs
Echo Wscript.Echo  Outstring>>dval.vbs

:loop

set /p variable="Please input filename (YYYYMMDD.txt) ?"
pause
For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A
pause
Echo Date format %result%
pause
If /i not "%result%"=="correct" goto loop
del c:\dval.vbs

Set variable="%variable3%".txt
IF EXIST "%variable2%\%variable%" echo This file has been Found.
IF EXIST "%variable2%\%variable%" GOTO START

IF NOT EXIST "%variable2%\%variable%" echo You are required to re-enter a file name that exists:
IF NOT EXIST "%variable2%\%variable%" goto loop

:start

ECHO.
ECHO 1. Generate Report for list of user logoffs
ECHO 2. Generate Report for list of network logons
ECHO 3. Generate Report for list of users who logged in and logged out
ECHO 4. Generate Report for Special permissions assigned to new logon

:choice
set choice=
set /p choice=Type the number to print text:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto loggedout
if '%choice%'=='2' goto networklogon
if '%choice%'=='3' goto nwlogin_loggedout_users
if '%choice%'=='4' goto specialprivs

ECHO "%choice%" is not valid please try again
ECHO.
goto choice

:loggedout
echo Please wait while the report gets created..
find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable%
SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit
echo Goodbye.
goto end1

:networklogon
echo Please wait while the report gets created..
findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable%
echo %variable2%\networklogon_%variable% has been generated.
pause
goto end1

:nwlogin_loggedout_users
echo Please wait while the report gets created..
mkdir "%variable2%\tmp"
find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp
find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable%
del /f %variable2%\tmp\logonlogout_%Variable%.tmp
echo C:\logonlogout_%variable% has been generated.
pause
goto end1

:specialprivs
echo Please wait while the report gets created..
find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable%
echo %variable2%\specialprivs_%variable% has been generated.
pause
goto end1
:end1
echo off

I ran your code & it showed me the %result% variable. I had to press a key twice though.

Take the 2 red pause statements out

:BEGIN
SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):

IF EXIST "%variable2%" echo This Directory has been Found.
IF EXIST "%variable2%" GOTO FileBegin

IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists:
IF NOT EXIST "%variable2%" goto Begin
:BEGINEND

:FileBegin

Echo Outstring="incorrect">dval.vbs
Echo StrDate=Wscript.arguments(0)>>dval.vbs
Echo y = Mid(StrDate,1,4)>>dval.vbs
Echo m = Mid(StrDate,5,2)>>dval.vbs
Echo d = Mid(StrDate,7,2)>>dval.vbs
Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs
Echo Wscript.Echo  Outstring>>dval.vbs

:loop

set /p variable="Please input filename (YYYYMMDD.txt) ?"
pause
For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A
pause
Echo Date format %result%
pause
If /i not "%result%"=="correct" goto loop
del c:\dval.vbs

Set variable="%variable3%".txt
IF EXIST "%variable2%\%variable%" echo This file has been Found.
IF EXIST "%variable2%\%variable%" GOTO START

IF NOT EXIST "%variable2%\%variable%" echo You are required to re-enter a file name that exists:
IF NOT EXIST "%variable2%\%variable%" goto loop

:start

ECHO.
ECHO 1. Generate Report for list of user logoffs
ECHO 2. Generate Report for list of network logons
ECHO 3. Generate Report for list of users who logged in and logged out
ECHO 4. Generate Report for Special permissions assigned to new logon

:choice
set choice=
set /p choice=Type the number to print text:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto loggedout
if '%choice%'=='2' goto networklogon
if '%choice%'=='3' goto nwlogin_loggedout_users
if '%choice%'=='4' goto specialprivs

ECHO "%choice%" is not valid please try again
ECHO.
goto choice

:loggedout
echo Please wait while the report gets created..
find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable%
SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit
echo Goodbye.
goto end1

:networklogon
echo Please wait while the report gets created..
findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable%
echo %variable2%\networklogon_%variable% has been generated.
pause
goto end1

:nwlogin_loggedout_users
echo Please wait while the report gets created..
mkdir "%variable2%\tmp"
find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp
find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable%
del /f %variable2%\tmp\logonlogout_%Variable%.tmp
echo C:\logonlogout_%variable% has been generated.
pause
goto end1

:specialprivs
echo Please wait while the report gets created..
find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable%
echo %variable2%\specialprivs_%variable% has been generated.
pause
goto end1
:end1Still not working on my end for some reason 
Cannot get the variable to show at all  Code: [Select]Set variable="%variable3%".txt
What does this line do?
Code: [Select]echo off

:BEGIN
SET /p variable2=[Enter directory that Security Log reports are stored in] (e.g C:\seclogs):

IF EXIST "%variable2%" echo This Directory has been Found.
IF EXIST "%variable2%" GOTO FileBegin

IF NOT EXIST "%variable2%" echo You are required to re-enter a directory name that exists:
IF NOT EXIST "%variable2%" goto Begin
:BEGINEND

:FileBegin

Echo Outstring="incorrect">dval.vbs
Echo StrDate=Wscript.arguments(0)>>dval.vbs
Echo y = Mid(StrDate,1,4)>>dval.vbs
Echo m = Mid(StrDate,5,2)>>dval.vbs
Echo d = Mid(StrDate,7,2)>>dval.vbs
Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs
Echo Wscript.Echo  Outstring>>dval.vbs

:loop

set /p variable="Please input filename (YYYYMMDD.txt) ?"
For /f "delims=" %%A in ( 'dval.vbs "%variable%"' ) do set result=%%A
Echo Date format %result%
If /i not "%result%"=="correct" goto loop

IF EXIST "%variable2%\%variable%" (
    echo This file has been Found
    goto start
    )
   

echo File "%variable2%\%variable%" not found
echo You are required to re-enter a file name that exists:
goto loop

:start

ECHO.
ECHO 1. Generate Report for list of user logoffs
ECHO 2. Generate Report for list of network logons
ECHO 3. Generate Report for list of users who logged in and logged out
ECHO 4. Generate Report for Special permissions assigned to new logon

:choice
set choice=
set /p choice=Type the number to print text:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto loggedout
if '%choice%'=='2' goto networklogon
if '%choice%'=='3' goto nwlogin_loggedout_users
if '%choice%'=='4' goto specialprivs

ECHO "%choice%" is not valid please try again
ECHO.
goto choice

:loggedout
echo Please wait while the report gets created..
find /n ",538," %variable2%\%variable% > %variable2%\userlogout_%Variable%
SET /p dummy=%variable2%\userlogout_%variable% file has now been generated.. Press return to exit
echo Goodbye.
goto end1

:networklogon
echo Please wait while the report gets created..
findstr /n ",540," %variable2%\%variable% > %variable2%\networklogon_%Variable%
echo %variable2%\networklogon_%variable% has been generated.
pause
goto end1

:nwlogin_loggedout_users
echo Please wait while the report gets created..
mkdir "%variable2%\tmp"
find /n ",540," %variable2%\%variable% > %variable2%\tmp\logonlogout_%Variable%.tmp
find /n ",538," %variable2%\tmp\logonlogout_%Variable%.tmp > %variable2%\logonlogout_%Variable%
del /f %variable2%\tmp\logonlogout_%Variable%.tmp
echo C:\logonlogout_%variable% has been generated.
pause
goto end1

:specialprivs
echo Please wait while the report gets created..
find /n ",576," %variable2%\%variable% > %variable2%\specialprivs_%Variable%
echo %variable2%\specialprivs_%variable% has been generated.
pause
goto end1
:end1Ah I'm still confused. I'm not sure why the variable is still not displaying.
Thanks for your help. Code: [Select][Enter directory that Security Log reports are stored in] (e.g C:\seclogs):s:\test
This Directory has been Found.
Please input filename (YYYYMMDD.txt) ?20091130.txt
Date format correct
This file has been Found

1. Generate Report for list of user logoffs
2. Generate Report for list of network logons
3. Generate Report for list of users who logged in and logged out
4. Generate Report for Special permissions assigned to new logon
Type the number to print text:


Alright, I've got it working apart from an error on this line:
for /f "delims=" %%A in ( 'cscript c:\dval.vbs "%variable%"' ) do set result=%%A

It says that 'The filename, directory name, or volume label syntax is incorrect'.

Any ideas?The vbs script is not being found. The batch is writing it to dval.vbs i.e. in the current directory (the same directory that the batch is in) but you have coded the calling line to look for c:\dval.vbs

EITHER: change all these dval.vbs to c:\dval.vbs

Code: [Select]Echo Outstring="incorrect">dval.vbs
Echo StrDate=Wscript.arguments(0)>>dval.vbs
Echo y = Mid(StrDate,1,4)>>dval.vbs
Echo m = Mid(StrDate,5,2)>>dval.vbs
Echo d = Mid(StrDate,7,2)>>dval.vbs
Echo If (IsDate(y^&"/"^&m^&"/"^&d) ^<^> 0) Then Outstring="correct">>dval.vbs
Echo Wscript.Echo  Outstring>>dval.vbs
OR: change c:\dval.vbs to dval.vbs

Code: [Select]for /f "delims=" %%A in ( 'cscript c:\dval.vbs "%variable%"' ) do set result=%%AHi ya,
Thanks for all the information.
I got it working anyway and it seems to be fine now. I disregarded the cb script popup boxes that displayed "incorrect" and "correct" and printed it out within the batch program.

I may have to do more complex things with these reports, like strip off certain information from the actual log text files.
Is Perl the best to generate these kind of reports?
Thanks,
Laura Quote from: newuserlh on DECEMBER 01, 2009, 05:41:55 AM

I disregarded the cb script popup boxes that displayed "incorrect" and "correct" and printed it out within the batch program.


That is a clue that you are running the script with wscript.exe and not cscript.exe which explains the lack of output you were experiencing.

You are using the command

cscript.exe //nologo before the vbs script name?

Yeah it's running cscript now.  I had issues with the output there and changed the DELIM line.
It's sorted out now thankfully.
1947.

Solve : Can U break up a string, in a batch file??

Answer»

If this topic has been previous posted I appologize but I did not find anything SIMILAR to this when I was searching the DATABASE regarding strings.

Question: Can you break a string up into subtrings.  I know you can do this in UNIX but can you do this using a batch file?

You have a string, "abc", and you break up the string into characters and assign those characters to different variables.

For example:
str = abc
chr1 = a
chr2 = b
chr3 = c

Like before, any comment or SUGGESTIONS are always welcome. 

thank you.I figure it out.  Ok, that's not entirely true.  I found an example on the net regarding substring:

%VAR:~n,m%

where n is the starting position (from zero) and m the substring's LENGTH. So, if VAR is set to "My pretty girl", %VAR:~3,6% identifies the substring "pretty".

n may have negative values meaning it REFERS to the end of the variable.

1948.

Solve : Command for command prompt?

Answer»

Hello all,

I have a problem with my PC,
can't see anything on my desktop but green.

Can someone anyone help me out with a command so that I could
go to (c:/program files/recovery pro) and set my sys back to FACTORY settings.
I tried everything else I know, witch AINT MUCH LOL.

Thanks in advance!

  FranCould you provide your OS?Windows XPok, now to goto that directory on command prompt, type in this:

cd /d C:\Program Files\recovery pro

It didn't work, got a message saying:
(operable program or batch file)
I also have a shotcut to recover pro on my desktop if this helps.ok go ahead and start it from your desktop, but can you still work your mouse?
No I can't see anything but green on my desktop,
I was hoping U can give me a command prompt to get it started.

TIA

  FranHitthe Windows key and the R key at the same time. That should bring up the run command. Type in CND and hit return.There is Typo CND should be CMD...

What do you mean by its Green?Are you able to bring up Task Mgr?

it's all good now, I Hit "Ctrl+Alt+Del" to load the Taskmanager

From the pulldown menu;  File --> New task (run)
I hit BROWSE found my program and restored my sys.

Thank you all so much.

  FranAnytime

1949.

Solve : How to read day of the week with dos commands?

Answer»

Hi EVERYONE,

I need to read the day of the week by a DOS command.
commands "time" and "date" don't help me.
With Solaris environment, with command "date" and some options I can read what I want like "Tue" for TUESDAY or "Feb" for February" ....

I need to do a batch file running on DOS.

Please help me


ThanksDo you mean  MS-DOS or Windows command prompt? If Windows, which version?
I mean windows prompt.
I'm working on windows 2000The native Windows 200 command scripting language (which is not MS-DOS) does not have date functions like you describe, but from a batch file (command script) you can access the ones in Visual Basic Script.

Code: [Select]echo off
REM Create VBS script
set vbsfile=DateInfo.vbs
echo           Newdate = Date>%vbsfile%
echo          DateYear = DatePart("YYYY", Newdate)>>%vbsfile%
echo         DateMonth = DatePart("M"   , Newdate)>>%vbsfile%
echo           DateDay = DatePart("D"   , Newdate)>>%vbsfile%
echo        WeekOfYear = DatePart("WW"  , Newdate)>>%vbsfile%
echo         DayOfYear = DatePart("Y"   , Newdate)>>%vbsfile%
echo     WeekDayNumber = DatePart("W"   , Newdate)>>%vbsfile%
echo    TodayNameShort = WeekdayName(WeekDayNumber,True)>>%vbsfile%
echo     TodayNameFull = WeekdayName(WeekDayNumber,False)>>%vbsfile%
echo    MonthNameShort = MONTHNAME(DateMonth,True)>>%vbsfile%
echo     MonthNameLong = MonthName(DateMonth,False)>>%vbsfile%
echo    Wscript.Echo DateYear^&" "^&DateMonth^&" "^&DateDay^&" "^&Week^
OfYear^&" "^&DayOfYear^&" "^&WeekDayNumber^&" "^&Today^
NameShort^&" "^&TodayNameFull^&" "^&MonthNameShort^&" "^&MonthNameLong>>%vbsfile%

REM    Store output of vbs script in variables
for /f "tokens=1-10 DELIMS= " %%A in ( ' cscript //nologo %vbsfile% ' ) do (
set Year=%%A
set Month=%%B
set Day=%%C
set WeekNumber=%%D
set DayNumber=%%E
set DayOfWeekNum=%%F
set DayNameShort=%%G
set DayNameLong=%%H
set MonthNameShort=%%I
set MonthNameLong=%%J
)

REM 3) Do something with the data
echo.
echo Date Year                 : %Year%
echo Date Month                : %Month%
echo Date Day                  : %Day%
echo Week Of Year              : %WeekNumber%
echo Day Of Year               : %DayNumber%
echo Day Of Week [Number]      : %DayOfWeekNum%
echo Day Of Week [Short Name]  : %DayNameShort%
echo Day Of Week [Full Name]   : %DayNameLong%
echo Month [Short Name]        : %MonthNameShort%
echo Month [Long Name]         : %MonthNameLong%
echo.
Echo %DayNameLong%, %MonthNameLong% %Day%, %Year% is in week %WeekNumber%
echo.







Thaks but I solved in this way:

http://www.flyonthenet.com/articoli/sistemi-windows/giorno-settimana-odierno-script-batch.html

I hope you can understand italian.

Thanks a lotYou changed a registry setting so that your local date format includes the short name of the day of the week?

Quote

I hope you can understand italian.

Va bene!
1950.

Solve : Replace + Run + Exit??

Answer»

Hello guys.

I'm QUITE a bit new in this batch stuff.

So, what I need is a batch that kill a process, replace two files, run a program and exit the batch.

What I've got so far is this:

taskkill /f /im vpngui.exe /t
replace "C:\VPN_Irapida_Instalar\IPSEC_Irapida.pcf" "%programfiles%\Irapida\IPSEC\Profiles"
replace "C:\VPN_Irapida_Instalar\IPSEC_IrapidaHOST.pcf" "%programfiles%\Irapida\IPSEC\Profiles"
%programfiles%\Irapida\IPSec\vpngui.exe
exit

But I'm getting some errors since the promp won't exit until I close the vpngui.exe.

Can you guys help me?

Thanks a lot in advance.

Cya Code: [SELECT]start "" "%programfiles%\Irapida\IPSec\vpngui.exe"
20 mins! How's that for service?


Thanks, Ill will try it.

But, I didn't get the service part

Thanks Or better, is it POSSIBLE to make something like it?

1- The batch close the process
2- CHECK if there is the C:\VPN_Irapida_Instalar\IPSEC_Irapida.pcf file.
  2.1 - If there is, replace it to %programfiles%\Irapida\IPSEC\Profiles
  2.2 - If not, download it from a server, save it to an folder (showing the progress)
  2.2.1 - replace it to %programfiles%\Irapida\IPSEC\Profiles
3- Prompt the user
  3.1- Success, Close the program? Y/N
  3.2- Error, try to call your admin.

Is it possible?

Thanks a lot in advance. Now I've got the service part actually 1:20min service. But I really APPRECIATED it.

CYAAnybody? Please?