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.

301.

Solve : Hi,, I need to change image sequece file names into one line name?

Answer»

Hi,, I need to fix this problem now.

I am making a batch script. It is about that if users drag and drop the first image file in a folder, the script should read what the last file name is and it will get ONE sequence file name.

For example, there is a folder with images like "test.0002.jpg", "test.0002.jpg", "test.0002.jpg", "test.0003.jpg", "test.0004.jpg", "test.0005.jpg", "test.0006.jpg", "test.0007.jpg". If I drag the first image, "test.0002.jpg", and I drop it into .bat, it should automatically change like "test.0002-0007.jpg".

When I test my script, it can read first image, but it can't read whole images.

My script is
===========================================================
:convertMOVIE
IF %1 == "" GOTO end
"C:\Program Files (x86)\djv 0.8.2\bin\djv_convert.exe" %1 "%~d1%~p1%~n1.MOV"
SHIFT
GOTO convertMOVIE
:end
ECHO.
ECHO Done!
pause
============================================================

"div_convert.exe" is a free software to convert image sequece to quicktime format.
The basic command is like "div_convert.exe test.001-005.jpg test.mov"

Please help me...

Thank you.1. Is the numerical sequence, 0002, 0007, etc, always 4 digits,
2. Is it always at the end of the name part of the filename?
3. Do you mean you want to change just the first filename of the sequence?

Quote

it can read first image, but it can't read whole images.

I am not sure what you mean by this.
Hi.. Thank you for the response.

1. numerical sequence number is different. sometimes 5 digits, sometimes 3 digits

2. test.0002.jpg, test.0003.jpg, test.0004.jpg, test.0005.jpg....

3. ex, there are 5 files, like image.0004.jpg, image.0005.jpg, image.0006.jpg, image.0007.jpg, image.0008.jpg
i want to convert these to movie. The converter should reand these sequence files to "image.0004-0008.jpg"
Then it executes as "div_convert.exe image.0004-0008.jpg test.mov" It will make a movie. Quote from: ylthh on October 16, 2010, 01:19:21 PM
Hi,, I need to fix this problem now.

I am making a batch script. It is about that if users drag and drop the first image file in a folder, the script should read what the last file name is and it will get one sequence file name.

For example, there is a folder with images like "test.0002.jpg", "test.0003.jpg", "test.0004.jpg", "test.0005.jpg", "test.0006.jpg", "test.0007.jpg". If I drag the first image, "test.0002.jpg", and I drop it into .bat, it should automatically change like "test.0002-0007.jpg".

When I test my script, it can read first image, but it can't read whole images.

My script is
===========================================================
:convertMOVIE
IF %1 == "" GOTO end
"C:\Program Files (x86)\djv 0.8.2\bin\djv_convert.exe" %1 "%~d1%~p1%~n1.mov"
SHIFT
GOTO convertMOVIE
:end
ECHO.
ECHO Done!
pause
============================================================

"div_convert.exe" is a free software to convert image sequece to quicktime format.
The basic command is like "div_convert.exe test.001-005.jpg test.mov"

Please help me...

Thank you.
So you just rename the first file?

Why have you QUOTED yourself?

correct, rename the first file.is filename format always something dot NNNN dot jpg like this: abcd.0001.jpg? (always three parts separated by dots?)


yes Code: [Select]echo off
set fullname=%~1
set foldernm=%~dp1
set barename=%~nx1
cd /d "%foldernm%"
for /f "tokens=1-3 delims=." %%A in ("%barename%") do (
set fileroot=%%A
set firstnum=%%B
set fileextn=%%C
)
set filespec=%fileroot%.*.%fileextn%
for /f "tokens=1-3 delims=." %%A in ('dir /b "%filespec%"') do set lastnum=%%B
set param1=%fileroot%.%firstnum%-%lastnum%.%fileextn%
set param2=%fileroot%.mov
"C:\Program Files (x86)\djv 0.8.2\bin\djv_convert.exe" "%param1%" "%param2%"
pause

Hi, Salmon

Thank you so much for your help.

In network server, "dir /b" didn't work well. The file order is not alphabetical. Then I added dir /b /o, then it worked.
Is it correct? Then when I execute batch file, it worked.

Thank you so much again. Quote from: ylthh on October 17, 2010, 09:02:10 AM
In network server, "dir /b" didn't work well. The file order is not alphabetical. Then I added dir /b /o, then it worked.
Is it correct?

That sounds good to me.

302.

Solve : Replace the particular string using Dos batch program?

Answer»

Hi,

I have text file ( fulllist.txt ) with following format contents

C:\PROGRAM Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube.mpg
C:\Program Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube_intro.mpg
-----
-----
-----
C:\Program Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube_intro.mpg
D:\Program Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube.mpg
D:\Program Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube_intro.mpg
-----
-----
-----
D:\Program Files\Nero\Nero 9\Templates\Smart3D\Menus\4_3\Cube\cube_intro.mpg


i want REPLACE "C:\" with "\\Server\" and  "D:\" with "\\Server\"

how to WRITE a batch file to open my file "Fulllist.txt" and replace the above string ?



Kindly help me..
Code: [Select]for /F "delims=" %%A in (fulllist.txt) do echo \\Server\%%~pnxA Quote from: Salmon Trout on October 24, 2010, 05:20:26 AM

Code: [Select]for /f "delims=" %%A in (fulllist.txt) do echo \\Server\%%~pnxA

Thanks!

i want redirect  the results new file..

Quote from: csselva on October 24, 2010, 05:41:33 AM
i want redirect  the results new file..

I am sure you know how to do that.



303.

Solve : Batch to ping network range?

Answer»

Trying to make a program to ping network range.
the range is selected via SET /p and later called in the following segment. (I believe this is where I'm having issues.)
Code: [Select]PING -n 1  %range%.2|find "reply from " >NUL
IF NOT ERRORLEVEL 1 goto s1
IF ERRORLEVEL 1 goto f1
s1 echos a success script and will nbtstat the successful IP
f1 returns fail and CONTINUES onto the next IP in the range

Is PING.exe reading the IP literally and thus RETURNING false?

the target range was tested and showed a .....0.2 ip in the range.

EDIT** Changed the SET /p to a set IP still returning false when ARP is returning that the IP exists.could you give an example of a range that might be typed in using set /p? (that is a typical value of %range%)

Quote

Is PING.exe reading the IP literally .. ?

Not SURE what you mean by this.



It will run as so...

Code: [Select]set /p range= Please select Range: Quote
user sees: Please select range:
User types: 192.168.1
Program runs: Code: [Select]ping -n 1 192.168.1.1 | find "reply" >nul
                        IF NOT ERRORLEVEL 1 goto success
                        IF ERRORLEVEL 1 goto fail
It will loop till 254 on that range
                        Quote from: Phuhrenzix on OCTOBER 27, 2010, 11:04:57 AM
It will loop till 254 on that range

What do you mean by this?

it will start on 192.168.1.1 and end in 192.168.1.254 in this example.
(the code is highly redundant because I couldn't get the FOR to loop and echo properly) Quote from: Phuhrenzix on October 27, 2010, 11:18:26 AM
it will start on 192.168.1.1 and end in 192.168.1.254 in this example.

How does it do that?
here, i'm probably not explaining well enough.
Code: [Select]echo off
SET /p username=User Name:
SET /p password=Password:
IF %password%==foo goto start
ELSE goto try1
:try1
echo login failed 1/3
SET /p password=Password:
IF %password%==foo goto start
:try2
ELSE goto try2
echo login failed 2/3
SET /p password=Password:
IF %password%==foo goto start
ELSE goto try3
:try3
echo login failed 3/3
SET /p password=Password:
IF %password%==foo goto start
ELSE goto end
:start
set /p range=please enter range:
Echo sniff sniff sniff
:1
PING -n 1  %range%.1 |find "reply" >NUL
IF NOT ERRORLEVEL 1 goto s1
IF ERRORLEVEL 1 goto f1
:s1
echo sniff sniff sniff, %range%.1 lives!
:f1
echo whimper, sorry Master %username% I could not find %range%.1
goto 2
:2
PING %range%.2|find "reply from " >NUL
IF NOT ERRORLEVEL 1 goto s2
IF ERRORLEVEL 1 goto F2
:s1
echo sniff sniff sniff, %range%.1 lives!
goto 3
:f1
echo whimper, sorry Master %username% I could not find %range%.1
goto 2
.
.
.
:end
You seem to think that the ping command will ping a range of IP addresses, but you are only giving it one IP address.

it continues on
:1 area pings %range%.1
:2 area pings %range%.2
:3 area pings %range%.3
 and so on


like i said it is highly redundant and has a instance for 1-254 to ping, the actual code isnt one IP address, unless it's only pinging what is entered for range.You mean you have 254 separate labels and 254 separate sections? Is this true?

1. Why???
2. Why did you not mention this before?
3. What are you trying to do here? Is it some kind of hack?



1. because I want it to return if the IP's are existant on the network. and the FOR wouldn't run the echo's properly
2. I was just with bad word choice
3. This is an alternative to ARP(which doesnt return IP's on public networks) on public networks to be used by network administrators. If you want to think of it as a hack in that element, yes. If you're thinking it is a hack as in illegal, no. 1. Either make the string for FIND to be "Reply" with a capital R or else make the find case-insensitive with the /I switch.
2. This is how to loop through a range of numbers using FOR

Code: [Select]REM example
set range=192.168.1
for /L %%N in (1,1,254) do PING %range%.%%N | find "Reply">nul && echo Reply from %range%.%%N
I'm finally seeing results from this.... however, the return is returning even failed pings. Code: [Select]echo off
REM example
set range=192.168.1
set num=1
:loop
PING -n 1 %range%.%num% | find "Reply from"> nul
if %errorlevel% equ 0 (
echo %range%.%num% YES
) else (
echo %range%.%num% NO
)
set /a num+=1
if %num% equ 255 goto next
goto loop
:next
echo Completed pinging range %range%
This is an awesome fix thanks, just one question though; why is the router not returning as existent?
304.

Solve : Batch file completion?

Answer»

Hello

OS: Windows XP
App: Access 2003 SP3

I am running a Batch file in VBA (see code below). I want to ensure the Batch file completes it's work (CREATING a TXT file) before moving onto the
next line of VBA. I currently Loop 20 million times before moving to the next line of VBA. This is a workaround... I'm looking for a solution.

VBA....
  'Run external Batch file to collect documents
  Shell ("c:\BatchFile.bat"), vbMinimizedNoFocus
  'Pause VBA until Batchfile completed!
VBA....

Any help would be GRATEFULLY appreciated.

Regards
MikeThere are a COUPLE of ways to do this. This link describes one of them. I would suggest you run the shellandwait function in a loop until you receive a success return code.

Another possibility is to create a Windows Shell object in your code and use the run method to execute your batch file. Unlike the VBA shell command, the run method has a wait on return PARAMETER you can set to true.

Good luck.  Many thanks... ShellAndWait works just perfect!

305.

Solve : File attribute change - run as administrator?

Answer»

I need to copy / overwrite approxiamately 200 files located on a network share into a workstation subdirectory with 20 read only files.  The target directory has an existing 300+ files.  The target workstations do not have LOCAL admin rights.  I've created a successful batch file, but it runs as the local user account logged into the MACHINE and it generates "access denied" error. 


On a side note, I've used a tool by Dell, called KBOX and attempted to syncronize the files but it does not work either.  My goal is to get the files copied to the workstations that USERS have no permissions to.  If anyone can help with another solution that would be great too.

Below is what I got so far.  Can I run the attrib command on the same line.  I can get the DOS window to pop up in run as mode, but can't SEEM to PASS my attrib command.

runas /user:strhospital\jortiz "cmd.exe attrib -r c:\program files\paragon94\."

306.

Solve : Batch trim audio files at regular/sequential intervals?

Answer»

(hope I didn't post this twice - I think I was logged off on my first try)

I'm trying to efficiently create sequential two minute clips from a library of wav files.  This sounds like a batch file to me but I haven't been able to solve the problem on my own.

Details: I have about 200 wav files spread over MULTIPLE directories and subdirectories. Each file is 10 to 20 minutes long.  I want to take each file and make several two minute wav files from them.  For example, if I had a 10 minute file named x, I want the output to be 1x, 2x, 3x, 4x, 5x where file 1x is  a clip of the first two minutes of x, 2x is a clip starting at minute 2 and ending at 4 and so on.  Ideally these would end up in a folder with the name of the parent file.  I can easily do this with a single file using the Regular Interval Labels tool in Audacity but I don't know of a way to use this tool to process multiple files at once.

Does anyone have suggestions for me?  I'm not experienced with for loops, but I thought maybe the combination of a for loop and an audio utility in Cygwin might do the job.  However, I’m not familiar with a utility that can do this.

This is my first post here and I hope I'm not repeating a question that's been asked PREVIOUSLY.  I haven't found anything similar in my searches but just let me know if I should be looking at a past thread.  Also, let me know if you need more information from me.

Am I'm using:
XP
MS DOS 5.1.2600
Cygwin 1.7.7
Audacity 1.3.12 Bata
GoldWave 5.58

Thanks for any help you can offer!Out of curiosity, why do you want to break up these audio files?  The answer might help some one else to offer a solution. Quote from: rthompson80819 on October 18, 2010, 04:26:34 PM

Out of curiosity, why do you want to break up these audio files?  The answer might help some one else to offer a solution.

Hi rthompson,

Thanks for the suggestion.  The RECORDINGS are of bird choruses and the two minute segments will be used to test volunteer bird counter's ability to identify BIRDS by song.  Maybe the best thing to do process each file on its own but I thought if there was a better way I should learn it.

Thanks. Code: [Select]MS DOS 5.1.2600
There is no such animal; I BELIEVE you mean Windows XP command line which is not MS-DOS.

If you can get the files into mp3 format, which is a trivial undertaking, you can use a tool called mp3splt which (among other things) can split an mp3 file into equal sized parts

Quote
mp3splt -t 10.00 album.mp3 [Split album.mp3 in many equal-sized parts of 10 minutes each.]

mp3splt album.mp3 10.12 14.25 -o out.mp3 [Split album.mp3 starting at 10min 12sec, ending at 14mins 25sec and save the mp3 slice in a new file called out.mp3]

http://labnol.blogspot.com/2006/10/mp3-cutters-split-mp3-files-into.html



Great, thanks Salmon Trout!  mp3splt looks like just what I need.  And you are correct of course, I'm using the XP command prompt v. 5.1.2600.  Not sure way I wrote MS DOS... I do know better
307.

Solve : Sound and Hidden Legacy Support??

Answer»

Hey guys, I'm confused. 

Loaded MS-DOS on my Acer Aspire One (AOA150).  It works just dandy.  I loaded mouse.com. and my touchpad worked.  But here's the confusing part:

I plugged in a USB mouse, and it worked.  No USB DOS drivers at all.  I checked the BIOS for LEGACY Support, and there was none.  But, if a USB mouse works without a DOS USB driver, doesn't this automatically mean that there is legacy support in the BIOS?  Does this mean that my BIOS has legacy support, but it is on by default and hidden?

My second question:
Now that the mouse works in DOS, I'd like to tackle, or at least explore, the much harder issue of getting sound to work.  Using the program lspci from linux, I found that my onboard audio is "N10/ICH7 Intel (rev. 2)".  At least, I hope this is accurate.  Is there a driver that can make this work in DOS?   And if my BIOS has legacy support, but it's hidden and undisclosed (weird), I assume that sound would/could already be working with no driver at all?

Any help is most appreciated, and if you GET sound working on my DOS netbook, I will let you have three of my five daughters (or credit you in a little multiboot DOS guide I'll write up -- your pick).

Quote from: princethrash on October 20, 2010, 10:05:07 AM

Hey guys, I'm confused. 

Loaded MS-DOS on my Acer Aspire One (AOA150).  It works just dandy.  I loaded mouse.com. and my touchpad worked.  But here's the confusing part:

I plugged in a USB mouse, and it worked.  No USB DOS drivers at all.  I checked the BIOS for Legacy Support, and there was none.  But, if a USB mouse works without a DOS USB driver, doesn't this automatically mean that there is legacy support in the BIOS?  Does this mean that my BIOS has legacy support, but it is on by default and hidden?
Yes. It does. Mouse.com only works with Serial and PS/2 mice. Therefore the USB mice is acting as one of the two; almost certainly PS/2.


Quote
Now that the mouse works in DOS, I'd like to tackle, or at least explore, the much harder issue of getting sound to work.  Using the program lspci from linux, I found that my onboard audio is "N10/ICH7 Intel (rev. 2)".  At least, I hope this is accurate.  Is there a driver that can make this work in DOS?   And if my BIOS has legacy support, but it's hidden and undisclosed (weird), I assume that sound would/could already be working with no driver at all?

Any help is most appreciated, and if you get sound working on my DOS netbook, I will let you have three of my five daughters (or credit you in a little multiboot DOS guide I'll write up -- your pick).

"N10/ICH7 Intel (rev. 2)" is the IDE/SATA controller....

Chances are, with a netbook, or really any laptop, is that it uses Host-based processing, for example, it may claim to have say a "realtek high definition audio controller" or something to that EFFECT, but what this generally means is that the "controller" defers all the actual processing of the sound to the CPU. (I'm not sure if they've changed this). This is largely redundant- you would almost certainly need the sound device to emulate a Sound Blaster in order to use it. DOS does not and has never had native sound support; generally you would buy a sound card back in the good old days and it would come with a driver disk, and then you'd change config.sys to load the driver with very specific settings (and you would need to flip about jumpers and whatnot on the actual card to match the settings you choose in config.sys, and hope it doesn't conflict with something).

the drivers, however, were wholly unneeded a lot of the time. First off- DOS never emits sound through the sound card, and programs that did use the sound card would look for a certain environment variable, the "BLASTER" variable. this commonly set like this in autoexec.bat or config.sys:

Code: [Select]SET BLASTER=A220 I5 D1 H5 P330 E620 T6

This tells the game/program where to look for a sound card. IN fact I cannot think of a single game that needed you to load the included "drivers" disk, aside from the fact that it added this environment variable for you. Basically, I'd throw something like that into autoexec.bat and run a game/program that uses audio. NOTHING included with DOS uses the sound card AFAIK.BC,

So I guess the question is, can this netbook's hardware emulate a SB?

I was playing with autoexec.bat SET BLASTER before posting, and I also tried your line, matching my programs configurations to the line (hex, dma, irq), but it still isn't working.  I'm not new to these things, I have adjusted jumpers on modems back in DOS and Win95 days, and have editted config/autoexec many-a-time.

I think I need to identify the audio hardware before I can really diagnose the issue, do I not?  So I can find out if it emulates an SB?  I am unsure how to do this.  I used DOS for years, and I am aware that drivers were not needed, the reason I mention drivers now is because, I assume, only some boards emulate SB (aka, DOS compatible) and others might need some "help".

As I said, I used lspci in linux and the only line with the word "audio" in it did indeed describe this as n10/ich7.  Are you sure these designations refer only to IDE/SATA, and not something more general?
308.

Solve : pasword protection?

Answer»

Hi to all.

I am kinda a biginer, and i am error prone with the writing of batch files.
I have written a program that is sopposed to open a HIDDEN folder, on my usb memory device I made it work once, but i accidentally erased a part of it, but it worked before i erased.

The file goes LIKE this...

echo off
color 0c
title lOGIN



echo             000PASSWORD0  000
echo           00000000000000   0000
echo         00000000000000000   0000000
echo          0000000000000000000   0000000000
echo        000000000000000000000    0000000000
echo       00000000000000000000000   00000000htp0
echo      000000000000000000          0000000htp00
echo       0000000000000000000          0000HTP000000
echo      0000000000000000000            000HTP0000000
echo    0000000000000000000            000000HTP0000
echo   00000000000000000000           0000000HTP0000
echo   000000000  000 000000     0000  00000000000000
echo  0000000000  00   00000      00000000000000000000
echo  000000000        00000       0000000000000000000
echo  000000000         00000       0000000000 0000000
echo  000000000         00000           00000  0000000
echo  000000000000     000000                  0000000
echo  000000000000      00000                00000000
echo  000000000000       000                0000000000
echo   00000000000                         0000000000
echo    000000                            00000000000
echo    0000000                               000000
echo     0000000                            0000000
echo      00000000                         00000000
echo       00000000                   00000000000
echo        0000000000000         00000000000000
echo          000all_files_will_be_deleted0000
echo            0after_3_incorect attempts00
echo               0000000WILLBURN000000


echo Welcome, zERoBurN
echo Continue?
pause

cls
echo sensitive information
ECHO pasword REQUIRED

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto NO

:YES
start "allinfo"
exit


:no

echo incorrect password....
pause

cls
echo sensitive information
ECHO pasword required

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto next1


next1
echo incorrect password....
pause

cls
echo sensitive information
ECHO pasword required

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto next2

:next2
echo incorect password

pause


echo you have been terminated
echo This file and all subfoders are now deleted
del allinfo\access.bat
shutdown -i
pause



I was also having trouble with getting it to shutdown. any help would be nice, or anything you think i should add. the reason for the no directory name is that computers change the name of the directory a lot, so i want it universal, this feature worked before.

and the immage at the biggining looks deformed, but that is the diference between notepad and this.\

Thanks for all the helpalso, to add, i am on a vista system right now, but i primarily use xp. I still want it universal for any windows computer
thankstry This
CODE: [Select]echo off
color 0c
title lOGIN
cd..



echo             000PASSWORD0  000
echo           00000000000000   0000
echo         00000000000000000   0000000
echo          0000000000000000000   0000000000
echo        000000000000000000000    0000000000
echo       00000000000000000000000   00000000htp0
echo      000000000000000000          0000000htp00
echo       0000000000000000000          0000HTP000000
echo      0000000000000000000            000HTP0000000
echo    0000000000000000000            000000HTP0000
echo   00000000000000000000           0000000HTP0000
echo   000000000  000 000000     0000  00000000000000
echo  0000000000  00   00000      00000000000000000000
echo  000000000        00000       0000000000000000000
echo  000000000         00000       0000000000 0000000
echo  000000000         00000           00000  0000000
echo  000000000000     000000                  0000000
echo  000000000000      00000                00000000
echo  000000000000       000                0000000000
echo   00000000000                         0000000000
echo    000000                            00000000000
echo    0000000                               000000
echo     0000000                            0000000
echo      00000000                         00000000
echo       00000000                   00000000000
echo        0000000000000         00000000000000
echo          000all_files_will_be_deleted0000
echo            0after_3_incorect attempts00
echo               0000000WILLBURN000000


echo Welcome, zERoBurN
echo Continue?
pause

cls
echo sensitive information
ECHO pasword required

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto NO

:YES
start "allinfo"
exit


:no

echo incorrect password....
pause

cls
echo sensitive information
ECHO pasword required

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto next1
goto YES


:next1
echo incorrect password....
pause

cls
echo sensitive information
ECHO pasword required

:password
set input= password =
set/p input=password (input then press enter):
if %input%==willburnyou goto YES
if not %input%==willburn goto next2
goto YES

:next2
echo incorect password

pause


echo you have been terminated
echo This file and all subfoders are now deleted
del allinfo\access.bat
shutdown -s
pause

309.

Solve : loggin console output of batch to text file without using redirect?

Answer»

Hi,
Can any one PLZ help me for the following case:
I want to save batch FILE console output with out using a redirect ie if we USE redirect command ">" the we have to execte batch in following way:
C:\mybatch.bat >C:\batchlog.txt
I need it to be in same batch file only, so that by only PASSING argument as -log="path to save batch'c log" that batch execute
as well as simultaneously record its console output  in text file.!

Thanks in advance ..!

ArpanBatch code does not support named arguments. However you might tag each command in your batch file with %2 which if -log= is present would redirect the output, and if not present, there would be no redirected output:

batchfile.bat
Code: [Select]command1 %2
command2
command3 %2

if you run the batch file as batchfile -log=">>path to save batch'c log", the output from commands 1 and 3 would be redirected. If you run the batch file as batchfile with no parameters, then none of the command output would be redirected.

 

Note: This method is not best practice. Readability would be increased if you simply used positional arguments on the command line. Not everyone might recognize that -log=">>path to save batch'c log" resolves to two parameters.

310.

Solve : Batch file/Terminal server help?

Answer»

Right, apologies i this has been asked, I did search but I am at work and extremely BUSY so didn't get to look completely. I'm also quite new to batch files.


Basically, I am trying to write a batch file to do the following:

1. Open a program (this works)
2. Login to TERMINAL server (this works)
3. Open a program on terminal server
4. Open ANOTHER program on terminal server

All from one batch file, on the local machine

What is the command to execute a program on a terminal server, from a local machine? I've tried \\tsclient\ "C:\file PATH", and other variations, but that doesn't work. Is it EVEN possible?

Many Thanks!Or ofcourse if that's not possible, is it possible to CALL a batch file on the Terminal server, from the Batch on the local machine?

311.

Solve : save .dbf file to .csv by opening it..!?

Answer»

hey folks .
I m new born child in dos n batch programming.
I NEED to WRITE a code in dos commands/batch program, which can OPEN a file(.dbf) from my computer and save it in a DIFFERENT format(.csv) on my computer.

can u help me ..its a litle urgent ..plz

rgds,
pcA .dbf file could belong to one of many applictions, which is it ?

However, I unless there is a CONVERTOR application, it is unlikely that you will be able to do this with a batch; vbscript might help you.

312.

Solve : output files based on two FIND criterias with .bat file.?

Answer»

I wrote a .bat script that will search a folder for files with file names that were modified on todays date and then output the results to a .txt file.  I want to change it to only return files that were not modified on todays date.  I tried to use /V in the second FIND statements, but it appears to apply the /V to both FIND statements.

Code: [Select]for /f "tokens=2,3,4 delims=/ " %%a in ('DATE /T') do set date=%%a/%%b/%%c
dir  "c:\temp"  /s  /ta  /a-d  | find "%test_script.txt% %script_test.txt%" | find "%date%" > c:\temp\list.txt
This is my /V attempt that does not do what I want.
Code: [Select]for /f "tokens=2,3,4 delims=/ " %%a in ('DATE /T') do set date=%%a/%%b/%%c
dir  "c:\temp"  /s  /ta  /a-d  | find "%test_script.txt% %script_test.txt%" | find "%date%" /V > c:\temp\list.txt

If you know how to modify this script to meet my needs let me know.

Thank youTry puting the /V switch after FIND and before the string. e.g find /v "%date%"

By the way, (1) did you really want to set a variable (%date%) with the same name as a system variable? (2) The /ta switch is time last accessed which is not necessarily the time a file was last modified. Maybe you need /tw (time last written) switch.

Why don't you just use FOR to find the modified date directly? 



The /V is in the wrong place in my post.  I am using it in directly after the find.

1. I can change the variable name.  Nice tip.

2. I should change the /ta to /tw.

I do not know how to use FOR to find the date directly.  Feel free to modify what I have and help me out.

Thank you for your help.I will have a try with some ideas I have... could you do one thing for me?

Open a command prompt and type

echo %date%

and copy and paste here what you GET?

I need to see your local date format

Thu 10/28/2010

That is the date format. 

The first line of my script returns "10/28/2010".


Thank you for your help.What sort of output do you get from this?


Code: [Select]
echo off
for /f "delims=" %%A in ('dir /s /b /tw c:\temp') do (
echo %%~tA %%~dpnxA
)

I have 3 test files.  Your script returns all of them.  These are the only three files in c:\temp.


10/28/2010 10:20 PM c:\temp\test_1.txt
10/28/2010 10:21 PM c:\temp\test_2.txt
10/11/2010 02:18 PM c:\temp\Test_3.txt
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
try this

Code: [Select]echo off
setlocal enabledelayedexpansion
set TodayDate=%date%
echo Today is %TodayDate%

REM create at least one file with todays date for test
echo hello>c:\temp\TodaysFile.txt

for /f "delims=" %%A in ('dir /s /b /tw /a-d c:\temp') do (
set FileDateTime=%%~tA
set FileDrivePathnameExt=%%~dpnxA
for /f "tokens=1-2 delims= " %%D in ("!FileDateTime!") do set DatePart=%%D
if "!DatePart!"=="%TodayDate%" (
echo Keep   !FileDrivePathnameExt!
) else (
echo Remove !FileDrivePathNameExt!
REM IN next line remove REM to actually remove the file
REM DEL "!FileDrivePathnameExt"
)
)
As you wrote it, it returns all files.  I think the problem is the TodayDate string.  I modified it to use my date string and now it tells me which files to keep.

I do not want to remove any files as they are already overwritten daily.  I just need a quick check to tell me which files were not UPDATED today, indication of an error.  I want to search for them by name as I did in my script. 

The folders will have other files that I want to exclude from the scope of this script, so I must search for them by name, and identify which ones I named in the FIND do not have a modified date of today.  I think what you have is really close though.



(Update) I realised that you want to output a list of files modified before today's date to a text file.

Code: [Select]echo off
setlocal enabledelayedexpansion
set TodayDate=%date%
if exist output.txt del output.txt
echo Files modified before date: %TodayDate%>output.txt
echo.>>output.txt
set filesfound=0
for /f "delims=" %%A in ('dir /s /b /tw /a-d c:\temp') do (
set FileDateTime=%%~tA
set FileDrivePathnameExt=%%~dpnxA
for /f "tokens=1-2 delims= " %%D in ("!FileDateTime!") do set DatePart=%%D
if not "!DatePart!"=="%TodayDate%" (
                     echo Modified: !DatePart! File: "!FileDrivePathnameExt">>output.txt
                     set /a filesfound+=1
                     )
)
echo Files found: %filesfound%

The output your latest version returns is below.  The only thing I need is to only apply the search to the named files like I was doing in my script.  And output the filename and date modified.  This is almost what I need.

Thank you for your help so far.



Files modified before date: Fri 10/29/2010

Modified: 10/25/2010 File: "FileDrivePathnameExt"
Modified: 10/22/2010 File: "FileDrivePathnameExt"
Modified: 10/25/2010 File: "FileDrivePathnameExt"
Modified: 10/25/2010 File: "FileDrivePathnameExt"
Modified: 10/29/2010 File: "FileDrivePathnameExt"
Modified: 10/28/2010 File: "FileDrivePathnameExt"
Modified: 10/25/2010 File: "FileDrivePathnameExt"


Code: [Select]echo off
setlocal enabledelayedexpansion
set TodayDate=%date%
if exist output.txt del output.txt
echo Files modified before date: %TodayDate%>output.txt
echo.>>output.txt
set filesfound=0
for /f "delims=" %%A in ('dir /s /b /tw /a-d c:\temp ^| find "%test_script.txt% %script_test.txt%" ') do (
set FileDateTime=%%~tA
set FileDrivePathnameExt=%%~dpnxA
for /f "tokens=1-2 delims= " %%D in ("!FileDateTime!") do set DatePart=%%D
if not "!DatePart!"=="%TodayDate%" (
                     REM this was an error
                     REM Replaced exclamation mark at the end of !FileDrivePathnameExt!
                     echo Modified: !DatePart! File: "!FileDrivePathnameExt!">>output.txt
                     set /a filesfound+=1
                     )
)
echo Files found: %filesfound%that does not return anything.  i have 3 test files.  one has a modified date of "10/29/2010".  Could it be that your date string reads Fri 10/29/2010.

thank you for your continued help. Quote

"%test_script.txt% %script_test.txt%"

What do these variables hold?

Those are file names.  I need to check just the file names I include in those strings for modified dates <> today and return them.

In my test c:\temp folder I have three files

script_test.txt          modified:  10/28/2010
test_script.txt          modified:  10/29/2010
not_included.txt      does not matter because it is not named in the script.

The goal would be to return:
script_test.txt         10/28/2010

This would tell me quickly that this file was not updated so I could troubleshoot the process responsible for updating that file.  I have to check a ton of folders each morning.  My ultimate goal is the clean up the process, but in the meantime I need this to take less of my DAY.  New jobs have their quirks.

Thank you.
313.

Solve : How to install a software autiomatically by using batch file?

Answer»

Hi all,

   DAILY i am installing many softwares in my system, everytime while installing i need to give "Next, Next, I agree buttons", So i DONT want to do everytime, Hence i need a software or batch FILE to schedule the INSTALL autiomatically. Can any one HELP?You might try running the installer from the command line and using the /? switch. This may display some help for running an unattended install.

An alternative would be a VBScript where you could send keystrokes to the installer program. This would take some planning so the keystrokes are timed properly and are in the proper sequence.

Good luck.

314.

Solve : how do I delete a primary partition both C: and D: are primary???

Answer»

I want to delete the D: Partition and expand the C: partition, but the OS says no, how do I tackle the problem or what DOS command do I use to delete D:??
What is on your D: partition?

If its your recovery drive, i would not advise it.What partition is the OS on (and page file) ?

Make SURE you have full admin rights.

After moving off or backing up all the data you want from the other drive you will be removing, try use 'Disk Management'.

Under Control Panel > Administrative Tools > Computer Management

On the left side bar you have:
Storage > Disk Management

You should see VOLUMES C:\ and D:\
Status will tell you System, BOOT, Active, Partition, Page File, etc.
Note - make sure you don't try remove the primary partition with boot, system and page file.

You should be able to delete the other volume and then extend the primary partition to claim back the free space.
Azzaboi

Lets hope thet dont follow your advice and delete the recovery partition.

You should gather more infromation before throwing 'advice' into the wind and hoping for the best. Sometimes telling the OP what they ask for straight away does not necessarily help them. Occasionally they dont know why or what they are asking!

no offence pwb67220reddevilggg -

You already previous meationed the possible "recovery partition",
and I said "After moving off or backing up all the data you want from the other drive you will be removing",
as well as "Note - make sure you don't try remove the primary partition with boot, system and page file."

Shrugs, sorry but I won't treat any user as a complete noobie - that's already Vista's job, lol.

Quote from: Azzaboi on October 30, 2010, 10:23:43 PM

Shrugs, sorry but I won't treat any user as a complete noobie - that's already Vista's job, lol.

Even THOUGH they have listed their experience as beginner, well done. Which indicates that they might not even know what a recovery drive is or does.

Your so quick to give advice and not so good at taking it. You can do more harm than good. ( Suppose its all part of growing up)
315.

Solve : Old files deletion?

Answer»

Hi all,

   Im looking for a batch script which will delete older than 7 days file. i have script which will copy some files into the FOLDER in .yyyddmm format.

   Everyday folder size will grow - To avoid FREE space issue, need a script which will KEEP last 7 days files and the older files need to be deleted permanently.

Please help me on this

Regards
Paulwintech

Copy and paste the batch file given in the first POST of the link and save it.

http://www.computing.net/answers/programming/delete-files-older-then-xdays/15229.html

Now you can read this part of the batch file for help:

Code: [Select]:SYNTAX
Echo.
Echo USAGE:
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo Where:
Echo [Days] = Number
Echo Determines the number of days previous to Today that will be selected.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG" Deletes all LOG files older than 5 days.
Echo.
Echo [Dir] = Path
Echo "Delete-Files.bat 120 C:\Temp *.LOG" Deletes all LOG files from the
Echo "C:\Temp" directory that are older than 120 days.
Echo.
Echo [File-Extension] = wildcards and extension
Echo This detemined which files or file-types that will be deleted.
Echo.
Echo Wildcards are allowed. [* ?]
Echo Examples: [*.* , *.LOG , ~*.*]
Echo.
Echo Example: "Delete-Files.bat 15 C:\Temp *.LOG"
Echo Example: This will delete all LOG files older than 15 days from C:\Temp
Echo.
Echo [Sub-Directory Search] = 1 or 0
Echo.
Echo Possible values {0 , 1}
Echo A value of "0" or blank, will not search sub-directory for possible files
Echo to delete.
Echo.
Echo A value of "1" and only "1", will search every directory underneath the
Echo the specified directory. If C:\Temp and "1" then C:\Temp and C:\Temp\srbackup\..
Echo will be searched and evaluated for file deletion.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG 1"
Echo This will search C:\Temp and ALL sub-directories for *.LOG files, older
Echo then 5 days and delete them.
Echo.
Echo Example: "Delete-Files.bat 5 C:\Temp *.LOG"
Echo This will search ONLY C:\Temp for *.LOG files older than 5 days and
Echo delete those that qualify.
Echo.
Echo [Read_Only_Delete] = 1 or 0
Echo WARNING!
Echo The Sub-Directory Search value must be present for this to work.
Echo.
Echo This fifth control-switch will force the deletion of Read-Only files.
Echo Enter a "1" if the forced deletion of Read-Only files is wanted.
Echo Leave the value empty or specify "0" to keep Read-Only untouched.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and will
Echo be deleted even if Read-Only. This switch will delete regular and Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 0 0"
Echo This will delete all LOG files, over 120 days, in C:\Temp, and
Echo will NOT delete Read-Only files.
Echo.
Echo Example: "Delete-Files.bat 120 C:\Temp *.LOG 1 1"
Echo This will delete all LOG files, over 120 days, in C:\Temp, in all subdirectories of C:\Temp
Echo and will delete files Read-Only and regular.
Echo.
--------------------
Echo Delete-Files.bat [Days] [Dir] [File-Extension] [Sub-Directory Search] [Read_Only_Delete]
Echo Delete-Files x C:\ wildcard.ext 0 or 1 0 or 1
Echo.
Echo Mandatory: "Delete-Files [Days] [Dir] [File-Extension]"
Echo "Delete-Files 180 C:\Temp *.Log"
Echo.
Echo -- End of help --

316.

Solve : How to prompt for a string and upshift the input.?

Answer»

Anyone know how to prompt for a value and upshift the INPUT?

I need a table name before calling SQL Plus and it has to be in upper case.

ThanksFound this in the snippet closet. KNEW it would be needed someday. You'll need to tweak this for your needs, but this will convert a string entered at the prompt to UPPERCASE:

Code: [Select]echo off

setlocal enabledelayedexpansion

set /p DB=Enter Database Name:

set u=ABCDEFGHIJKLMNOPQRSTUVWXYZ
set L=abcdefghijklmnopqrstuvwxyz

set database=%db%
for /l %%b in (0,1,25) do call :u !l:~%%b,1! !u:~%%b,1!
echo "%db%" has been converted to "!database!"
GOTO :eof

:u
  set "database=!database:%1=%2!"
  goto :eof

Good luck.

317.

Solve : Making Multiple folder(s) with batch File?

Answer»

Hello Everyone, I WOULD like some help making a batch FILE as a side project for modding games,
I would like the batch file to make multiple folder(s) with it's file name of my choice.
But will make FOLDERS in this style Eg.
My folder(1)
My folder(1)
My folder(1)
My folder(1)

The numeric value changing every new folder or coped folder
there is a long way of doing this but i NEED a lot of folders

echo on
mkdir Fallout3Mod #(NUMBER) <<< maby a %andom% on the end of the file name???
copy Fallout3Mod # (Same Dir, new numeric value)
Batch.batYou WANT to use FOR /L ... do
for /?
at the command prompt to see how it works

318.

Solve : Syntax problem with the FOR command?

Answer» HI,

I'm trying to extract File extensions (8.3) from a text file but I can't get it to work, any ideas?  Here is the code i'm trying to use:

    DIR "C:\test\datafile.*" /b > C:\data.lst"
   
    FOR /F "eol= " %%i IN (C:\data.lst) DO (
       SET FileExt=%%i:~9%
       ECHO %FileExt%
    )


The contents of "C:\data.lst" looks like:

    datafile.1
    datafile.7
    datafile.25
    datafile.98
    datafile.167
    datafile.817


ThanksI figured it out, I NEEDED to use the SETLOCAL command and instead of using % I needed to use !.  This is the syntax I'm using:

    DIR "C:\test\datafile.*" /b > "C:\data.lst"
   
    SetLocal EnableDelayedExpansion
    FOR /F "eol= " %%i IN (C:\data.lst) DO (
       SET DataFile=%%i
       SET FileExt=!DataFile:~9!
       ECHO !FileExt!
    )
    EndLocal

If anyone has any better ideas to do this, I'm all ears!!set fileExt=%%~xi

type FOR /? at the prompt for full help
319.

Solve : i need help with batch files??

Answer»
how do i CREATE a BATCH file which will create a folder at the ROOT of the C drive? More HOMEWORK?yesSorry. As I told you in the other threads, we don't do homework.
320.

Solve : OR operator?

Answer»

I've searched a lot for this but I can't find the answer. What I want to do is the following (doesn't work otherwise I wouldn't have opened a new topic  )

Code: [Select]IF "%1" == "help" OR "%1" == "--help" OR "%1" == "-help" (
ECHO:HELP FILE
GOTO :EOF
)
If this is something mentioned, please point me to that topic. Thanks in advance.I am presuming you mean NT/W2K/XP/Vista/W7 cmd.exe - there is no OR operator in batch language, so you have to build the test manually. Here is an example:

Code: [Select]set bool=0
IF "%1"=="help" set /a bool+=1
IF "%1"=="--help" set /a bool+=1
IF "%1"=="-help" set /a bool+=1

IF %bool% GTR 0 (
    ECHO:HELP FILE
    GOTO :EOF
)


alternative format for incrementing %bool%

Code: [Select]set /a bool=%bool%+1This is exactly what I was looking for! THANK you, it makes a lot of sense the way you do it That code above will work with "help" or "--help" or "-help" but would fail with HELP or --HELP or -HELP so if you want the string tests to be case insensitive use IF with the /I (or /i) switch


Code: [Select]set bool=0
IF /I "%1"=="help" set /a bool+=1
IF /I "%1"=="--help" set /a bool+=1
IF /I "%1"=="-help" set /a bool+=1

IF %bool% GTR 0 (
    ECHO:HELP FILE
    GOTO :EOF
)
Yep, I know I already use the /I switch. An alternative OR implemetation

Code: [Select]IF /I "%1"=="help" goto help
IF /I "%1"=="--help" goto help
IF /I "%1"=="-help" goto help

REM not asking for help
REM main code here
goto end

:help
echo Usage syntax
echo bla bla bla

:end
REM end of script

Thanks for the help, both ways work perfectly.

Now a small problem I've come across:

Code: [Select]ECHO OFF
CALL :SUBMESSAGE "first argument" "second argument"
PAUSE
GOTO :EOF

:MSG
ECHO. && ECHO:______________________________
IF /I %~2=="" (
  SET %2=Failed!
)
ECHO:[%~1] %~2
ECHO:______________________________ && ECHO.
IF /I %1=="error" (
  PAUSE
  EXIT
)

GOTO :EOF
I cannot get it work if I specify only one argument... It's related to quotes but it's still driving me crazy

Thank you in advance.I'm not surprised you can't get it to work...

Code: [Select]CALL :SUBMESSAGE "first argument" "second argument"
Where is the :SUBMESSAGE label?

Code: [Select]IF /I %~2==""
Since %~2 is the %2 parameter without (any) SURROUNDING quotes, this equality will never be satisfied.

Code: [Select]SET %2=Failed!
I don't know what you think this is going to do...




:MSG = :SUBMESSAGE, just a typo

I simply want to use a SUBROUTINE to display some messages based on the input. But the input arguments will always have quotes.

Code: [Select]ECHO OFF
CALL :SUBMESSAGE "first argument" "second argument"
PAUSE
GOTO :EOF

:MSG
ECHO. && ECHO:______________________________
IF /I %~2=="" (
  SET %2=Failed!
)
ECHO:[%~1] %~2
ECHO:______________________________ && ECHO.
IF /I %1=="error" (
  PAUSE
  EXIT
)

GOTO :EOFDid you even read my POST?
Of course I did. Well a solution would be to always use quotes and always specify %2.
Anyway, thanks. Quote from: Chem4 on November 09, 2010, 03:16:21 AM

Of course I did. Well a solution would be to always use quotes and always specify %2.
Anyway, thanks.

if you want to know if %2 is NULL (blank) then you need to do

if "%~2"=="" then [whatever]

or

if {%~2}=={} then [whatever]

or you can use any non-control character as the prefix and suffix.





Unlike some programming languages this "" is not an empty string in batch. It is a string of length 2 characters.

And you cannot do this

SET %2=Failed!

321.

Solve : Using the Path in Windows 7 doesn't like (x86)?

Answer»

Can someone tell me how to add something to the path in a WINDOWS 7 (x64) that CONTAINS (x86).
It craps out and I cannot find a command to change the contents to 16 bit versions.Here is some more information.
I need to add the Oracle_home variable to the users path and then take it away once they leve the application.
The PROBLEM is the existing PATH has "Program FILES (x86)" in it...and the '(' are causing an error.

REM Setup path for Oracle
if {%DATABASE%}=={ORACLE} (
  set OLDPATH=%PATH%
  set PATH=%ORACLE_HOME%\bin;%PATH%
)

Well I found the solution on another site.
For all those who are going to have the same problem here it is.

Add QUOTES around the PATH=... statement.

REM Setup path for Oracle
if {%DATABASE%}=={ORACLE} (
  set "OLDPATH=%PATH%"
  set "PATH=%ORACLE_HOME%\bin;%PATH%"
)

Well done!

322.

Solve : lpr command?

Answer»

Hello,

I do not have very much KNOWLEDGE about DOS, but I have been reading. I am trying to use the lpr command to print a pdf document, but is there a WAY I could incorporate the lpr command in my webpage so when the user clicks print it will execute that command? Or do you have a better recommendation to use the lpr command with a more user friendly than command prompt?
Do you WANT a visitor to go to a web PAGE and print that page?
If so, you can not just use a DOS command. You don't know what OS he has. Maybe he is using an APPLE, not DOS.
In JavaScript you can print a page.
Print a Web Page Using JavaScript
Of course, that is not for a PDF file.

323.

Solve : How to compare 2 text files in a script??

Answer»

Hello

I have to write a script that downloads a small text file from our mainframe daily. If the file has the same contents as in the file downloaded the day before then the script exits but if the files have different contents then I have to append the contents to another file  among other things that are not RELEVANT. The only challenge I have is the comparison of files as you may suspect. I have tried a couple of things but without success.  I tried this:

FC c:\Download\TodayFile.txt c:\Yesterday\File.txt \L > DIFF
Copy diff compareIt > Nul
If not exist compareIt GOTO SAME_FILE_TODAY

I also used command COMP.

I'd love to find a solution that is within DOS.

Any help is welcome.

Thanks

p.s. Please reply to this post or email me directly.





Code: [Select]FC c:\Download\TodayFile.txt c:\Yesterday\File.txt /L | FIND "FC: no dif" > nul
   IF ERRORLEVEL 1 goto different
echo Files are the same.
goto end
:different
echo Files are different.
:end
basically, we cheat and use FIND to search through the results of FC, since to my understanding FC doesn't return an errorlevel.Yep, NOTICED that too. I will give it a TRY. I am SURE it will work.

Thank you Quote from: DosStud on November 03, 2010, 05:58:41 PM

Yep, noticed that too. I will give it a try. I am sure it will work.

By taking a ride on your suggestion I decided to use it this way...

FC c:\Download\TodayFile.txt c:\Yesterday\File.txt /L | FIND "FC: no dif" > diff
COPY Diff Nul > Nul
IF ERRORLEVEL 1 goto ....

It would be straightforward if FC returned errorlevel

Thank you very much
Quote from: BC_Programmer on November 03, 2010, 05:46:46 PM
to my understanding FC doesn't return an errorlevel.

That's odd because I thought it returned 0 if the files are the same, 1 if they are different, and 2 if one or both files do not exist.

Code: [Select]echo off
echo hello > test1.txt
copy test1.txt test2.txt>nul
echo goodbye > test3.txt
fc test1.txt test2.txt>nul
echo Compare 2 identical files          errorlevel=%errorlevel%
fc test1.txt test3.txt>nul
echo Compare 2 different files          errorlevel=%errorlevel%
fc test1.txt test4.txt 2>1>nul
echo compare file with nonexistent file errorlevel=%errorlevel%
fc test5.txt test4.txt 2>1>nul
echo compare two nonexistent files      errorlevel=%errorlevel%

Code: [Select]Compare 2 identical files          errorlevel=0
Compare 2 different files          errorlevel=1
compare file with nonexistent file errorlevel=2
compare two nonexistent files      errorlevel=2
Identical output on Windows XP Professional 32 bit SP3 and Windows 7 64 bit Professional. Am I being dumb here and missing something?



cool, that should make the script even shorter then; just a quick errorlevel check in the original script presented by the OP would have done the trick. For some reason I didn't even check if fc actually returned errorlevels. But you know what they say, assuming makes an *censored* out of u and some guy named ming, guess that's what I did.
324.

Solve : MKDIR: Access is Denied But Can Create Folder via Windows?

Answer»

Hi

First Post..new to MSDos

I'm trying to create a new folder using the mkdir command but get the message "Access Is Denied". There is no folder with the same name and I can create the folder if I go in via Windows Explorer.  Same user

I'm trying to install the JAVA djk for a new course I'm starting. I also need to unpack a zip file into the new folder (which I cannot create via dos but created via explorer).

I go back into dos and try to unpack the zip file (src.zip) into the new folder (src) (as dictated in the book i'm using) and I get:

java.io.IOexception: com: COULD not create directory
   at sun.tools.jar.Main.extractFile
   at sun.tools.jar.Main.extract
   at sun.tools.jar.Main.run
   at sun.tools.jar.Main.main

I'm guessing it something to do with same problem I can't use the mkdir command

Also:  IS THERE A WAY I CAN COPY AND PASTE THE DOS SCRIPT!!!!!!? Typing it could take me a while!

Thanks
Steve1.
Please specify your O.S.
Windows 7 etc. and Windows 95 are quite different.

2.
When you reply, above the Post/Preview etc buttons is Additional Options which allows you to ATTACH a file.

Alan
Hi Alan_Br

I'm using W7

How do I save the file..I can see only select all which would allow me to paste somewhere. I that what you meant?

Thanks
SteveI cannot see "Select All" unless I right CLICK for context menu options.
You are doing something wrong.

Click on Additional Options, click on Browse, then a small "file manager" will allow you to choose what to attach.

See my sshot-199.gif

Alan


[recovering disk SPACE - old attachment deleted by admin]

325.

Solve : MS DOS Memory Stick Boot Up?

Answer»

Hey I Have A Problem Which has probably wasted about 8 hours of my time, im not sure if ANYONE throughout the ms dos forum know how how to boot ms dos through a memory stick please can you help IVE been trying forever to get it to WORK

ive tried creating a virtual floppy and formatting a dos start up but even if i try running the exe just to see what happens it loads cmd and closes straight away with a wrong version error, ive tried alsorts of methods but they just leave me with the blank screen with the cursor ticking, can anyone help?

im running windows 7 and tried using a 4gb stick and 2x 2gb sticks

kadejddescribe the method you have used in (much) more detail
I am running a virtual machine (VMWARE) on my work computer, but have been wondering if it would be possible to run DOS on a WindowsXP computer (home, no vmware) from a memory stick. Any help much appreciated!I PRESUME you mean MS-DOS? Do you have a set of Microsoft floppy disks?

326.

Solve : DOS Output?

Answer»

Is there a way to simultaneously  REDIRECT the DOS OUTPUT to both the printer and a text FILE?Maybe something like this:

Code: [Select]command > file && type file
EDIT: It will probably overwrite each time THOUGH, so the file will only have the most recent command at the TOP. It won't work if you are trying to make a log. You could subsecquently use >>, but then each time the type command is executed, it will print out the whole log to the screen.

327.

Solve : batch 2 change files's created date 2 modified date?

Answer»

I NEED a batch file to copy a files modified date to the created date.Don't think this is possible. There is no native way to do this in batch so you'll need a 3rd party program called Touch. You can read about it here and if it seems helpful follow the link to the download

The DateCreated field in VBScript is read-only. If you have access to Powershell you can do this in a one-liner.

Good luck.  Thank you for your quick response! The program that you mentioned will change all selected file dates to a fixed date. That isn't what I need.

The issue is that I just bought a new phone. All of my pictures {487 of them) were transferred to the new phone, but they all are out of order. I found that all the transferred files had the same date and time which is the time that the files were xfered. The file dates are showing up correct. Looking further, the file's date is the modification date and the creation date is the date the files were transferred. It appears that the phone uses the creation date to sort the pictures, thus no sorting of the xfered files.

If anyone has any other ideas, please let me know.If you transfer files to a phone, and the phone gives them a creation date corresponding to when you transferred them, why do you think a batch file run on a computer is going to be any use?

I am TRANSFERRING to a MicroSD Card. It apparently did the same thing when I transferred the pictures to the computer the first time.

Is there a way to recopy the files while modifying the CREATE date to the modify date in the process?
Quote

Is there a way to recopy the files while modifying the create date to the modify date in the process?

No. You'll have to wait until the pictures reach their final destination before modifying any dates. How is this MicroSD card connected to the computer? If you look in My Computer does it have a drive letter assigned? Do you use the NT copy command to transfer the pictures or some sort of software that came with the phone?

The links I posted may have been unclear. FileTouch can be run from the command line and with a little imagination you can extract the modified date of a file and push it into the date created field:

Code: [Select]echo off
setlocal enabledelayedexpansion

SET picDir=c:\temp
for /f "tokens=* delims=" %%i in ('dir %picDir% /b') do (
  set dtmMod=%%~ti
  "e:\Small Applications\FileTouch\FileTouch" "%picDir%\%%i" "!dtmMod!" -c
  echo.


picDir = the location of the pictures. This is why I asked if the SD card (or phone) is assigned a drive letter
c:\filetouch\filetouch = the fully qualified path to the filetouch program; change as required

Good luck. 


Thanks, I will give it a try. The sd card is set up with a drive letter on the lan as I am now using the card slot in my printer. I was SIMPLY using drag and drop to do the transfer.
328.

Solve : Append file name with the hostname?

Answer»

I have a batch file to capture tracert and systeminfo and saving to a .txt file, though want to have the file name include the 'hostname'.  Example is the file would be tracert(hostname).txt
Tried rename and no luck.show us your batch file
Trying to capture trace routes and system info for TROUBLESHOOTING LAN/WAN performance issues and save to a file for easy association.

The batch file may be run on any workstation (hostname), the output file 'oracle.txt' may be stored with others captured from different sources, so need an easy way to manage, identify and retrieve the file for each host.  As such, the hostname is an easy way since no name is the same.

echo off
:starttrace

echo %date% %time% >>oracle.txt

echo starting trace route for Oracle

tracert oracle.es.com >>oracle.txt

echo trace route complete

systeminfo >>oracle.txt

exitWhy not just echo the results to tracert.oracle.es.com.txt?

The same batch file (trace) may run from anyone of thousands of workstations globally, so would like the file to be named specific to that trace.1. Where is the batch file GETTING the hostname from?
The batch file is run on the workstation (hostname), capturing the tracert and system information to the .txt file. The results in the file tell a lot about the path USED to reach the remote system and the current state of the workstation useful in troubleshooting remote system LAN/WAN access.

Results in the oracle.txt file from running oracle.bat

Tue 10/26/2010 12:37:12:10
Tracing route to oracle.es.com [10.40.23.234]
over a maximum of 30 hops:

1     12ms     13ms     <11ms     10.42.255.45
2     120ms   114ms   118ms      oracle.es.com [10.40.23.234]

Trace complete.

Host Name:                  ESP231456
OS Name:                     Microsoft Windows XP
OS Version:                   4.1.2.0
 - - - - ---------------------------------You want the hostname of the machine on which the batch is run to be used in the filename of the logfile? Possibly you could use the system variable %LOGONSERVER% like this...

CODE: [Select]echo off
:starttrace

echo %date% %time% >>tracert.%LOGONSERVER%.txt

echo starting trace route for Oracle

tracert oracle.es.com >>tracert.%LOGONSERVER%.txt

echo trace route complete

systeminfo >>tracert.%LOGONSERVER%.txt

exitlogonserver needs illegal characters to be removed

Code: [Select]echo off

set hname=%logonserver:\=%

:starttrace

echo %date% %time% >>tracert.%hname%.txt

echo starting trace route for Oracle

tracert oracle.es.com >>tracert.%hname%.txt

echo trace route complete

systeminfo >>tracert.%hname%.txt

exitResolved by using 'COMPUTERNAME', so the resulting file is named "ES12345-tracert.txt" for the below code line.

tracert oracle.es.com >>%COMPUTERNAME%-tracert.txt

"HOSTNAME" does not work.

Thanks for the assist.  Now, have to get support to use it.

329.

Solve : Batch script to read data in a URL and save in .csv or .txt format?

Answer»

Hi there,

I wondering if there is anyscript to do so?  This script should be able to read text  data from a URL and save in a format say .csv

Possible?

any help is appreciated!

THANKS,
Sengive example
Thanks for replying ,


say i have this url http://webcode.xyz.com/scripts/sen/ intranet site within a company. So when i go to this webpage it displays data which is text.  like

"  3/4 5:38am John O''brain  from poland  was PAGED and did initial triage. LAN was declared good. "
it does have special characters like "%..!

what I  now do is to go to file menu click save as   .csv  and then OPEN with notepad manually.

So wondering if this can be automated through batch script,
I HOPE i am clear? if not pls let me know

any insights?


Thanks,











330.

Solve : readyboost + ms-dos prompt?

Answer» HI all ..

i really need HELP ..
is there any way to activate readyboost by COMMAND prompt?

thanks a lot .. Readyboost is a Windows program which uses the Superfetch SERVICE and a USB flash drive or memory card as memory cache and performs boot optimization. It cannot work with any version of MS-DOS. Did you mean Windows command prompt? Anyhow, in a version of Windows which has Readyboost as an option, you activate Readyboost from the context menu of a SUITABLE USB device. Maybe you think there is a magic command that will enable Readyboost on a Windows version that does not support it, or a USB device that fails the compatibility test? Well, there isn't.




i see ..
thanks a lot sir .. really appreciate it ..

Quote from: Salmon Trout on November 06, 2010, 11:17:04 AM
Readyboost cannot work with any version of MS-DOS.
331.

Solve : Can batch files edit themselves??

Answer»

I was wondering if it is possible to use a batch file to edit part of another batch file (or itself)

ie:
batch1
:Label1
set name=Fuzzy

:Label2
set name=FLUFFY
-----------------------
batch2
findstr "Fluffy" batch1 ...(CHANGE Fluffy to Furry)
------------------------------------------------------------
after running batch2, batch1 would read:

:Label1
set name=Fuzzy

:Label2
set name=Furry
---------------------
is that possible? (hopefully it's at least an understandable question)Yes, it is possible -- you might have to call a helper batch to make the edit then re-invoke it, I cannot remember if a batch is locked while running - it MAY even be cached too.

However, it might be a tidier approach to store these values in a file and test against that - there would be no difficulty editing a separate text file. Also, no system manager wants to have a self-modyfing program on the system, this opens up all sorts of security issues.Depending on what code is being run, the batch file can continue without ERROR, but most often you will get some obscure error involving an unknown command (even though there isn't). Quote from: Helpmeh on November 04, 2010, 07:46:32 PM

Depending on what code is being run, the batch file can continue without error, but most often you will get some obscure error involving an unknown command (even though there isn't).

Yes, because when the command interpreter executes a command or program, it stores its position in the script, and if you alter the code size prior to that, when cmd.exe returns, it still returns to that byte position. If it now lands in the middle of a word or command, it may have NONSENSE to interpret.
That would explain it! Thanks Salmon!
332.

Solve : How to make a bat file to return the latest file name in a dir ??

Answer»

How to?
Thanks
ADH Code: [Select]for /F "delims=" %%A in ('dir /B /od /a-d') do set latest=%%~nxA
echo the latest FILE is %latest%

333.

Solve : Installing Dos6.22 from CD (I've got a problem)?

Answer»

I have a n old very basic computer I want to install Dos6.22 on, I do not have any usable floppy disk's.
I have a CD to install DOS from (I've done all the preparation etc.) It boots ok and goes through a couple of screens UNTILL it gets to one that says "format 2 floppies to make uninstall disks" It then says put disk one in "a" when ready and press any key to proceed.
I am now STUCK because I don't have any floppies that are usable and I don't really want any uninstall disks but there is no way past this screen untill you make the disks.
I did read somewhere that you can do a couple of key strokes to bypass the making of these disks (I can't find the article again)
Can anyone HELP PleaseMSDos never came on a CD....where is this CD from ? ?What difference does that make? There are loads of MSDos CD's & CD images available for free.
This is probably because floppy disks never were reliable, and most modern computers don't even have a floppy disk drive.
These CD images are the exact same MSDos6.22 but everything is in the same place.
Even if I had floppy disks that worked I would not want to create un-install disks.

I have four computers and none of them will read or write to any of the old floppy disks I had.

And yes they are not write protected.The difference it makes is that it's a copyright violation and our policy here is we do not assist wth warez. Quote from: Merv Wiz on November 10, 2010, 08:13:38 AM

Even if I had floppy disks that worked I would not want to create un-install disks.

The "true" MS-DOS install floppies do not create uninstall disks. The "upgrade" versions; for example, MS-DOS 6.22 Step-up (6.0 to 6.22) Do, however.

Otherwise, no Uninstall disks are ever prompted or created.

In either case, you should be able to skip it by RUNNING setup with the /G switch.

Patio: Since it's prompting for Uninstall disks, it sounds like an upgrade version, which MS has for free download on their site (also, they are useless without a previous installed version of DOS, iirc). How it got on a CD image I haven't the faintest, though.Thanx for the heads up BC... Quote from: BC_Programmer on November 11, 2010, 06:43:25 AM
How it got on a CD image I haven't the faintest, though.

I can guess... see above remarks about warez.
334.

Solve : copy all pro?

Answer»

Hi dear friends,
I have MP3 FILES in my c\ drive in many different folders and i want to copy all these mp3s into new one folder in drive c or another drive. Can you please help how to write this command? any idea appreciated.This ought to work, just input the folder/drive where you want to copy it all to.

CODE: [Select]echo off
:DriveIn
cls
echo.Input Drive Letter to copy MP3s to(e.g. D for D Drive):
SET /p destdrive=?
echo.
echo.Input Folder under previously inputted Destination Drive(Type
echo.nothing to copy to Drive ROOT) or (e.g. if D Drive was previously
echo.inputted, "Folder1\Music" to copy to "D:\Folder1\Music").
set /p destfolder=?
dir "%destdrive%:\%destfolder%" /B
if ERRORLEVEL GEQ 2 (
echo.Invalid Drive, please Select a different drive
pause
goto DriveIn
)
for /r "C:\" %%a in (*.mp3) do (
copy "%%a" "%destdrive%:\%destfolder%"
echo.MP3 Found and copied:
echo.%%a
echo.
)
echo.All MP3s in C Drive copied to:
echo.%destdrive%:\%destfolder%
pause
exit
Give that a whirl.

Hope this helps
,Nick(macdad-)

335.

Solve : MSDOS batch to delete folders older than 30 days?

Answer»

Hello i have the following batch file:

echo off
:: variables
set drive=W:\JoseNunes\backup
set backupcmd=xcopy /s /c /d /E /h /i /r /y

SET dd=%DATE:~0,2%
SET mm=%DATE:~3,2%
SET yyyy=%DATE:~6,4%

SET hh=%TIME:~0,2%
SET mn=%TIME:~3,2%
SET ss=%TIME:~6,2%

set dayfolder="%yyyy%-%mm%-%dd%"
set timefolder="%hh%%mn%%ss%"

echo ###checking if daily folder exists
IF NOT EXIST "%drive%\%folder%\". (
   echo ###creating dayli folder.
   md "%drive%\%dayfolder%\".
   echo ###daily folder created.
)

IF NOT EXIST "%drive%\%folder%\%timefolder%\". (
   echo ###creating dayli folder.
   md "%drive%\%dayfolder%\%timefolder%\".
   echo ###daily folder created.
)
   
echo ### Gestware BD...
%backupcmd% "C:\20988" "%drive%\%dayfolder%\%timefolder%\Gestware"

echo Backup Complete!
pause


THis batch makes a backup of some files i NEED and creates a folder with the day and inside that one with the hour.
I need to delete folder older than 30 days.


Thanks in advanceIn general, batch code does not do date/time arithmetic. I did see a batch solution once but it was 7 pages of ponderous code and seemed like a lot of overhead for what really is a simple task in any other language.

If you can, download ForFiles. This is a Microsoft batch utility you can insert into your existing batch code. After unzipping the executable into a directory, run forfiles --h from the command prompt for the online help.

You might also consider a separate VBSCRIPT or Powershell SCRIPT to do the folder aging and deleting by calling it from your batch file. Lots of possibilities limited only by your imagination.

 

336.

Solve : Help with my program!?

Answer»

I have made this PROGRAM but i have a major problem. When i run the program and try to make it act on the answers i've inserted it just takes it from the top it doesn't jump to the ":nametag" i've made. Please try it and SEE if one of ya can find the problem i really hope so.

Sincerly
Vikken

echo off
color f0
cls
echo off
setlocal
title The Program That Talks
echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if [%Answer%]==[Fine] goto :Good
if {%Answer%}=={Bad} goto :Bad

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Noway
echo Why not? Don't you like me anymore?
Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[Never] goto :Never

:Okay
echo Wee this has to be fun! But first answer this question.
set /p Answer="Are you evil? [Yes/No]> "
if [%Answer%]==[Yes] goto :1
if [%Answer%]==[No] goto :Never

:Never
echo I HATE you!
PAUSE
shutdown.exe -s -t 30 -c DIE! Code: [Select]echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if [%Answer%]==[Fine] goto :Good
if {%Answer%}=={Bad} goto :Bad

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway


You are requiring too much from the user. The first question requires a Fine/Bad response (caps included). A better approach would be to make the if statements case insensitive:

Code: [Select]if /i [%Answer%]==[Fine] goto :Good
if /i {%Answer%}=={Bad} goto :Bad

As a coder you need to be more defensive. Just because you code Fine or Bad as the correct response, there is no guarantee the user will actually pick one of them. You must be prepared for any response otherwise the code will fall through to the next instruction which is probably not what you want. In the original code, if the user enters neither Good or Fine (caps included) the code will fall into the :Good label.

Code: [Select]:howru
  echo Hello there How are you?
  set /P Answer="Please tell me. [Fine/Bad]> "
  if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i {%Answer%}=={Bad} (goto :Bad
    ) else (goto howru)

Note: the goto :label statements do not require the colon, but the :labels themselves do.  Not to be confused with the call :label statement which is used for another purpose.

Good luck.  Thx m8 I'll try that out right away.I cant get the else STAMENTS working it says it doesn't reconise them as intern or extern commando...

please helpPlease post your code. That way we'll both know what's going on.

Note: the :OKAY block of code has a goto :1 statement, but there is no :1 tag (label)

 echo off
color f1
cls
echo off
setlocal
title The Program That Talks

:howru
echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if /i [%Answer%]==[Fine] (goto :Good)
 else if /i [%Answer%]==[Bad] (goto :Bad)
 else (goto :howru)

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[No] goto :Noway

:Noway
echo Why not? Don't you like me anymore?
Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[Never] goto :Never

:Okay
echo Wee this has to be fun! But first answer this question.
set /p Answer="Are you evil? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :1
if /i [%Answer%]==[No] goto :Never

:Never
echo I HATE you!
pause
shutdown.exe -s -t 30 -c DIE!

:1
echo Good for you bye bye.
pause
exit

Please tell me you can figure it out.

Re-worked the prompt responses to prevent fall thru to the next code block.

Code: [Select]echo off
color f1
cls
setlocal
title The Program That Talks

:howru
  echo Hello there How are you?
  set /P Answer="Please tell me. [Fine/Bad]> "
  if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i [%Answer%]==[Bad] (goto :Bad
    ) else (goto :howru)

:Good
  echo That's nice. Im glad that your good.
  set /p Answer="Wanna try something fun? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[No] (goto :Noway
    ) else (goto :Good)

:Bad
  echo Ohh that's too bad. I might be able to lighten your day.
  set /p Answer="Wanna try something fun? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[No] (goto :Noway
    ) else goto (:Bad)

:Noway
  echo Why not? Don't you like me anymore?
  Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[Never] (goto :Never
    ) else goto :Noway)

:Okay
  echo Wee this has to be fun! But first answer this question.
  set /p Answer="Are you evil? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :1
    ) else if /i [%Answer%]==[No] (goto :Never
    ) else goto :Okay

:Never
  echo I HATE you!
  pause
  shutdown.exe -s -t 30 -c DIE!

:1
  echo Good for you bye bye.
  pause
  exit

That code block labeled :Never seems a bit harsh, but hey! what do I know.  Thank you so much !!! Quote

if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i [%Answer%]==[Bad] (goto :Bad
    ) else (goto :howru)

This looks over complex. What's wrong with something like this

Code: [Select]if /i [%Answer%]==[Fine] goto :Good
if /i [%Answer%]==[Bad] goto :Bad
goto :howru
By the way, I am uneasy about that shutdown stuff at the end. Childish prank scripts that shut down other people's computers are kind of borderline in terms of the CH RULES aren't they? (I'm being polite - in fact I'm sure they are well over the line.)


337.

Solve : entering directory with commond CD ... not workz if space?

Answer» HI any1 can tell me .... cd doeznt work if space b/w directori name or file name

 detail:
          V can enter any directory with commond cd but i experienced dat when there any space b/w a directory nam or file then cd commmend doesnt work

  Code: [SELECT]C:\>
C:\>
C:\>cd "\documents and settings\Kohn"

C:\Documents and Settings\Kohn>

He is saying use QUOTE MARKS.
338.

Solve : Help needed for file deletion based on file extension and specify folder?

Answer»

Hi All,

Appreciate if anyone could help =)

I'm trying to create a BATCH file that:

- delete all files in c: drive with the extension .txt, .DOC, .xls, .ppt
- deletion to EXCLUDE specific directories (c:\windows and program files and it's subfolders

The purpose of this batch files is to delete all users' doc and files in c: while preventing accidental deletion of system/application text files like virus definition.

Thank you!SORRY, we don't help with homework.Hi commando,
I think you got me wrong.

I have no problem with the file extension part.

I'm only having problem with the if/for statement to exclude the directories. Appreciate if you can provide GUIDANCE on this part.Hi all,

I managed to find a solution to this. Thank you.

339.

Solve : Command inside for loop in a batch file is not working?

Answer»

Hi All,

Can anyone shed any light why the follwoing line would work on machine but not on another:

for /f "tokens=2 delims=: " %%i in ('dir .') do set _OS_BUILDNUMBER=%%i

I get this error while execuing this from a file containing only this line:

C:\Users\User1>temp.cmd

C:\Users\User1>for /F "tokens=2 delims=: " %i in ('dir') do set _OS_BUILDNUMBER=%i
'dir' is not recognized as an internal or external command,
operable program or batch file.

But it works FINE in another machine with same OS version.

Thanks. Any help is aprreciated.

PS.

This is just an example. Practical applicability of the line is not expressed here.

I see you posted this on MSDN scripting forums 20 hours ago... I guess we should be flattered... you even MISSPELLED "APPRECIATED" identically... You haven't said what OS and service pack version you are USING on each machine. I wonder if %comspec% is altered on the machine where dir does not work, if command extensions are enabled, and if cmd.exe has been damaged. Is one of the OSs Server 2003? Do other internal commands fail in a similar way?



 Great! ComSpec was INDEED the issue. It's fixed now. Thanks.

Yay! CH 1 MSDN 0

340.

Solve : Check for case?

Answer»

Is there a simple way to check the VALUE of a variable, to determine if begins with an upper/lowercase letter? Or WOULD I have to do a case-sensitive check against a-z separately?

Thanks.Pipe the FIRST character of the variable string through findstr /R with the whole alphabet in upper case* as the regex. Then inspect the errorlevel.

*This avoids the findstr regex case bug (which is: in Windows after NT, ie 2k to 7 inclusive, findstr /r has a case sensitivity bug so that the regex for alphabetical ranges fails on all CHARS after the first so "[A-Z]" correctly rejects a but incorrectly passes b-z)

Code: [Select]echo off
:loop
set /p variable="Enter a string ? "
if "%variable%"=="ZZZ" goto end
echo %variable:~0,1% | findstr /r  "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]">nul
if %errorlevel% equ 0 (
echo 1st char is upper case
) else (
echo 1st char is lower case
)
goto loop
:end


Code: [Select]S:\Test\Batch\>casetest.bat
Enter a string ? Hello
1st char is upper case
Enter a string ? hello
1st char is lower case
Enter a string ? cat
1st char is lower case
Enter a string ? Cat
1st char is upper case
Enter a string ? a
1st char is lower case
Enter a string ? A
1st char is upper case
Enter a string ? zzz

S:\Test\Batch\>

That worked. Thanks a lot.

341.

Solve : Dos Batch: Kill parallel jobs at the same time?

Answer»

I am running the bat job(main bat) and that will call the two bats parallely at the same time,

I have tried to end the job(main bat) by ctrl+c then one bat file is getting ended, but the other bat file is still running,so again I have to do the ctrl+c to end the other bat file.

So how can I kill all the bat files at the same time and also how can i program this in the main bat job so that all the parallel jobs gets ended when I use ctrl+c.



Can some body please help me on this.



Thanks in advance. Quote

I am running the bat job(main bat) and that will call the two bats parallely at the same time,

How are you doing that? When a call is made, the calling file enters a wait state and the called file begins executing. When the called file ends, control is returned to the calling file at the next sequential instruction after the call. This occurs no matter how MANY levels of calls are used. USING ctl+C will terminate the entire run unit.

It would be helpful if you posted your code and please mention your OS.

 Thankyou..

Following is the code of the main bat file..

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Personal.bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat

Following is the code for the 2 bat files..

Following is the code of the first bat file...

setlocal
REM *********************************************************
REM * Rundate 'D'YYMMDD must be specified as first argument *
REM *********************************************************

REM *********************************************************
REM * Command-file must exist *
REM *********************************************************
FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G


set rc=%errorlevel%
REM *******************************************************
REM * Exit script and report return code *
REM *******************************************************
:done
echo rc=%rc%
exit /b %rc%

REM *******************************************************
REM * Handle argument errors *
REM *******************************************************
:noargument
echo Error: No argument specified
set rc=2
goto done
:nopgm
echo Error: Command file "%sch_command%" does not exist
set rc=2
goto done

Following is the code of the second bat file.

echo off & setLocal enableDELAYedexpansion
set toterrors=
set totjobs=
for /f "tokens=1 delims= " %%a in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a toterrors+=%%a
)
for /f "tokens=2 delims= " %%b in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a totjobs+=%%b
)
echo total errors is !toterrors!
echo total jobs is !totjobs!
goto :EOF
Wow!

Main.bat
Quote
D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Personal.bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat

The first statement will transfer control to old_Campaign_DB_Personal.bat. There is no mechanism to return, the next statement (call) will never GET executed.

First.bat
Quote
FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

Choose either start or call but not both. Note the /b switch on the start command disables CTL+C.

The Second.bat file seems OK.

It may help to map out what you expect to happen, read up on the both the start and call commands and go from there.

Good luck.
342.

Solve : Creating different version in a folder?

Answer»

Hi All,

   I have a batch script which will create a folder in 20100810(yyyyddmm) format. Here is my below requirements

1. We have some files which is modified in daily basses, so i will be creating the folder as above and copy the modified into the newly created folder using a batch file.

2. But now a days modification of files are increases(UPTO 5 times or more). according to the changes i need a batch script to check the folder for that day is created are not? If so we need create a folder inside the 20100810 folder LIKE version(20100810-v1). At the end of the day we can see how many versions(changes) are done.

Please help me on this.

Thanks & Regards
PaulwintechThis little spit of CODE might help:

Code: [Select]echo off
setlocal enabledelayedexpansion

set folder=c:\temp
set yy=%date:~10,4%
set mm=%date:~4,2%
set dd=%date:~7,2%

:loop
  set /a seq+=1
  if exist %folder%\%yy%%mm%%dd%-V!seq! goto loop
 
MD %folder%\%yy%%mm%%dd%-v%seq%

My system date format is dow mm/dd/yyyy. You may have to tweak how yy, mm, dd are assigned. Also change the folder value to something that matches your environment.

Not for nothing, but why not simply concatenate the time to the date and name your folders that way. Just a thought.

Good luck.  Thank you very much.....

Regards
Paulwintech

343.

Solve : CIPHER command?

Answer»

Hi all,
Im kindof new to DOS commands. I started making a batch file that would encrypt a message for you by shifting each letter a few letters up, then i came across the CIPHER command. I know it does not do the same thing and that it is supposed to encrypt files, but when i was messing around with it, i encrypted a few files and when i went to them nothing had changed.

What exactly does it MEAN when it says its encrypting the file, or am i doing something wrong

Thankyoua quick overview of NTFS: http://www.pcguide.com/ref/hdd/file/ntfs/otherEncrypt-c.html

Short story: Encryption is built into the NTFS file system. In order for a program to encrypt/decrypt a file, it merely needs to call EncryptFile() or DecryptFile().

The file data On-Disk is encrypted based on the current User's SID and the SID of any designated "recovery agents"; this means that the only way to decrypt the data is with a user that has one of those SIDs.

When you access an encrypted file- or more precisely, when any program accesses an encrypted file, unless they use special backup modes to access the actual encrypted data, the data is decrypted on the fly as the program reads from the file, by using the current user's SID. if the SID is unable to decrypt the file, an Access Denied Error occurs.

I am still a little unsure as to what the CIPHER command actually does. Are you saying that if i encrypt a file that another user on the same computer wont be able to see it? could you try to keep your answer a little simpler, because im quite new to all of this... Thanks Quote from: jpotts on November 15, 2010, 07:37:57 PM

Are you saying that if i encrypt a file that another user on the same computer wont be able to see it?

No. I'm saying they won't be able to access it.

Quote from: BC_Programmer on November 15, 2010, 07:41:58 PM
No. I'm saying they won't be able to access it.

Indeed. One thing that you can’t do with the Cipher tool that you can do through the GUI is give other users cryptographic access to encrypted files or folders. Windows XP and 2003 Server (unlike Windows 2000) allow the person who encrypts a file to ADD other user accounts that enable others to view his/her encrypted data. This is done through the Encryption Details dialog box (accessed VIA the Details button on the Advanced Attributes property sheet). There is no mechanism for doing this with the Cipher tool. Quote from: Salmon Trout on November 16, 2010, 12:23:18 AM
There is no mechanism for doing this with the Cipher tool.

Windows 7 or vista added a /ADDUSER switch to cipher.
344.

Solve : using one router like the "GoToMyPC" technology?

Answer»

all,

Would it be possible for me to connect to one computer that is connected to the same router as my requesting computer?  What I want to do is use my one router that I have as a substitute for a LAN.  I know that really can't be done technically, but I really want to work on, and modify files that are on my home machine in my living room, from my little netbook.   Ideally I would be in my basement working on files that are located on my desktop upstairs.

Is this sort of thing possible?  Both MACHINES would be connected to the same router, and according to the ISP, they do not recycle IPs at all, so the address would never change.

I have limited amount of knowledge about DOS, but I do understand how to connect to an IP, ping them, FTP concepts, etc...

Any help from the gurus here would certainly be appreicated!  Thanks so much! Quote from: ajetrumpet on November 20, 2010, 12:45:12 PM

Would it be possible for me to connect to one computer that is connected to the same router as my requesting computer? 
Of course.

Quote
What I want to do is use my one router that I have as a substitute for a LAN.  I know that really can't be done technically,
That's EXACTLY what it is; the computers connected to a router form a LAN.


short story: you'd need to find the lan side IP address of the computers involved. My desktop, for example, is 192.168.0.100; obviously, this has nothing to do with connecting to the internet or anything outside the LAN; other network computers can see my desktop as that IP, but outside of the LAN it's meaningless.

Usually, there is a PAGE on the router setup pages where you can see the IP assignments within the LAN for each machine. Or, you can just use ipconfig; the IP address of your machine is the LAN-side address.
345.

Solve : "invalid drive specification"?

Answer»

Hope this isnt a silly question...ive created an xp boot disk. after booting to it i type C: to get to the c drive but all i get is "invalid drive specification".

other than this everything is fine, and the COMPUTER boots ok. needles to say im doing this on an xp machine

how can i get to my c drive??

thankyou may need this kind of boot disk>http://ntfs.com/boot-disk.htmOr check out this URL  www.bootdisk.com Quote from: mbeechwood on SEPTEMBER 12, 2004, 04:35:14 AM

Hope this isnt a silly question...ive created an xp boot disk. after booting to it i type c: to get to the c drive but all i get is "invalid drive specification".

other than this everything is fine, and the computer boots ok. needles to say im doing this on an xp machine

how can i get to my c drive??

thank
Quote from: manishverma481 on NOVEMBER 23, 2010, 12:38:03 AM

Start a new thread and don't reopen threads that are almost seven years old.
346.

Solve : sync folders?

Answer»

Hi, this is my first post here, so please forgive me if I have done something wrong (posted in the wrong place or i dunno)

for /r "%~d0\Music\" %%F in (*) do if not exist "C:\Users\Polle\Music\%%~nxF" del "%~d0\Music\%%~nxF"

So basically wath I'm trying to do is this: I'm trying to use this for command to find all files on my hard drive that are no longer on my computer and delete those files from my harddrive

Now, wath this command is doing:
-It works correct in the folder "%~d0\Music"
-It does nothing in the folder "%~d0\Music\someartisthere\"

example: it checks my HARDRIVE and finds the file "%~d0\Music\ACDC\thunder.mp3"
now on my pc it should look for "C:\Users\Polle\Music\ACDC\thunder.mp3"
but it is looking for "C:\Users\Polle\Music\thunder.mp3" which does not exist
so it will try to delete "%~d0\Music\thunder.mp3" wich does not exist either

nothing happens

Can anyone help me out on this one? More INFO, I gues I didn't make myself clear:
I have an external HDD, and I want to make sure that if a file is no longer on my computer it is no longer on my external HDD either, I'm basicly trying to syncronize my external drive with my computer

heres the full script (it's mainly in dutch tough)


Code: [Select]echo off

title = Folder Backup!  (program by Polle)
color 0e
MKDIR %~d0\Muziek
MKDIR %~d0\willekeurig
MKDIR %~d0\games
MKDIR %~d0\Vuze
MKDIR %~d0\batch
MKDIR %~d0\batch\special
MKDIR %~d0\restore\registry
cls





set /P backup= Backup van alles maken? (j/n) :
if %backup% EQU j goto B

set /P muziek= Backup van muziek maken? (j/n) :
set /P willekeurig= Backup van documenten maken? (j/n) :
set /P GAMES= Backup van games maken? (j/n) :
set /P Vuze= Backup van Vuze maken? (j/n) :
set /P Batch= Backup van batch bestanden maken? (j/n) :
set /P Registry= Backup van registry maken? (j/n) :
goto A




:A


set start1=%time:~0,2%
set start2=%time:~3,2%
set start3=%time:~6,2%
set starttime=%start1%:%start2%:%start3%


title = making music backup... (program by Polle)
if %muziek% EQU j xcopy /d /c /y "C:\Users\Polle\Music" "%~d0\Muziek"
for /r "%~d0\Muziek\" %%F in (*.*) do if not exist "C:\Users\Polle\Music\%%~nxF" del "%~d0\Muziek\%%~nxF"

title = making documents backup... (program by Polle)
if %willekeurig% EQU j xcopy /s /d /c /y "C:\Users\Polle\willekeurig" "%~d0\willekeurig\"
for /r "%~d0\willekeurig\" %%F in (*.*) do if not exist "C:\Users\Polle\willekeurig\%%~nxF" del "%~d0\willekeurig\%%~nxF"

REM title = making games backup... (program by Polle)
REM if %GAMES% EQU j xcopy /s /d /c /y "C:\Users\Polle\NDS games" "%~d0\games\NDS\"
REM if %GAMES% EQU j xcopy /s /d /c /y "C:\Users\Public\Games\World of Warcraft\instal" "%~d0\games\WoW\"
REM for /r "%~d0\games\NDS\" %%F in (*.*) do if not exist "C:\Users\Polle\NDS games\%%~nxF" del "%~d0\games\NDS\%%~nxF"
REM for /r "%~d0\games\WoW\" %%F in (*.*) do if not exist "C:\Users\Public\Games\World of Warcraft\instal\%%~nxF" del "%~d0\games\WoW\%%~nxF"

title = making Vuze backup... (program by Polle)
if %Vuze% EQU j xcopy /s /d /c /y "C:\Users\Polle\Vuze" "%~d0\Vuze\"
for /r "%~d0\Vuze\" %%F in (*.*) do if not exist "C:\Users\Polle\Vuze\%%~nxF" del "%~d0\Vuze\%%~nxF"

title = making batch backup... (program by Polle)
if %Batch% EQU j xcopy /s /d /c /y "C:\Users\Polle\Desktop\danger" "%~d0\batch\"
if %Batch% EQU j xcopy /s /d /c /y /h "C:\Program Files\CwindowsMD" "%~d0\batch\special\"
for /r "%~d0\batch\" %%F in (*.*) do if not exist "C:\Users\Polle\Desktop\danger\%%~nxF" del "%~d0\batch\%%~nxF"
for /r "%~d0\batch\special\" %%F in (*.*) do if not exist "C:\Program Files\CwindowsMD\%%~nxF" del "%~d0\batch\special\%%~nxF"


REM title = making registry backup... (program by Polle)
REM if %Registry% EQU j xcopy /s /d /c /y "C:\regbackup" "%~d0\restore\registry\"
REM for /r "%~d0\restore\registry\" %%F in (*.*) do if not exist "C:\regbackup\%%~nxF" del "%~d0\restore\registry\%%~nxF"


set stop1=%time:~0,2%
set stop2=%time:~3,2%
set stop3=%time:~6,2%
set stoptime=%stop1%:%stop2%:%stop3%

set /A result1=%stop1% - %start1%
set /A RESULT2=%stop2% - %start2%
set /A result3=%stop3% - %start3%
set resulttime=%result1%:%result2%:%result3%

cls
echo start = %starttime%
echo stop = %stoptime%
echo duration = %resulttime%
pause


exit






:B
set muziek=j
set willekeurig=j
set GAMES=j
set Vuze=j
set Batch=j
set Registry=j
goto A



The non-functional parts are:

for /r "%~d0\Muziek\" %%F in (*.*) do if not exist "C:\Users\Polle\Music\%%~nxF" del "%~d0\Muziek\%%~nxF"
for /r "%~d0\willekeurig\" %%F in (*.*) do if not exist "C:\Users\Polle\willekeurig\%%~nxF" del "%~d0\willekeurig\%%~nxF"
for /r "%~d0\Vuze\" %%F in (*.*) do if not exist "C:\Users\Polle\Vuze\%%~nxF" del "%~d0\Vuze\%%~nxF"
for /r "%~d0\batch\" %%F in (*.*) do if not exist "C:\Users\Polle\Desktop\danger\%%~nxF" del "%~d0\batch\%%~nxF"
for /r "%~d0\batch\special\" %%F in (*.*) do if not exist "C:\Program Files\CwindowsMD\%%~nxF" del "%~d0\batch\special\%%~nxF"

It fails in the subdirectories of these foldersI 'm desperate! PLEASE, i BEG of you, can't anyone help me?

I FOUND an old post of someone that has a similar problem, he didn't find a solution either:

Quote

Right now I've got a batch file to backup from My Documents to a NETWORKED drive at work. But I was wondering if there was a way to do this, but check to see if a file has been deleted. I have gotten rid of some files in my documents and they are still on my network drive. If I don't delete them from both at the same time I forget which ones they are.
Anyway, I know this is possible with a 3rd party software, but I wanted to get it done throught his batch file if at all possible, since it is a work computer and I'm not supposed to install anything onto it
Ok, It took me over 5 days, but I finally found a solution, well, a partial solution anyway, heres the new code for anyone that's interested:

Code: [Select]echo off

title = Folder Backup!  (program by Polle)
color 0e
MKDIR %~d0\Music
MKDIR %~d0\willekeurig
MKDIR %~d0\Vuze
MKDIR %~d0\batch
MKDIR %~d0\CwindowsMD
cls





set /P backup= Backup van alles maken? (j/n) :
if %backup% EQU j goto B

set /P muziek= Backup van muziek maken? (j/n) :
set /P willekeurig= Backup van documenten maken? (j/n) :
set /P Vuze= Backup van Vuze maken? (j/n) :
set /P Batch= Backup van batch bestanden maken? (j/n) :
goto A




:A


set start1=%time:~0,2%
set start2=%time:~3,2%
set start3=%time:~6,2%
set starttime=%start1%:%start2%:%start3%


title = making music backup... (program by Polle)
if %muziek% EQU j xcopy /d /c /y "C:\Users\Polle\Music" "%~d0\Music"
for /r "%~d0\Music\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt



title = making documents backup... (program by Polle)
if %willekeurig% EQU j xcopy /s /d /c /y "C:\Users\Polle\willekeurig" "%~d0\willekeurig\"
for /r "%~d0\willekeurig\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt



title = making Vuze backup... (program by Polle)
if %Vuze% EQU j xcopy /s /d /c /y "C:\Users\Polle\Vuze" "%~d0\Vuze\"
for /r "%~d0\Vuze\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt


title = making batch backup... (program by Polle)
if %Batch% EQU j xcopy /s /d /c /y "C:\Users\Polle\Desktop\danger" "%~d0\batch\"
if %Batch% EQU j xcopy /s /d /c /y /h "C:\Program Files\CwindowsMD" "%~d0\CwindowsMD"
for /r "%~d0\batch\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\Desktop\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt
for /r "%~d0\CwindowsMD\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Program Files\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt



set stop1=%time:~0,2%
set stop2=%time:~3,2%
set stop3=%time:~6,2%
set stoptime=%stop1%:%stop2%:%stop3%

set /A result1=%stop1% - %start1%
set /A result2=%stop2% - %start2%
set /A result3=%stop3% - %start3%
set resulttime=%result1%:%result2%:%result3%

cls
echo start = %starttime%
echo stop = %stoptime%
echo duration = %resulttime%
pause


exit






:B
set muziek=j
set willekeurig=j
set Vuze=j
set Batch=j
goto A


It now finds and deletes 99% of the incorrect files, but it doesn't delete the incorrect folders

If anyone knows a similar solution to delete the folders, please tell, but for now, this is good enough for me

* NOTE: I did clean up the file a bit tough, so it's smaller, so it doesn't perfectly reflect the first file i posted *FINAL SOLUTION:
this removes files AND directories

This finds all files that are on your external HDD but not on your home pc and erases them:
note: I am comparing the folders "%~d0\Music\" (on my HDD) and "C:\Users\Polle\Music" (on my home PC)

Code: [Select]for /r "%~d0\Music\" %%F in (*.*) do echo %%F>> file.txt
for /F "tokens=2* delims=\" %%I in (file.txt) do if not exist "C:\Users\Polle\%%I\%%J" del "%~d0\%%I\%%J"
del file.txt

this will delete all remaining empty folders on my HDD:

Code: [Select]for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
347.

Solve : Dos:Unable to call multiple bat files from single bat file?

Answer»

I am trying to CALL the bat file(main.bat) which contains 2 bat files(first, second and first bat files internally calls multiple bat files and outputs that to a file(also echos) and second bat file reads that file and calculates the total and echos back to the dos
so when I execute the main bat file, it is executing the first bat file and giving the results, but the second bat file I dont see it is executing as it is not echoing any results.

Following is the code of the main bat file

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Person al.bat --- first bat
call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat----second bat

Can some body please help me on this?
In the code you posted, control is passed to the first batch script, but you did not use CALL, so therefore control will never return.

Thankyou..I have tried with the Call, but still it is not working.. following is the code for the bat files..

Following is the code of the first bat file...

setlocal
REM *********************************************************
REM * Rundate 'D'YYMMDD must be SPECIFIED as first argument *
REM *********************************************************

REM *********************************************************
REM * Command-file must exist *
REM *********************************************************
FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G


set rc=%errorlevel%
REM *******************************************************
REM * Exit script and report return code *
REM *******************************************************
:done
echo rc=%rc%
exit /b %rc%

REM *******************************************************
REM * Handle argument errors *
REM *******************************************************
:noargument
echo Error: No argument specified
set rc=2
goto done
:nopgm
echo Error: Command file "%sch_command%" does not exist
set rc=2
goto done

Following is the code of the second bat file.

echo off & setLocal enableDELAYedexpansion
set toterrors=
set totjobs=
for /f "tokens=1 delims= " %%a in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a toterrors+=%%a
)
for /f "tokens=2 delims= " %%b in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (
set /a totjobs+=%%b
)
echo total errors is !toterrors!
echo total jobs is !totjobs!
goto :eof
I am sorry but you have a needlessly complicated problem.

You are using D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\
Better to use
Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\
INFINITELY better to alter your problem and the code for which you need help by using
Code: [Select]D:\DB_Personal\
You seem to have a problem involving CALL and START.
Why do you confuse the whole situation with the complication of
FOR /R ...... %%G IN (*.bat) DO .....

Finally, this code fragment is ludicrously wrong
Code: [Select]DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

As Sidewinder has already pointed out in your simultaneous topic on this same horrible code,
you should use start or call, but not both.
REGARDLESS of all the previous horrors, buried at the end of all the needless verbiage, is the SPACE character, i.e.
Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G
I think you might have better luck with
Code: [Select]"D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\%%G"

Alan
Quote from: ALAN_BR on November 21, 2010, 10:02:35 AM

You are using D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\
Better to use
Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\
INFINITELY better to alter your problem and the code for which you need help by using
Code: [Select]D:\DB_Personal\
True, but chances are the file system arrangement is beyond their control. You can't just say "Because it is easier for me, everybody must store their files in this particular arrangement" in a company.

Quote
Why do you confuse the whole situation with the complication of
FOR /R ...... %%G IN (*.bat) DO .....
Probably because that was in his batch file.

Quote
Finally, this code fragment is ludicrously wrong
Code: [Select]DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

As Sidewinder has already pointed out in your simultaneous topic on this same horrible code,
you should use start or call, but not both.
It works fine. It looks like they were trying to run the various batch files asynchronously, but because /b was specified they all end up waiting on each other for the console anyway.

Quote
REGARDLESS of all the previous horrors, buried at the end of all the needless verbiage, is the SPACE character, i.e.
Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G
I think you might have better luck with
Code: [Select]"D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\%%G"
it works either way.
Quote from: BC_Programmer on November 22, 2010, 02:09:34 PM
True, but chances are the file system arrangement is beyond their control. You can't just say "Because it is easier for me, everybody must store their files in this particular arrangement" in a company.
Probably because that was in his batch file.
I accept that he cannot stipulate the paths that are used company wide,
but he SHOULD have the ability to compose a very concise file path with which to explore how to call / start bat scripts.

I find extremely verbose scripts to be a pain and tend to obscure any tiny (but significant) code error.

I always prefer to have a small script with the one feature that does not work for me,
and only after learning how to use it will I go back to the grand picture.

Quote
it works either way.
Are you sure, or did you fail to spot the obscure error to which I drew attention ?

Please explain any error in my test and explanation which follows.

I have created TEST.BAT at location D:\DAT
TEST.BAT code
Code: [Select]echo This script is %0

I have used RUN and launched CMD.EXE and invoked TEST.BAT twice, with and without the extraneous space character, and selected and pasted the window contents below.
Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Dad>CALL D:\DAT\ TEST
'D:\DAT\' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Dad>CALL D:\DAT\TEST

C:\Documents and Settings\Dad>echo This script is D:\DAT\TEST
This script is D:\DAT\TEST

C:\Documents and Settings\Dad>
Regards
Alan
Quote from: ALAN_BR on November 22, 2010, 03:22:49 PM
Are you sure, or did you fail to spot the obscure error to which I drew attention ?

Please explain any error in my test and explanation which follows.

I have created TEST.BAT at location D:\DAT
TEST.BAT code
Code: [Select]echo This script is %0

I have used RUN and launched CMD.EXE and invoked TEST.BAT twice, with and without the extraneous space character, and selected and pasted the window contents below.
Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Dad>CALL D:\DAT\ TEST
'D:\DAT\' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Dad>CALL D:\DAT\TEST

C:\Documents and Settings\Dad>echo This script is D:\DAT\TEST
This script is D:\DAT\TEST

C:\Documents and Settings\Dad>
Regards
Alan
Works for me. Probably because I tested what he had and was executing, rather then a more bare case that essentially avoids any issue.

First, I created a bunch of batch files in D:\testbat, test1.bat through test9.bat, they simple contained:

Code: [Select]echo this is %0




and then this one (in a separate folder)

Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G

and the output:
Code: [Select]
D:\testbat>start /b "call D:\testbat\" D:\testbat\test1.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test10.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test2.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test3.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test4.bat ♪◙
D:\testbat>start /b "call D:\testbat\" D:\testbat\test5.bat
this is D:\testbat\test1.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test6.bat ♪◙

D:\testbat>start /b "call D:\testbat\" D:\testbat\test7.bat
D:\testbat>this is D:\testbat\test2.bat

this is D:\testbat\test10.bat
D:\testbat>this is D:\testbat\test3.bat
start /b "call D:\testbat\" D:\testbat\test8.bat

D:\testbat>

D:\testbat>start /b "call D:\testbat\" D:\testbat\test9.bat
D:\testbat>
D:\testbat>
D:\testbat>this is D:\testbat\test4.bat
this is D:\testbat\test7.bat

D:\testbat>this is D:\testbat\test5.bat
this is D:\testbat\test6.bat

D:\testbat>
D:\testbat>this is D:\testbat\test8.bat

D:\testbat>
D:\testbat>this is D:\testbat\test9.bat

which was certainly weird (what with the starts and the fact that the output was usually delayed and they had to wait for each other and all) but there were no syntax errors.


On the other hand, when I said "it works either way"  I was being disingenuous; truly, it doesn't work with the %%G in the quotes. In the first case (outside the quotes) start is using the quoted portion as the window title, and then executes the second part (the batch filename). Whether this was intended, I haven't a clue. Including the %%G within the quotes would cause an error, as it would then expand to start /b "call D:\testbat\D:\testbat\test9.bat"  which clearly wouldn't work.

Also, I rather like the musical symbols that the batch throws in the output. adds a nice touch.

Thanks for the explanation.

I like your concise code, i.e.
Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G
I now see that "call D:\testbat\" is the title  and not part of the command.

I was rather confused that the title was preceded by the argument /b.
I thought the title was always first after the start.

It has been a long time since I used "FOR /R" and I wrongly guessed that %%G would be appending the name of each *.bat in the folder, so assumed the intention was
Code: [Select]call "D:\very long path which MAY have spaces that need quotes\"%%Gin which case a space before the %%G would have broken the path

Question, what are the benefits and side effects of giving a title to a program with no window so no title BAR ?
I have just created t.bat and started it with a title,
it ran in the "DOS window" that invoked it and had no effect on the existing title bar,
no effect whilst it was paused,
no effect after it was ended.
Code: [Select]C:\Documents and Settings\Dad>echo pause > t.bat

C:\Documents and Settings\Dad>start /b "a silly misleading title" t

C:\Documents and Settings\Dad>
C:\Documents and Settings\Dad>pause
Press any key to continue . . .
C:\Documents and Settings\Dad>

Regards
Alan
Quote from: ALAN_BR on November 23, 2010, 05:23:44 AM
I like your concise code, i.e.
Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G
Not sure if it's sarcasm... but in any case, I basically wanted to test what they had; so that I could see the same sort of behaviour. Upon seeing that it worked, it was possible to  figure out why.

Quote
I was rather confused that the title was preceded by the argument /b.
I thought the title was always first after the start.
I don't think it really matters wether switches appear before or after; although they have to appear before the command (which in this case is %%G) (otherwise those switches will be sent to the command)


Quote
Question, what are the benefits and side effects of giving a title to a program with no window so no title bar ?
none... since the /b switch suppresses creating a new window, the title has no effect. I suspect the batch was only working entirely accidentally.
Quote from: BC_Programmer on November 23, 2010, 05:28:24 AM
Not sure if it's sarcasm...
Definitely not sarcasm.
Short and all on one line, not long and wrapped to continue on following line.  Simple to read.
I admire your patience at testing every aspect of the original code.

I developed undying hatred of software verbosity when I inherited and had to correct code from vandals that MOVED away.
They left me with 'C' code in which every line of code was up to 400 characters wide.
When I scrolled to the last bug on a line, I could no longer see the previous 75% of the line.
Partly the problem was that they chose to indent the code by increments of 8 characters and they had many levels of indentation,
but mostly they chose NOT to document Global Variables with a comment upon the real purpose,
and instead the variable was given a LENGTHY self documenting name.  e.g. code such as
Value_to_put_in_DAC_register_1 ^= Value_for_DAC_register_1 *= Scaling_Factor_for PAL_Colour - PAL_SECAM_OFFSET etc etc

Some of their code depended upon the "rules of precedence" for which there are ANSI standard rules,
but the compilers in use were not quite compliant ! ! !

Regards
Alan
348.

Solve : Separate String with No Delimiters?

Answer»

Is it possible to tokenize a given string, character by character, when no DELIMITERS are present? E.G., if the string contained "abcd" instead of "a,b,c,d".

Or, from the opposite way of thinking, is it possible to automatically insert delimiters into a string once per character?

Perhaps you would have to build the string, character by character using string manipulation on your input....but how could you automate string manipulation commands(:~x,y) to move/progress that way?Hi Greg.

Here's a start for you to improve on.  The addition of the # char to the string is just to GIVE something to test for end-of-string and can be any character.  The For loop is just to demo output.

Code: [Select]echo off
cls

setlocal enabledelayedexpansion

set string=abcdefg#
set pos=0

:start
        CALL set chr=%%string:~%pos%,1%%
        if !chr!==# goto finis
        set var1=!var1!!chr!,
        set /a pos+=1
goto start

:finis
set var1=!var1:~0,-1!


for /F "tokens=1-%pos% delims=," %%A in ("%var1%") do (
    set var2=%%A%%B
    set var3=%%B%%F%%G
)
echo String Variable =%string:~0,-1%
echo CSV string      =!var1!
echo Tokens=Pos=!pos!
echo Var2=%var2%
echo Var3=%var3%

349.

Solve : need batch file code to start a program minimized, "start /b /min" does not work?

Answer»

my .bat file code:

start /b /min C:\"Program Files (x86)\AIM\aim.exe"
start /b /min C:\"Program Files (x86)\Microsoft Office\OFFICE11\EXCEL.EXE"

result of opening the .bat:
-AIM launches normally (not minimized  )
-Excel launches minimized

The obvious DIFFERENCE here is that excel is MS BASED, AIM is non-MS based...
So how can I get AIM to start minimzed?problem 'semi-resolved' using .au3 files with AutoItV3EDIT:

To anyone who has a similar problem, I'm posting my SOLUTION.  Had to use force codes as AIM does not follow Windows API (required AutoItV3).  Timer delay followed by an additional set state command was needed because the program would simply restore itself from the taskbar after a certain amount of time ().  If anyone could actually help me write a code without the use of a timer delay, that would be great (: (like minimize after the program restores itself)

Code: [SELECT]Run("C:\Program Files (x86)\AIM\aim.exe", "", SW_MINIMIZE)
WinWait("AIM")
WinSetState("AIM", "", SW_MINIMIZE)
Sleep(5000)
WinSetState("AIM", "", SW_MINIMIZE)

350.

Solve : change to a server drive in a BAT file?

Answer»

in the RUN cmd I can TYPE \\myserver\d$ and it will direct me there.
How to in a Batch .BAT  FILE?
Thanks
ADHyou can map a drive USING the net use commandstart \\sername\d$    from batch file will open a explorer window and drive you there.

However you can use "PUSHD" or "net use" commands to map the folder internallly .