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.

2751.

Solve : "set" not working as expected within a for loop?

Answer»

Okay, this is driving me batty. Can someone tell me what I'm doing wrong here, because I don't see it.

I'm utterly confused. "SET" is acting very strangely within a for loop. Here's my code. PortList is a file with a few pre-formatted lines of text (I'm assuming it has 4 lines for this example).

Code: [Select]set count=1
for /f "tokens=1" %%i in (PortList) do (
echo %count%^) %%i
set /A count=%count%+1
)
echo.
set /P input=Please select [1-%count%]:

The output I EXPECT is

Code: [Select]1) [first entry in PortList]
2) [2nd entry]
3) [3rd entry]
4) [4th entry]

Please select [1-5]:

(yes, I know I need to decrement count before that last line, but I'll deal with that later).

What I get instead is

Code: [Select]1) [first entry in PortList]
1) [2nd entry]
1) [3rd entry]
1) [4th entry]

Please select [1-2]:

Notice that it DOES increment count at the end, so I get "1-2" instead of "1-1".

What am I missing? No matter what I've tried, the set /A line is ignored within the for loop until AFTER the final iteration of the loop. Even if I simplify it down to the following:

Code: [Select]set count=1
for %%i in (1 2 3 4) do (
set /A count=%count%+1
echo %count%
)
echo %count%

The output is:
1
1
1
1
2

Heck, I've even tried this:
Code: [Select]count=1
for %%i in (1 2 3 4) do (
set count=hello
echo %count%
)
echo %count%

And all I get is:
1
1
1
1
hello

Maddening I tell you!

Oh, this is a batch program on WIN 2K3.This is a well know noob trap. You need to find out about delayed expansion. Google is your friend.

Wow. 5 years of batch programming and I've never run across this.

That did it, thanks.I re-read my answer and it kind of looks like I was calling you a noob, which wasn't very polite, and it wasn't my INTENTION to be rude, so sorry if it sounded that way.

A well know trap for progressing batch programmers.
No worries. Programming/scripting is an ancillary part of my job that I do only occasionally, so in many ways I am still a n00b. Especially since I bounce around between Windows batch, linux shell, python, perl, etc. I can design an algorithm in my sleep, but when it comes to specific language syntax and compiling/runtime quirks, I can't keep it all straight.Quote from: gdiddy on January 29, 2009, 12:09:05 PM

Especially since I bounce around between Windows batch, linux shell, python, perl, etc.

I Googled "delayed expansion" just to check that it brought up relevant stuff and I found a blog by someone called Batcheero, who explains it quite clearly, and he ALSO shows how to make a mixed batch/perl script

Quote
Perl In Batch Clothing

As someone who writes a lot of scripts, Perl is my language of choice. But it does not mean I can live without Windows batch. Sometimes though, it is necessary to combine the two by disguising a Perl script as a batch file.

When might this come in handy? Well, to be honest I can't really think of any right now, but this is certainly cool. This trick is not a batch file trick per se. It's really a Perl trick, and you'll see soon enough why that is. But I'd like to put it here just the same because hey, it's got some batch scripting in it.

To write your Perl script as a batch file, all you have to do is add a few lines at the top of your Perl script, rename the script extension to .bat or .cmd, and you're done.

@echo off

perl -x %~dpf0 %*

EXIT /b %errorlevel%

#!perl

use strict;

print "Hey $ARGV[0] I'm in Perl!\n";

exit 0;

This file, being a batch file, is executed by the command processor as any batch file. It reads each line and executes that line.

The first line is straightforward. The second line is really the trick. Doing perl -x tells Perl to read the file you pass as argument, %~dpf0,
which is the complete path of the batch script, and ignore anything in the file until it finds the #!perl line.
Then it treats it like any other Perl script.

The last argument on that line is simply passing all the command line arguments you pass to your batch script to the Perl as well.

So try and invoke the script. Let's say you named the script foo.bat.

foo.bat Batcheero

You'll see the following printed output.

Hey Batcheero I'm in Perl!


quite a few tips

http://batcheero.blogspot.com/

Yeah, that's the one I ended up at when I searched.Quote from: Dias de verano on January 29, 2009, 11:46:31 AM
I re-read my answer and it kind of looks like I was calling you a noob, which wasn't very polite, and it wasn't my intention to be rude, so sorry if it sounded that way.

A well know trap for progressing batch programmers.


You feeling all right Dias?

FB
2752.

Solve : Hello! Very puzzling batch file execution, and need help!?

Answer»

Hi all,

Here is a little background to my issue. I am trying to FIGURE out a way to create one autorun CD for my company's software that will install the proper software depending on if the machine is 32 bit or 64 bit. So, I created an autorun exe using RJL AutoRun Wizard software that will run a batch file named OS type which contains the following code:

::Batch File looks at Processer_architecture to determine
::64 Bit or 32 Bit, then installs appropriate KW
@echo off
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (START AutoRunKegWizard32bit4.0/autorun.exe )
IF NOT "%PROCESSOR_ARCHITECTURE%" == "x86" (START AutoRunKegWizard64bit4.0/autorun.exe )
END

It simply ANALYZES the processor architecture to determine if it 32 or 64 bit, then IS SUPPOSED!! to route to the other autorun.exe file that is in the subfolder that takes care of the actual software installation which consists of my company's kegwizard software and the driver for our machine. The only problem is that when OS type.bat is manually run (by clicking on it), it routes to the proper folder, BUT, if it is run via the autorun, it does not route to the proper folder. Instead, it attempts to install the 32 bit version of software. This only seems to happen on a VISTA 64 bit machine, as all other 32 bit machines I tried it on, it WORKED in both ways, using the autorun and manually. I do not understand this!! Is this a 64 bit Vista issue, or am I doing something WRONG?

THANKS!!!!





I figured it out. There must be a problem with the RJL generated autorun.exe. I just changed it so that the autorun.inf called the batch file directly instead of calling the autorun.exe which then called the batch file. WEIRD!!!

2753.

Solve : Help With MS-DOS Please?

Answer»

I'm Having a problem With my MS-DOS Program\~Tmpa. I rebooted my COMPUTER and several popups come up on the screen and the only optoin that is given is to ignore or cancel. There is about Five To Six Popup windows the show up every 20 to 25 min. I fact they just poped up right now the hole window states from top left.

16 bit MS-DOS SUBSYSTEM
~tmpa.exe
The NTVDM CPU has encountered an illegal instruction.
CS:0def IP:0113 OP:ff ff ff d4 d0 CHOOSE 'Close' to terminate the APPLICATION.
_____ ______
\Close\ \Ignore\

The windows that popup with this window have a blue bar at the top and are label ~tmpa.exe they are showen with black backgrounds and suply no data at all. Again this happens every 20 to 25 mins and will continue to show up. If I leave the preveus windows there every 20 to 25 mins it will build up with more windows of the same.Your system is infected with malware...if you google ~tmpa.exe
there are LOTS of talk about it and how to remove the malware.
http://www.spywareremovalblog.com/remove-tmpaexe/

2754.

Solve : a batch program to create directory with the name yyyymmdd?

Answer»

I am using the following SCRIPT but it does not PRODUCE yyyymmdd only yyyyddmm
any ideas would be appreciated.
Jim
@ECHO OFF
TITLE DateDir
REM DateDir.CMD
REM CREATES a directory in format YYMMDD using today's date.
REM
REM -------------------------------------------------------------
Set CURRDATE=%TEMP%\CURRDATE.TMP

DATE /T > %CURRDATE%

Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j

Echo mkdir %YYYYMMDD%%HHMM%
mkdir %YYYYMMDD%%HHMM%

Quote

Echo mkdir %YYYYMMDD%%HHMM%
mkdir %YYYYMMDD%%HHMM%

That's your problem.

Change it to

Quote
Echo mkdir %YYYDDMM%%HHMM%
mkdir %YYYYDDMM%%HHMM%
2755.

Solve : file convertion.....?

Answer»

I am new to the DOS world, and I have a question. Is there an application that convers an .exe back to a .bat or something that you can see the codes? I am creating a batch FILE to auto run an application but it's not working correctly due to the fact that the application also call for some other executables. I want to see the codes so that I can include those executables in my batch. Can someone help? ThanksI HEARD that some bat to exe wrappers for batch FILES if you change the .exe to .bat and then use the EDITOR they are raw ascii ... havent confirmed this, but I overheard sort of speak some info on this on the web with one of the free batch to exe wrappers. Give it a try and see.

Some others out there have decompilers to get them back to their .bat form to be read although I would be careful taking this route as for its in territory that could be viral if you find a download for a decompiler.I am having problem calling a batch file inside another batch file. I have TESTED each of them individually and all of them works. Can someone check my codes please. Thanks.

Main batch
==========
@echo off
("C:\Program Files\SI_SCOPE\si_scope32" < si_scope32 /p1:fdf0h /p2:fdf8h /i1:07 /i2:07 /BOARD_TYPE:5 /NOALERT /B:128)
at 1:15PM /call "C:\Program Files\SI_SCOPE\close.bat"
at 1:16PM /call "C:\Program Files\SI_SCOPE\copy.bat"
at 1:17PM /call "C:\Program Files\SI_SCOPE\Hard Fault Captures\RenameFileToDate.bat"
at 1:20PM /call "C:\WINDOWS\reboot.bat"
==========


Close
==========
@echo off
taskkill /im "si_scope32.exe" /f
==========


Copy
==========
@echo off
copy "C:\Program Files\SI_SCOPE\SI_SCOPE.DAT" "C:\Program Files\SI_SCOPE\Hard Fault Captures"
==========


RenameFileToDate
==========
@echo off
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "SI_SCOPE.DAT" %%e-%%f-%%g.dat
==========

Reboot
==========
@echo off
shutdown -r
==========

2756.

Solve : command for including dimensions when printing directory?

Answer»

I would like to be able to print a list of a file containing pictures to a text file and have that list include the DIMENSIONS of the file as can be displayed in windows explorer. My computer is Windows XP.

Normally my command line is dir *.* > [filename].txt which will show DATE, name, file size. Your help directory shows a list of attributes which can be added but does not include the dimensions as far as I can tell.

Can you give me the command to print a directory and SUBDIRECTORIES' list to a file which will include the dimensions and date picture taken as well.

Thanks.
Carolyn I am sending this because I didn't check the notify me of replies before I hit the post button. I APOLOGIZE but this is my FIRST post. Thank you again. Carolyn

2757.

Solve : find command?

Answer»

I WANT to find a string in file and PROMPT message if the count is >0.

find "Hello" "C:\test.dat"

but this command outputs file name and number of occurance. how to CAPTURE number of occurance in script???check the errorlevel, i think this is the right way round:

Code: [Select]find "Hello" "C:\test.dat">nul
if errorlevel 0 echo message here
FBQuote from: fireballs on January 29, 2009, 08:28:12 AM

check the errorlevel, i think this is the right way round:

Code: [Select]find "Hello" "C:\test.dat">nul
if errorlevel 0 echo message here
FB

but...

Quote
how to capture number of occurance in script???

But...

Quote from: rao on January 29, 2009, 08:13:59 AM
I want to find a string in file and prompt message if the count is >0.

I read the original POST as MEANING the above, and capturing the occurances as an after thought to stop the output appearing on screen. I guess the OP can clear this up.

FBYup you're right, the OP asked 2 different questions.

By the way in Windows 200 and later these work

Code: [Select]find "Hello" "C:\test.dat">nul && echo hello is present in the file
Code: [Select]find "Hello" "C:\test.dat">nul || echo hello is not present in the file
to get the count is slightly more complex and the OP should please say if that is what he or she wants.

2758.

Solve : Need a bit of help?

Answer»

Hi all,

I have a question. I want information from a text file written to another file.

Below is an example of a line in the text file

jan-21,16:25:35.265 CSTASRV Agent_Selected callid 363548 devicenr1 0302304493 devicenr2 3353 agentname1 agentname2 clinden acdname KSC 1e lijn MMCType Voice Skill

This is the info i want out of it and written into a new txt file
jan-21,16:25:35.265 devicenr1 0302304493 agentname2 clinden acdname KSC 1e lijn

I am a bit stuck on how to do this..can anyone HELP me out?
thanks a lot,
TheoCode: [Select]for /F "tokens=19 delims= " %%a in (file.txt) do (
echo.%%a %%f %%G %%k %%l %%m %%n %%o %%P
)
try thatyou'd need to have ('type file.txt') or usebackq (`file.txt`).

FBThis what i have so far:

@echo off
color 31
cd c:\mitroslog
SET /P filename=Enter the name of the file...
SET /P search1=Enter first search command...
SET /P search2=Enter second search command...
findstr %search1% %filename% > eerstefiltering.txt
findstr %search2% eerstefiltering.txt > gevraagdeinformatie.txt
del C:\mitroslog\eerstefiltering.txt
START /MAX NOTEPAD.EXE "C:\mitroslog\gevraagdeinformatie.txt"
exit

I am new to this so not sure were to put the EXTRA scripting to GET the desired information.
jan-21,16:25:35.265 CSTASRV Agent_Selected callid 363548 devicenr1 0302304493 devicenr2 3353 agentname1 agentname2 clinden acdname KSC 1e lijn MMCType Voice Skill ---> this is put into gevraagdeinformatie.txt

jan-21,16:25:35.265 devicenr1 0302304493 agentname2 clinden acdname KSC 1e lijn ---> This is what i want to filter out of gevraagdeinformatie.txt..and if possible put in another txt file.

Thanks a lot for the help


Code: [Select]for /F "tokens=1-19 delims= " %%a in ('type gevraagdeinformatie.txt') do (
echo.%%a %%f %%g %%k %%l %%m %%n %%o %%p >> temp.txt
)

2759.

Solve : Running a batch file from a different directory?

Answer»

Hello,

I have a BATCH file in the location C:\Program Files\IBM\WebSphere\AppServer\bin\configurewebserver_1.bat

and I WANT to run it from the location C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01


Any quick solution ? I tried googling this but GOT no luck

Thanks in advanceQuote from: kashifusmani on September 28, 2009, 08:01:21 AM

Hello,

I have a batch file in the location C:\Program Files\IBM\WebSphere\AppServer\bin\configurewebserver_1.bat

and I want to run it from the location C:\Program Files\IBM\WebSphere\AppServer\profiles\AppSrv01


Any quick solution ? I tried googling this but got no luck

Thanks in advance

Use the complete path to configurewebserver_1.bat
regardless which folder you are in:
C:\Program Files\IBM\WebSphere\AppServer\bin\configurewebserver_1.bat
or
copy configurewebserver_1.bat
to the new folder and then execute.
2760.

Solve : Missing files?

Answer»

When the COMPUTER says that The following file is missing or CORRUPTED, How do I fix it?It all rather DEPENDS on which file it is ... simplistic answer is to put the in the correct PLACE

2761.

Solve : How to get the command result??

Answer»

Salaam,

How can I GET the results of executiong a dos command in a TEXT FILE?
For EXAMPLE I want to make a text file of dir command or so on...

Regards, Command >>"C:\path\to\text\file.txt"

Like that?

2762.

Solve : Make a batch file click the mouse?

Answer»

OK well how do i make a BATCH file click the mouse rapidly for the use of css because my Friend bought a mouse with like turbo and all it does it when you PRESS the left mouse button and a button on the side it click rapidly. but he wont stop rubbing it in my face because you can shoot faster in the game. so if anyone knows how i can do this in a batch file by pressing ctrl + to turn on on ctrl - to turn off please help or i will keep dieing when hes over and if you cant do it with a batch file what can you do it with and how?

p.s. he bought it becouse im BETTER than him so he wanted to be better than me and i dont know where he GOT the mouse. wont tellIn short you can't.

FBok well time to START search for a mouse like thatYou can do this kind of stuff with AutoIt...That's a easy language. But you have to install a special interpreter for it to work.

2763.

Solve : ESC give a certain errorlevel ??

Answer»

My main question is. When you use escape to exit a program or SOMETHING. Would that give off a certain ERRORLEVEL? Or would it give of an errorlevel similar to other ones. My second question is. Is it possible to clear variables, so that they can be set again.Quote

My second question is. Is it possible to clear variables, so that they can be set again.

You don't need to, simply give your variable a new value. You can also use set var=, just as you would at the console. You can also reset variables by using setlocal and endlocal in tandem, by restricting the scope of each variable.

Quote
When you use escape to exit a program or something. Would that give off a certain errorlevel?

It should. I believe they are called scan codes. If you need it, I may have a little DOS script that will produce an errorlevel value for every key. That would be great if I had that script. Then a user wouldn't have to press enter to choose an option in a batch file menu .The script is older than dirt. It might even still work.

Code: [Select]A 100
XOR AH, AH
INT 16
CMP AH, 0
JE 100
MOV AL, AH
MOV AH,4C
INT 21

R CX
10
N SCANCODE.COM
W
Q


The last line is purposely left blank. Save the script with a scr extension and from the command line run debug < scriptname.scr to assemble the code.

The ASSEMBLED program is scancode.com. The batch file returns the scancode of the key pressed at the prompt.

Code: [Select]@echo off
echo Enter Key:
scancode
echo %errorlevel%

Good luck. . It didn't work..Quote
It didn't work..

That response is right up there with there is weather outside. How did it not work? When you ran the batch file did you get a prompt? What key did you RESPOND with? What happened next?

Did you copy/paste the script? Did you type it out yourself?

Maybe it doesn't work on Vista. Works OK with XP. Maybe this should have been left in the grave of DOS 3.1

Well, I copy and pasted it into notepad, (I added the blankspace). Then I did from the command line that
debug < scriptname.scr, and it said something like it can't find the file.Quote from: BatchFileCommand on January 27, 2009, 06:37:16 PM
Well, I copy and pasted it into notepad, (I added the blankspace). Then I did from the command line that
debug < scriptname.scr, and it said something like it can't find the file.

Did you save it with the name scriptname.scr in the right folder?

Quote
something like

Love the precision.

in Vista there is no DEBUG That explains that then.I use Vista home premium and i've got debug, and i've just tested the code from Sidewinder and it works fine.

FBweird- it's not on my Vista Ultimate I have on my laptop- is it a separate checkbox during the installation? Or maybe you copied it after install FB?OEM installation, and i don't believe i've downloaded it since installation. THOUGH i've got telnet and that's 'hidden' in vista too. It might be something like that with debug.

FBif they didn't include debug that would have been dumb. "hey, let's remove that silly debug tool! And while we're at it let's give everybody that useless edlin tool from DOS 5!"

I did a dir /s and debug.exe wasn't found on my vista install- so I took the cheap way out and copied it from my XP x64 partition. Not that I ever use debug, though. But on the other hand, I never use my XP installs since they have a few issues I am too lazy to address either...I have Vista Ultimate too. Debuggers not in the extra features either.
2764.

Solve : Help Please (not recognized internal...)?

Answer»

Hey, i need some help.

Well i just started "programmming" and ive downloaded c++ VISUAL express edition, and i found this problam, what was happen was that i could never debug/run the code.. which is how i stubbed APON this, i think the cmd isnt working right.. so i went into cmd.exe and tryed a simple ping. and i get this error. "ping" is not recognized as an internal or external command, operable program or batch file.

i'm useing windows XP

keep in MIND that i very new to cmd but is there any way to fix this.. any help would be great.

-Adamstart a command window, at the prompt type

echo %path%

and copy and paste the results into your next post.

Quote from: Dias de VERANO on January 28, 2009, 12:34:52 PM

start a command window, at the prompt type

echo %path%

and copy and paste the results into your next post.




c:\WINDOWS\system32ok i figured out what the problem was.. the default "path" isnt in the system32, how can i set the path internally? so i dont have to set it each time i open cmd.1 Right click My Computer and click properties.

2 In the System Properties window, click on the Advanced tab.

3 In the Advanced section, click the Environment Variables button.

4 In the Environment Variables window, highlight the path variable in the Systems Variable section and click edit.

This is the default Windows XP path variable:

C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem

If you need to add any more folders, they can be added, SEPARATED by semicolons as above.

5 Click OK twice.

6 Reboot
Question I have is what does PING have to do with C++?

Are you trying to perform a system(" "); call in C++ that PINGs?

Hoping this is a friendly console app you are attempting to create and not malicious!

Quote from: DaveLembke on January 28, 2009, 01:13:22 PM
Question I have is what does PING have to do with C++?

Are you trying to perform a system(" "); call in C++ that PINGs?



Nope i was playing around with C ++ and thats how i figured out something was wrong with my cmd.. so i tryed a simple PING to see if i was right...

Everythings working now tho, thanks for the help Ok then... btw you can use SYSTEM(" "); to execute other executables and dos commands from within your C++ program by placing a path to the executable or dos command in between the " " .... the C++ Express should have the .h handlers automatic, older VC++ 6 etc you had to manually #include the handler at the top of the program.

Just in case you wanted to know that ... or the more versatile WinExec or ShellExecute, ShellExecuteEx, or CreateProcess routines that can be imported via the windows headers.

2765.

Solve : Windows Updates - System Restart - Can dos tell??

Answer»

I have some systems that patch over the weekend and restart at around 3 am Monday morning. Some of the systems are considered servers and have processes that run on that are required to be up and running prior to other systems COMING online, if they come up in the wrong order then applications on other machine with fail to work correctly until the app is terminated and the services are restarted.

Is there a way in dos to DETERMINE if a computer was rebooted/restarted due to a windows update? I was thinking that I could use this as a way to then ping the needed systems and then start the application in question.

Can't stager the restart period as it is a pushed domain policy. Thanks for your help ...

No code yet as for something LIKE this I wouldn't know where to start or what to look at. I would shut off automatic UPDATES and make this a manual process where you have control over when and which systems are up and down. I'd set the systems to download and prompt when they have new updates. Then manually do the task.

Only easy way to physically make a automated process in which systems will come up powered in a specific order would be to use a remote power controller and do some programming to pass instructions to the power controller.... a more advanced method would be to turn certain services off and back on in the specific order that they need to be back online sich as using the NET STOP and NET START commands for the service to start or stop such as SQL Database and Agent, so windows is up and running, but there is no conflict because the potentially conflicting service is stopped until ready to start. ( I had to go this route with some POS ( Point of Sale ) systems that have to come up in a specific order to handle the front end communications. The first system up would take the lanes, but only the MFS1 would handle membership, so the MFS1 had to come up first then there was time delay batches added at the startup on the MFS2 and LFS server/system to start the winpos service after 1 minute for the MFS2 when both MFS1 and MFS2 are BOOTED up at same time and like hardware start up speeds. The LFS then would come up to start the service last in the cashier office 3 minutes later.

I currently use these power controllers which are secure and allow for remote power management of devices, systems, servers, and anything you want to turn power off and on remotely up to a 15 amp maximum draw. ( I havent performed custom commands linked to batches or any macros with these, but noticed that you can cache the last command and resend the last command to these through IE, so if you can read in the cached event and store it, you can then add a pointer to that cached command and make this fully automated. )

http://www.digital-loggers.com/EPCR2.html

These power controllers are very simple to set up via a web interface built into them or you can also interface to them via serial connection and terminal session or via a modem if a remote location...you have to add modem connected through serial null cable to go modem terminal connection.

I bought 20 of these and got a price better than advertised due to quantity discount. I also had one that got indirectly hit by lightning over the LAN and they took it in and gave me a replacement so their support team is good.

Oh...and you will have to have your servers set to power back up upon power loss in BIOS for these power controllers to turn the system / servers back on.

2766.

Solve : Is it possible to convert the binary file to ASCII file??

Answer»

Hi Friend,

Thanks in advance.

Actually I need to convert a Binary file to Text file (ASCII file). Is it possible to convert it using DOS. If so please help to attain the same.

Thanks,
Vinoth R
http://www.google.co.uk/search?source=ig&hl=en&rlz=&=&q=convert+binary+to+ascii&btnG=Google+Search&meta=lr%3D

FBI need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it...,

Thanks,
Vinoth RajagopalQuote from: vinoth124 on January 28, 2009, 05:10:26 AM

I need a CODE to convert the file from Binary to ASCII formated file.... I dont want any tools to do it...,

Thanks,
Vinoth Rajagopal

that doesn't MAKE any sense. Binary isn't a file format- it's a method of creating a file format. Word documents are binary. so are EXE images. So are a number of other formats... what kind of "Binary file" are you trying to convert to ASCII and what possible information could you glean from the ASCII result?


If your looking to turn it into ASCII via HEX, a simple application to do so would load the file and write out the HEX equivalent of each byte.

if your looking for CODE you should probably SPECIFY what kind of CODE you want. There is more then one type of CODE to do it in, and capitalizing CODE provides no benefit grammatically as I have just discovered.

EDIT: ALSO, we aren't here to do what might be homework for you; especially when the description is exceptionally vague.well its pretty hard to do it in batch. you would need to learn binary and how to convert from binary to 32bit Integer and then convert that to its ASCII equivalent.

VB would be needed for this kinda thing, since there are no user defined data types in batch.Quote from: macdad- on January 28, 2009, 05:45:21 AM
VB would be needed for this kinda thing, since there are no user defined data types in batch.

you wouldn't need a UDT.

Code: [Select]Private Function GetHiWord(dw As Long) As Integer
If dw& And &H80000000 Then
GetHiWord% = (dw& \ 65535) - 1
Else
GetHiWord% = dw& \ 65535
End If
End Function

Private Function GetLoWord(dw As Long) As Integer
If dw& And &H8000& Then
GetLoWord% = &H8000 Or (dw& And &H7FFF&)
Else
GetLoWord% = dw& And &HFFFF&
End If
End Function

Public Sub Binfile2Hexfile(ByVal InFile As String, ByVal Outfile As String)
'Input: Any file.
'Output: will create a file with each byte of Infile represented as a hexadecimal number.
'Each byte is separated by a colon.
'each line will contain 10 bytes worth of hex data.
Dim fnIn As Integer, fnout As Integer
'open both files.
Dim longval As Long, longStr As String
Dim tmpInt(1 To 2) As Integer, HexStr As String
Dim AddColonCounter As Integer, BytesOnline As Integer
fnIn = FreeFile
Open InFile For Binary As fnIn
fnout = FreeFile
Open Outfile For Output As fnout

Do Until EOF(fnIn)
Get #fnIn, , longval
longStr = ""
'convert to a Hexadecimal string. Add necessary zeros to make it the proper size-
' in the case of a VB6 long variable, it's 8 bytes binary, but each byte is 2 bytes hex, so 16 characters.
HexStr = Hex(longval)
'Debug.Assert longval = 0
If longval > 0 Then
longStr = String$(8 - Len(HexStr), "0") + Trim$(HexStr)
Else
longStr = String$(8, "0")
End If
For AddColonCounter = 1 To 2
Mid$(longStr, (AddColonCounter * 2) + (AddColonCounter), 1) = ":"
Next AddColonCounter
Print #fnout, longStr;
BytesOnline = BytesOnline + 1
If BytesOnline = 10 Then
Print #fnout, vbCrLf
BytesOnline = 0
End If
Loop



Close #fnout
Close #fnIn




End Sub

*censored*, sometimes I forget all the experience I have with string manip routines. Haven't used the statement form of mid$ for a very long time... nicely done BC!
kept getting errors with mine. took about 30 minutes. I was about to use a UDT and I realized that's what I was disproving

So I just had to add in the low-word/hi-word functions, which I ended up not using anyway. interesting.
2767.

Solve : how would i cheak to see if a file exsists??

Answer»

how WOULD i cheak to see if a file exsists?
and how would i COPY a file
also how would i copy a file into a folder that name is changing regularly1.
If EXIST file.txt echo FILE.TXT DOES EXIST
2.
Copy file.txt FOLDERNAME
3.
Do you know what it changes to? If so:

if exist Foldername1 copy file.txt Foldername1
if exist Foldername2 copy file.tdt Foldername2
rem Repeat the above lines for all the possible folder names. unfortunatly i dont know what it changes toQuote from: steven32collins on April 24, 2010, 03:40:53 PM

unfortunatly i dont know what it changes to

The you are stuck unless you do it manually.

ok there is a shortcut on my desktop and its link goes straght to the folder how would i save that link as a variable?SET linkvariable=shorcut.lnk
2768.

Solve : Elevated command prompt faiis to find path?

Answer»

Hi
I am having a problem with a elevated command prompt.
I can not find the path to an external drive using it.

Yet, it is needed to run:
net user administrator /active:yes

Which I need to successfully run:
TAKEOWN /F S:\Backup-Music\Bad-Owner\Waltz

I can find the path with the non-elevated command prompt.
Any help will be appreciated.
Frank C
Win Vista Ultimate 64 bit
Dell Inspiron 530STry this context menu add-on instead: http://www.howtogeek.com/howto/windows-vista/add-take-ownership-to-explorer-right-click-menu-in-vista/Thanks for the reply Broni,

I had INSTALLED that tool. It flashes quickly and offers no explanation of success or failure. I still cannot delete files or folders with bad owner after running it.

I was able to get ICACLS to run, using the standard cmd prompt, on the Waltz folder viz.:
ICACLS S:\BackUp-Music\Bad-Owner\Waltz /reset /T /C /L

Frank CampLet's go back a LITTLE..
What exactly are you trying to do?Thanks for the reply Broni,
My problem arose from the use of ROBOCOPY to back up my music files on a local network shared Western Digital 1 TB drive.
The backup worked OK, but on subsequent backups, Robocopy would quit when it found a file with a bad owner that it could not replace.
A sample error:
ERROR 5 (0x00000005) Deleting Extra File \\externaldrive\public\BackUp-Music\recordings\AmbroseNew\A Fine Romance-Browne.mp3
Access is denied.
The process stops there. Subsequent folders are not BACKED up.
I got around the problem by moving the bad files and folders on the external drive out of the main backup path.

In the interest of neatness I have been trying off and on for months to delete those files and folders that have the bad owner.
I tried the conventional method as administrator:
Properties > Security > Advanced > Owner > Edit > change owner to
I get access denied.
Now, I am trying to get TAKEOWN to work but as I reported It cannot find the path using an elevated command prompt.
This is not a show stopper but I would LIKE to delete the offending files and folders.
Thanks
Frank CampAddendum
Those files an folders that cause a problem have an owner of
"nobody (Unix User\nobody)"
The ones that are OK have an owner of
"Linux User,,, (EXTERNALDRIVE\everyone)"
I don't understand how Unix or Linux comes into play here unless it is a
byproduct of Robocopy.
If I look at the owner in the source it is universally:
"Frank (FRANKSPC\Frank)"What actually happens, when you try to delete those files normally?
Are you getting any errors?Sequel
Yes, The error message is "You need permission to preform this action"
That is what lead me to the DOS realm of ICACLS and TAKEOWN

I investigated my user id - Frank, It said Administrator in the description field. Yet the Account Type was ticked as Standard User. I switched to the administrator account and I was able to delete the files with the owner of Unix User\nobody.
I tried to change one of the bad owners using:
Properties > Security > Advanced > Owner > Edit > change owner to
and was denied. I could not change permissions either.

As long as I can delete the offending files I am satisfied. However, it does not clear up my confusion about ownership and permissions.
Thank You very much for your assistance Broni.
Frank CampWe can try couple more things.
First...

Download, and install Unlocker: http://ccollomb.free.fr/unlocker/
Restart computer.
It'll install under right click menu.

Open Windows Explorer.
Navigate to offending folder/file.

Right click on a folder/file. Click Unlocker
Select Delete from drop-down menu:



Click OK.
A folder/file will refuse to be deleted, but Unlocker will give you an option to delete on reboot:



Click Yes.
Restart computer.

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

If the above doesn't work, try...

LockHunter: http://lockhunter.com/

FileASSASSIN: http://www.snapfiles.com/get/fileassassin.html
Thank you Broni,
I said in my last response that I was able to delete the offending files as administrator. I didn't know that my regular ID was not administrator.
I am going to leave it at that. I will keep your advice in case of future problems.
Thanks for the help.
Frank CampYou're welcome

2769.

Solve : how can i rar windows folder in dos?

Answer»

hi
i tried to make backup to windows folder by raring it via winrar
and some of the files couldn't be read sense the its being used and some files unreadable
or something like that
i tought if i MIGHT rar it via dos in command prompt it will go clear
what is the command to rar entire windows folder in dos and what should i download to use the commandThere is no built-in command for RARing folders/files.

WinRAR comes with a command line application just called RAR.EXE.

Code: [Select]@echo off
set path="C:\Program Files\WinRAR";%path%
rar a <Directory of files to be archived>
echo Done.
pause
exit
That ought to archive the directory to the same.doesn't work
C:\>rar a
The syntax of the command is incorrect.Quote from: punto on June 03, 2010, 11:15:52 AM

doesn't work
C:\>rar a <c:\php>
The syntax of the command is incorrect.

You are not meant to copy the < and > symbols; they are there to show that what is between them is an example.
It's also probably not a good way to backup Windows anyways...Quote from: patio on June 03, 2010, 12:42:54 PM
It's also probably not a good way to backup Windows anyways...

Command line RAR or WinRAR, same problems. No good for BACKING up Windows.
then which way is good?
TRUE image doesn't supplies me
i WANT to make backup so if someday i will want to format and reinstall windows
i can do it by image iso or something and it will be exatcly like now with all the programs installedQuote from: punto on June 03, 2010, 03:59:29 PM
then which way is good?
true image doesn't supplies me
i want to make backup so if someday i will want to format and reinstall windows
i can do it by image iso or something and it will be exatcly like now with all the programs installed

yeah... and trueimage, despite being designed for that very purpose, doesn't cut it?probably no
keeps giving me errorsQuote from: punto on June 03, 2010, 09:23:33 PM
probably no
keeps giving me errors

Feel free to tell us what these errors are.Quote
backup to windows folder by raring it

Are You Serious About That...

Means How COULD You.....Why Do You....What Is The Use Of It
2770.

Solve : How can i move files in directories without the directories??

Answer»

look here

http://bit.ly/a8vkkq

and here

How to Backup using Batch Files

http://www.speedguide.net/read_articles.php?id=1547

and here

old school: use xcopy to back up your stuff

http://andrewblock.net/?p=82

and here

Using xcopy to update/backup your working folders

http://shailan.com/using-xcopy-to-updatebackup-your-working-folders/

i dont want to make backup
i already got the folders backed up with True Image
what i want is batch file that will move the directories while overwriting all the existing files\directories
same as this command
Quote from: Salmon Trout on May 19, 2010, 12:11:05 AM


Code: [Select]@echo off
for /F "delims=" %%F in ( ' dir /b /s /a-d ' ) do move "%%F" "C:\PRISON"



just that this command move only the files inside the directories and leaving the direcories emptyanyone?ignore the phrase "backup". It just means "COPY".
Quote
Have you got permission of the copyright owners of Prison Break to download their show?

Salmon..... Alwayz Following Rules ,Copyright, Law And Order



Salute To Your Rules Following NatureQuote from: the_mad_joker on June 04, 2010, 02:33:26 AM
Salmon..... Alwayz Following Rules ,Copyright, Law And Order

Salute To Your Rules Following Nature

No. But he understands the adage that when in Rome, you do as the Romans do.

Or, when you're on a forum you follow the rules. It's really quite a simple premise. I'm rather surprised it so easily slips out of the clutches of the cognitive skills of so many people seeking assistance.Quote
Rome, you do as the Romans do.

This Time I Am Not Joking...

But Seriously Dude NICE EXAMPLE mad joker, you do post like a complete jerkwad sometimes. Most of the time in FACT. Maybe EVEN all of the time.

2771.

Solve : bat file... quick launch icon!?

Answer»

what is the code for CREATING a quick launch icon to my .exeQuote

what is the code for creating a quick launch icon to my .exe

Quick Launch Means Shortcut Or .... Quote from: night-rider on June 03, 2010, 11:13:34 PM
what is the code for creating a quick launch icon to my .exe


C:\test>type coll.bat
@ECHO off

start "c:\program files\internet explorer\iexplore.exe" HTTP://www.google.com/

C:\test>what did that do Marvin
Quote from: the_mad_joker on June 04, 2010, 02:34:17 AM
Quick Launch Means Shortcut Or ....

yap! so maybe I will just then copy the shortcut icon to the DIRECTORY of quicklaunch.Quote from: mat123 on June 04, 2010, 05:53:32 PM
what did that do Marvin


Starts internet Explorer and displays google.com.

relevance is left as an exercise for the reader, I suppose.
2772.

Solve : serch bat program?

Answer»

Quote from: mat123 on June 03, 2010, 08:03:54 AM

Marvin bat to exe compilers have a bat FILE in them
when you run the exe the bat file is put in a temporary folder this finds it opens it up in notepad
to be edited

The reason to complie a batch file to an .exe file is to hide the batch code?

But now you say the .exe file can be edited with your decomplier and the original batch code is available.

I doubt it.

Please show your output.

Quote from: mat123 on June 03, 2010, 08:03:54 AM
Marvin bat to exe compilers have a bat file in them
when you run the exe the bat file is put in a temporary folder this finds it opens it up in notepad
to be edited

Sometimes it is run from memoryQuote from: Salmon Trout on June 03, 2010, 11:27:50 AM
Sometimes it is run from memory
It all depends on what converter you used.Quote from: Helpmeh on June 03, 2010, 03:28:17 PM
It all depends on what converter you used.

Does Helmeh mean the compiler that changed the original batch file to an exe file?

Or does Helpmeh mean the "DECompiler" that changes the exe file to the original batch file?Quote from: marvinengland on June 03, 2010, 04:13:57 PM
Does Helmeh mean the compiler that changed the original batch file to an exe file?

Or does Helpmeh mean the "DECompiler" that changes the exe file to the original batch file?
Try reading. If you do, you may realize that neither of those options are what I mean.Quote from: mat123 on May 23, 2010, 04:42:01 PM
I am making a exe to bat decompliler but it has problems could you help me fix them




http://technet.microsoft.com/en-us/library/cc750056.aspx

All the following from the above link.


"Compiling Batch Files
Batch Files are easy to modify, which can create problems. BAT2EXEC is a compiler for batch files, and it turns your batch file into a exe file. Compiled batch files execute faster and create a source code that is protected from change. Before you compile a batch file, be sure to save the original under another name. Once you have compiled the file using BAT2EXEC, you cannot uncompile it to make changes."Quote from: marvinengland on June 03, 2010, 06:47:31 PM


http://technet.microsoft.com/en-us/library/cc750056.aspx

All the following from the above link.


"Compiling Batch Files
Batch Files are easy to modify, which can create problems. BAT2EXEC is a compiler for batch files, and it turns your batch file into a exe file. Compiled batch files execute faster and create a source code that is protected from change. Before you compile a batch file, be sure to save the original under another name. Once you have compiled the file using BAT2EXEC, you cannot uncompile it to make changes."
try using bat2exec on a batch file today. Note the DATE:

"BAT2EXEC (Douglas Boling, PC Magazine, August 1990)"

How many batch files posted here would work on DOS 6? a optimistic estimate would be mybe a quarter of a percent.

It only works for batch files that work in Pure DOS- that is, no for /f, no FORFILES, no command extensions whatsoever. You'd be hard pressed to find more then a handful of batch files that will actually work with that compiler today.

Additionally since the result is also a DOS COM executable it won't work on 64-bit operating systems and doesn't support anything provided by cmd- including long file names. Additionally the number of additional limitations imposed on the function of a batch file when it is converted to a 64K flat model restrict it's usefulness even further.

Good luck creating something useful within such severe limitations. In fact, even the relatively simple batch file you posted earlier wouldn't work:

Code: [Select]@echo off

rem Convert exe to bat

rem http://fixunix.com/ms-dos/539963-converting-exe-file-bat-file.html


rem How to convert exe file to bat file?
Rem Simple, here's an example:


@echo off
REM tested
ren myfile.exe myfile.bat

rem another example:
echo off
REM RESULTS cause problems in some OS's
ren Buddist.exe Christian.bat


Know why? Of course not. That's why you think bat2exec is even close to what is being discussed. If you add a "dir Christian.bat" to the end of that batch (in order to confirm output, as you are so readily able to point out in other peoples batches but appear to neglect in your own) you will get the message "File not found".

If even the most basic batch consisting of a few rename commands doesn't work properly what hope is there for batches that actually do something useful?
Quote from: marvinengland on June 03, 2010, 06:47:31 PM


http://technet.microsoft.com/en-us/library/cc750056.aspx



I did not write the following code. I provided a link to the code. The code demonstrated the futility of a "decompiler." The code and link did not claim a valid decompiler.

rem Convert exe to bat

http://fixunix.com/ms-dos/539963-converting-exe-file-bat-file.html

How to convert exe file to bat file?
Simple, here's an example:


Code: [Select]@echo off
REM tested
ren myfile.exe myfile.bat

rem another example:
echo off
REM results cause problems in some OS's
ren Buddist.exe Christian.bathttp://www.program-transformation.org/Transform/LegalityOfDecompilation



Legality Of Decompilation
Program-Transformation.Org: The Program Transformation WikiIf decompilation is possible to a certain extent, is it then also allowed?
Decompilation can be used for a number of reasons (see WhyDecompilation for more), including:
Recovery of lost source code (by accident or via a disgruntled employee),
Migration of assembly language applications to a new hardware platform,
Translation of code written in obsolete languages no longer supported by compiler TOOLS,
Determination of the existence of viruses or malicious code in the program, and
Recovery of someone else's source code (to determine an algorithm for example).
However, not all uses of decompilers are legal uses.
Throughout the world, computer programs are protected by copyright law. Copyright protects the expression of an idea in the form of a program, hence protecting the developer's (or company's) investment in writing the software. Copyright law provides a bundle of exclusive rights to the software developer; among others, the right to reproduce and make adaptations to the developed computer program. It is a breach of these rights to make reproductions or adaptations without permission of the copyright holder. Further, license agreements may also bind the user to operate the program in a certain way and to avoid using decompilation or disassembly techniques on that program.
Different countries have different exceptions to the copyright owner's rights or precedent has been established in court proceedings. This means that these uses are allowed by law. The most common ones are:
Decompilation/disassembly for the purposes of interoperability (to another piece of software or hardware) where the interface specification has not been made available,
Decompilation/disassembly for the purposes of error correction where the owner of the copyright is not available to make the correction, and
To determine parts of the program that are not protected by copyright (e.g. algorithms), without breach of other forms of protection (e.g. patents or trade secrets).
Not all countries implement the same laws, you should contact your lawyer if in doubt.
2773.

Solve : how can i stop the scandisk?

Answer»

hi
each time i restart the COMPUTER it makes scandisk
since i tried to MAKE backup with true image
im SURE its something to do with the true image installation
since after the scan there is message including true image
anyway i want to cancel the scandisk so no scandisks will appear each time i reboot
is it possible? os is xp

Possibly Scandisk is being run for a good reason. If it is always finding lost chains like in the picture, then you could have a disk PROBLEM. Also, why didn't you tell us what exactly was the "message including true image"?
Boot to the recovery CONSOLE and run chkdsk /r

2774.

Solve : Robocopy version and Download source?

Answer»

Hi,
How do I determine the version of Robocopy that I have?
I looked at Robocopy.exe.mui > properties > details and it did not show the version. If I can determine the version and if here is a later one available where can I find it?
My Robocopy came with Vista.
Thanks
Frank C
Quote from: FrankGC on June 06, 2010, 10:14:40 AM

Hi,
How do I determine the version of Robocopy that I have?
I looked at Robocopy.exe.mui > properties > details and it did not show the version. If I can determine the version and if here is a later one available where can I find it?
My Robocopy came with Vista.
Thanks
Frank C


C:\>dir /s robo*.*
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\Program Files\Windows Resource Kits\Tools

04/02/2003 08:07 PM 253,440 robocopy.doc
04/18/2003 06:06 PM 79,872 robocopy.exe
2 File(s) 333,312 bytes


http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en




Directory of C:\Windows\System32

07/13/2009 08:14 PM 97,280 Robocopy.exe
1 File(s) 97,280 bytes
Code: [Select]Version File version Year Origin
1.70 - 1997 Windows NT Resource Kit
1.71 4.0.1.71 1997 Windows NT Resource Kit
1.95 4.0.1.95 1999 Windows 2000 Resource Kit
1.96 4.0.1.96 1999 Windows 2000 Resource Kit
XP010 5.1.1.1010 2003 Windows 2003 Resource Kit
XP026 5.1.2600.26 2005 Downloaded with Robocopy GUI v.3.1.2
XP027 5.1.10.1027 2008 Bundled with Windows Vista, Server 2008 and later
Note: XP027 only runs on Vista and later, and was included in those OSs anyway, so there is no point in downloading later than XP026.
Holey Cow...Thanks to all for the responses.
My Win Vista has Windows Resource Kits Tools is here:
C:\Program Files (x86)\Windows Resource Kits\Tools
It has Subinacl but I don't see Robocopy.
The reason that I asked about the version of Robocopy is because I got in considerable difficulty with some folders and files regarding ownership and permissions on the external drive that was used for backup by Robocopy.
See Post "Elevated command Prompt fails to find path" Reply #4 on: June 01, 2010, 11:36:21 AM »
I did not want to repeat that experience so I wanted to see if My robocopy was up to date. I did run it again and had no difficulty.
Still, it would be nice to find the Robocopy.exe and see it's version number.
Do you KNOW where it is in Vista Ultimate 64 bit?
Thanks
Frank CampQuote
Do you know where it is in Vista Ultimate 64 bit?

The usual place would be C:\Windows\System32 (This is where Robocopy.exe is on my Windows 7 Pro 64 bit, and I have no doubt that it's the same on Vista. If it is, and you didn't put it there, it must be the default bundled version and it must therefore be the latest version - XP027, file version 5.1.10.1027.

Your file ownership/permission problems are unlikely to be have been CAUSED by Robocopy.
Thanks so much Salmon Trout,
I did find Robocopy.exe in C:\Windows\System32
It came bundled with Vista Ultimate 64 bit.
It is version 5.1.0.0 1027 dated 1/20/2008.
I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive.
The bad owners were - nobody (Unix User\nobody)
The OK owners were - Linux User,,, (EXTERNALDRIVE\everyone)
Thanks
Frank CampQuote
I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive.
The bad owners were - nobody (Unix User\nobody)
The OK owners were - Linux User,,, (EXTERNALDRIVE\everyone)
Thanks
Frank Camp

Quote
/COPY:copyflag :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

did you use /COPY:DATSOU ?Quote from: FrankGC on June 07, 2010, 03:28:23 PM
I do believe the ownership/permission problem arose from Robocopy. I was not using any other tool to write to the external drive.

OK, I'll rephrase it slightly

Your file ownership/permission problems are likely to be have been caused by how you used Robocopy.Thanks to both for the response.

This is the Robocpy cmd inside of a small .bat file
Perhaps using /COPY:DT was not a good idea, but initially I got a lot of "Error 5 Access denied".

Robocopy C:\Users\Owner\Music\recordings\ \\externaldrive\public\BackUp-Music\recordings\ /S /COPY:DT /MIR /Log:MusicBkupLog.txt

/COPY:DT copies Data and Timestamps. Does not copy Attributes thus avoiding "Error 5 access denied".
/MIR mirrors the source directory tree
/S copy Subdirectories, but not empty ones.

Running Robocopy under Task Scheduler can be challenging if the destination is a shared network drive.
A solution to get the destination drive accessed is to use Universal Naming Convention (UNC) addressing for the target:
\\externaldrive\public\BackUp-Music\recordings\

I used the same format to backup pictures with no problem:
Robocopy C:\Users\Public\Pictures\ \\externaldrive\public\BackUp-Pictures\ /S /COPY:DT /MIR /Log:PictureBkupLog.txt

Thanks
Frank Camp
2775.

Solve : SORT.exe?

Answer»

Quote

Run Command Window as System Administrator:
Click START , right click Command Prompt and Choose "Run as System Administrator"

This Worked For Me

Hoorayyyyyyyyyyyyyy Quote from: the_mad_joker on June 08, 2010, 11:47:41 AM


Hoorayyyyyyyyyyyyyy

Run Command Window as System Administrator:
Click Start , right click Command Prompt and Choose "Run as System Administrator"

The above worked because the default command window location for the System Administrator is :

C:\Windows\system32\

When the OS searches for sort.exe, it looks at the current folder first.

Nevertheless, for future sessions you need to set your system search PATH.



C:\test>path
PATH=C:\Program Files\Windows Resource Kits\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1
;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\GnuWin32\bin;c:\bin

C:\test>TYPE pat.bat
@echo off
set PATH=C:\Program Files\Windows Resource Kits\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShel
1.0\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\GnuWin32\bin;c:\bin

rem path=%PATH%;C:\Program Files\GnuWin32\bin


path
C:\test>I've already told him that, marvin. Are you always going to dog my steps, posting the same things I do? I Think Salmon Is Angry On Marvin ...... LADIES AND GENTLEMAN ,Dogs And Cats ,Clowns (Of Course) We Are Gonna Have A FIGHT Here

Common Salmon YOU Can Do It

========================================
| Apart Jokes , Thanx To Both Of You Salmon And Marvin |
========================================
2776.

Solve : DOS command to Count files in a folder?

Answer»

Please help me with a DOS command to count the NUMBER of files in a FOLDER with name starting with 'xxx'. The folder contains hundreds of files and few of then will be of name 'xxx_01.txt', 'xxx_02.txt' 'xxx_03.txt' etc.There are several ways to do this, amongst them are:
1] dir xxx*.*
which will show the count of files at the end of the list of files
2] dir /b xxx*.*|find /c /i "xxx"
which just SHOWS the count
Graham
Thanks a lot Graham.
The second command is exactly what i NEEDED.

2777.

Solve : return in the same window?

Answer»

Hi everyone,

I didn't success to make my problem understandable by Google,
so I'm TRYING this here !
And it's surely not so hard..

So my problem is :
I use Devcon to manage my devices, it's a small .exe file.

With the command : devcon /hwids *usb*, the PROGRAMM returns all the devices linked with the PC.

But when I do this, it open a new window, print the list, and then this window close.

But what should normally happend, and what I want, is that the list print in the same window I execute the command.

With the aim, after, to write this list in a txt file, with the command : devcon /hwids *usb* > device.txt


I hope I'm giving all the REQUIRED clues. THANK you ! Maybe try:

call devcon /hwids *usb* > device.txtNo It still pop-up...Maybe that's just the program. I don't think you can do that... I'm quite sure it's possible, because the examples given (or here )with this program SHOW the return is print direct after the command.
Maybe it's due to W7 Ms-Dos compatibility, or I don't know..

Any way, Thanks for responding ! Ok, I confirm, it's a problem of which OS you have.
It works better on the command prompt of W XP !you have to start the command prompt first. Then you run the devcon command.

2778.

Solve : Download the most recent files from FTP?

Answer»

I am trying to create a batch file that will download the 5 most recent files from the FTP. The full file name will be unknown because they are generational files. The files will look like AAAA.AAAAAAAAA.daily.G0001, AAAA.AAAAAAAAA.daily.G0002, AAAA.AAAAAAAAA.daily.G0003 etc.
The dates on the files might all be the same but I need to download only the most recent files. IE G0002 and G0003.
Currently I have the batch file downloading the entire path with wild card characters.
here is how I am declaring which files to pull:

mget 'AAAA.AAAAAAAAA.daily*.*'

This pulls everything. I just need the 5 most recent. These appear on the bottom of the list in FTP but the entire list has the same date.

Any help WOULD be nice.
Thanks,
JC


To determine an unknown character, you can use ?

A better alternative to FTP is WSH for example:

@ECHO OFF
set v1=C:\folder
set var="temp.vbs"
set id=filename.g0001
set url=http://yourwebpage.com/folder/file.G0001
if not exist %id% md "%id%"
echo strFileURL = "%url%">%v1%\%var%
echo strHDLocation = "%v1%\%id%">>%v1%\%var%
echo Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")>>%v1%\%var%
echo objXMLHTTP.open "GET", strFileURL, false>>%v1%\%var%
echo objXMLHTTP.send()>>%v1%\%var%
echo If objXMLHTTP.Status = 200 Then>>%v1%\%var%
echo Set objADOStream = CreateObject("ADODB.Stream")>>%v1%\%var%
echo objADOStream.Open>>%v1%\%var%
echo objADOStream.Type = 1 'adTypeBinary>>%v1%\%var%
echo objADOStream.Write objXMLHTTP.ResponseBody>>%v1%\%var%
echo objADOStream.Position = 0 >>%v1%\%var%
echo Set objFSO = Createobject("Scripting.FileSystemObject")>>%v1%\%var%
echo If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation>>%v1%\%var%
echo Set objFSO = Nothing>>%v1%\%var%
echo objADOStream.SaveToFile strHDLocation>>%v1%\%var%
echo objADOStream.Close>>%v1%\%var%
echo Set objADOStream = Nothing>>%v1%\%var%
echo End if>>%v1%\%var%
echo Set objXMLHTTP = Nothing>>%v1%\%var%
%v1%\%var% &AMP;del /q/f %v1%\%var%


Now assuming the extention of each filename is in order, g0001, g0002, g0003, ect and stored to a folder you can use IF

@ECHO OFF
set v1=c:\pathtoyourfolder
if exist %v1%*.g000? (for /f "tokens=1*" %a in ('dir /a %v1%*.g000? /b') do set id=%a & if exist %v1%\%id% (call set /a h=%id:~-1,1%+1))
if not exist %v1%*.g000%h% (set var=tmp.vbs &set url=http://yoururlhere.com/folder/filename.%g000%h%&GOTO UPD) ELSE CLS&ECHO File ALREADY On HD&Pause&Goto xx
:UPD
echo strFileURL = "%url%">%v1%\%var%
echo strHDLocation = "%v1%\%id%">>%v1%\%var%
echo Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")>>%v1%\%var%
echo objXMLHTTP.open "GET", strFileURL, false>>%v1%\%var%
echo objXMLHTTP.send()>>%v1%\%var%
echo If objXMLHTTP.Status = 200 Then>>%v1%\%var%
echo Set objADOStream = CreateObject("ADODB.Stream")>>%v1%\%var%
echo objADOStream.Open>>%v1%\%var%
echo objADOStream.Type = 1 'adTypeBinary>>%v1%\%var%
echo objADOStream.Write objXMLHTTP.ResponseBody>>%v1%\%var%
echo objADOStream.Position = 0 >>%v1%\%var%
echo Set objFSO = Createobject("Scripting.FileSystemObject")>>%v1%\%var%
echo If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation>>%v1%\%var%
echo Set objFSO = Nothing>>%v1%\%var%
echo objADOStream.SaveToFile strHDLocation>>%v1%\%var%
echo objADOStream.Close>>%v1%\%var%
echo Set objADOStream = Nothing>>%v1%\%var%
echo End if>>%v1%\%var%
echo Set objXMLHTTP = Nothing>>%v1%\%var%
echo Set objXMLHTTP = Nothing>>%v1%\%var%
%v1%\%var%
if not exist (%v1%\%var% CLS&echo Update failed, File not available&Pause&GOTO XX) else CLS&Echo Update Succeeded&Pause&goto XX
:xx
exit


In the above example it checks to see the last file downloaded, and downloads the file beyond that you need only to set the variables to your liking it will tell you if it FAILS or succeeds

2779.

Solve : Need to create batch file with 10 sec interval between every 5 files transferred?

Answer»

I need to create a batch file that copies multiple files (huge # of files) from my xp desktop to a windows 2003 server.
I need to copy 5 files at a time and then take a 10 seconds break in between until all the files are copied.

xcopy a:\file_1 \\10.0.0.5\C$
(from) (to)
Any help would be appreciated.

Thanks!Quote from: zzahid on June 09, 2010, 02:08:20 PM


xcopy a:\file_1 \\10.0.0.5\C$
(from) (to)
Any help would be appreciated.

Thanks!

This is rough idea what is needed. A COUNTER and sleep command.


C:\test>type zz.bat
Code: [Select]@Echo off
setlocal enabledelayedexpansion
set /a CNT=0
for /f "delims=" %%i in ('dir /s /b c:\*.txt') do (
set /a cnt=!cnt! + 1
echo cnt=!cnt!
if !cnt! EQU 10 sleep 10
if !cnt! EQU 12 goto end
xcopy /s %%i c:\zz\
)

:end
Output:

C:\test>zz.bat
cnt=1
cnt=3
C:\06-07-2010\a1.txt
1 File(s) copied
cnt=4
C:\06-07-2010\a2.txt
1 File(s) copied
cnt=5
C:\06-07-2010\a3.txt
1 File(s) copied
cnt=6
C:\06-07-2010\a4.txt
1 File(s) copied
cnt=7
C:\06-07-2010\a5.txt
1 File(s) copied
cnt=8
C:\06-07-2010\abc.txt
C:\06-07-2010\archive\abc.txt
C:\06-07-2010\Backup\15\abc.txt
C:\06-07-2010\Backup\17\abc.txt
C:\06-07-2010\Backup\18\abc.txt
C:\06-07-2010\savhere\abc.txt
6 File(s) copied
cnt=9
C:\06-07-2010\abc2.txt

C:\06-07-2010\archive\abc2.txt
C:\06-07-2010\Backup\15\abc2.txt
C:\06-07-2010\Backup\17\abc2.txt
C:\06-07-2010\Backup\18\abc2.txt
C:\06-07-2010\savhere\abc2.txt
6 File(s) copied
cnt=10
C:\06-07-2010\abc5.txt
C:\06-07-2010\Backup\17\abc5.txt
C:\06-07-2010\Backup\18\abc5.txt
3 File(s) copied
cnt=11
C:\06-07-2010\arc.txt
1 File(s) copied
cnt=12

C:\test>I have to SAY, not a bad effort by marvin.
2780.

Solve : MS Dos Project?

Answer»

The project I have to do is create a zip file in MS Doc for all data that fails. & Then plainly put the created code with the rest of the code. Please tell me if I am on the right track & please give me hints.

Code:


ECHO OFF // Displays messages, or turns command-echoing off.
set ConfigFile=config.cfg // Allows you to change one variable or string to another.

set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt // Allows you to change one variable or string to another.

set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt // Allows you to change one variable or string to another.

set wmailto=c:\windows\wmailto.exe // Allows you to change one variable or string to another.

set "ExistFreeSpace=0" // Allows you to change one variable or string to another.

echo Job starting.... >> %loglocation% // Displays messages, or turns command-echoing on

date /t >> %loglocation% // Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% // Appends output to the named file if it exists or creates the file and then writes to it.

:: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% // Call to the file and displays.

:: ** Call MDMcreateCSVfiles //Call to the file and displays.

:: ** echo Returned from bat file call - continuing.... >> %loglocation% // Keep file running after it returns

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof
) // Checks to see if file is there; if not display the following messages.

:: *** Call the subroutine; // Calls another batch file and then returns to current batch file to continue.



:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo // Calls another batch file and then returns to current batch file to continue.

call :ReadConfig email email// Calls another batch file and then returns to current batch file to continue.

call :ReadConfig Warningemail Warningemail // Calls another batch file and then returns to current batch file to continue.

call :ReadConfig extension extension // Calls another batch file and then returns to current batch file to continue.

call :ReadConfig MinFreeSpacePrcnt MinFreeSpace // Calls another batch file and then returns to current batch file to continue.

echo Log space on server.... >> %loglocation% Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace >> %loglocation% // Calls another batch file and then returns to current batch file to continue.

setlocal EnableDelayedExpansion // Inserts strings into the command environment. The set values can be used later by programs.

FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i // Executable statement

call :ReadConfig Source!ind! source // Calls another batch file and then returns to current batch file to continue.

call :ReadConfig OlderThan!ind! olderthan // Calls another batch file and then returns to current batch file to continue.

echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation%
cd %source% // Displays messages, or turns command-echoing off/on.

echo . >>%loglocation% Displays messages, or turns command-echoing off/on.
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% // executable statement



echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% //
Displays messages, or turns command-echoing off/on.

echo Delete finished... >> %loglocation% // Displays messages, or turns command-echoing off/on.

echo. >>%loglocation%
) // Displays messages, or turns command-echoing off/on.

echo. // Displays messages, or turns command-echoing off/on.
echo All Deletes complete.... >> %loglocation% // Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace>> %loglocation% // Calls another batch file and then returns to current batch file to continue.

date /t >> %loglocation% // Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% // Appends output to the named file if it exists or creates the file and then writes to it.

echo >>%loglocation% // Displays file.

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min REQUIRED free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
) // Executable statement

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof // Executable statements

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof // Executable statements

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION // Allows you to change one variable or string to another.

::@SETLOCAL ENABLEEXTENSIONS // Allows you to change one variable or string to another.

@CLS //

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p //

@SET /A TotalSpace=!TotalBytes:~0,-9! // Allows you to change one variable or string to another.

@SET /A FreeSpace=!FreeBytes:~0,-10! // Allows you to change one variable or string to another.

@SET /A TotalUsed=%TotalSpace% - %FreeSpace% // Allows you to change one variable or string to another.

@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! // Allows you to change one variable or string to another.

@SET /A PercentFree=100-!PercentUsed! // Allows you to change one variable or string to another.
@ECHO Total space: %TotalSpace%GB // Displays messages
@ECHO Free space: %FreeSpace%GB // Displays messages
@ECHO Used space: %TotalUsed%GB // Displays messages

@ECHO Percent Used: %PercentUsed%%% // Displays messages

@ECHO Percent Free: %PercentFree%%% // Displays messages

::ENDLOCAL //

ENDLOCAL &set "%~1=%PercentFree%" //
goto :eof //


My code for the zip file:

set LOCAL_DIR=C:\temp1

if %COMPRESS% equ 1 (

echo %time% - Compressing Data Pump Files >> %SLOG% 2>&1
dir %LOCAL_DIR%\%DUMPFILE%*.* /b > %LOCAL_DIR%\dir.lst
set DIR_LIST=%LOCAL_DIR%\dir.lst


FOR /F %%A IN (%DIR_LIST%) DO (
echo Compressing: %%A

rar.exe a %LOCAL_DIR%\%%A.zip %LOCAL_DIR%\%%A
if %ERRORLEVEL% neq 0 (echo %time% - *** COMPRESS ERROR *** >> %SLOG% 2>&1)

if exist %LOCAL_DIR%\%%A.zip (del %LOCAL_DIR%\%%A /q)
)
)


A
MS DOC. what is that?
B
don't comment like that use rem or ::
for ex
ECHO OFF // Displays messages, or turns command-echoing off
becomes
@echo off
::Displays messages, or turns command-echoing off
C
what are you tying to do. fails what?
D
is this for homework?Sorry that I commented my code the way I did. I am used to dealing with C++ Programming & Java. Basically the program/ code is supposed to place all failed data into a file, I want to put it into a zip file. I am trying to figure out how to create the code so that the failed data can transfer into the zip file efficiently. P.S. I am doing this my uncle; who owns technology company. Quote from: JH0676796 on June 10, 2010, 07:39:52 AM

Sorry that I commented my code the way I did. I am used to dealing with C++ Programming & Java. Basically the program/ code is supposed to place all failed data into a file, I want to put it into a zip file. I am trying to figure out how to create the code so that the failed data can transfer into the zip file efficiently. P.S. I am doing this my uncle; who owns technology company.

since every line with a // is now invalid you can start by fixing the comments.

use REM, not ::, by the way. :: has too many special cases where it can cause all sorts of problems.Okay I fixed the comment aspect. Whats next??

Fixed Code:
ECHO OFF :: Displays messages, or turns command-echoing off.
set ConfigFile=config.cfg :: Allows you to change one variable or string to another.

set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another.

set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another.

set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another.

set "ExistFreeSpace=0" :: Allows you to change one variable or string to another.

echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on

date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

:: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays.

:: ** Call MDMcreateCSVfiles :: Call to the file and displays.

:: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof) :: Checks to see if file is there; if not display the following messages.

:: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue.



:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue.

echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue.

setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs.

FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i :: Executable statement

call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue.

echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation%
cd %source% :: Displays messages, or turns command-echoing off/on.

echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on.
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement





echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on.

echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

echo. >>%loglocation%
) :: Displays messages, or turns command-echoing off/on.

echo. :: Displays messages, or turns command-echoing off/on.
echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue.

date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

echo >>%loglocation% :: Displays file.

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
) :: Executable statement

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof ::Executable statements

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof :: Executable statements

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another.

::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another.

@CLS //

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p //

@SET /A TotalSpace=!TotalBytes:~0,-9! // Allows you to change one variable or string to another.

@SET /A FreeSpace=!FreeBytes:~0,-10! // Allows you to change one variable or string to another.

@SET /A TotalUsed=%TotalSpace% - %FreeSpace% // Allows you to change one variable or string to another.

@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! // Allows you to change one variable or string to another.

@SET /A PercentFree=100-!PercentUsed! // Allows you to change one variable or string to another.
@ECHO Total space: %TotalSpace%GB // Displays messages
@ECHO Free space: %FreeSpace%GB // Displays messages
@ECHO Used space: %TotalUsed%GB // Displays messages

@ECHO Percent Used: %PercentUsed%%% // Displays messages

@ECHO Percent Free: %PercentFree%%% // Displays messages

::ENDLOCAL //

ENDLOCAL &set "%~1=%PercentFree%" //
goto :eof //

First, most of the comments are still "//"

second, they can only appear on a line by themselves. batch has no PROVISION for inline comments.

I did it, whats next :


ECHO OFF :: Displays messages, or turns command-echoing off.
set ConfigFile=config.cfg :: Allows you to change one variable or string to another.
set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt :: Allows you to change one variable or string to another.
set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt :: Allows you to change one variable or string to another.
set wmailto=c:\windows\wmailto.exe :: Allows you to change one variable or string to another.

set "ExistFreeSpace=0" :: Allows you to change one variable or string to another.

echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on

date /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

:: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% :: Call to the file and displays.

:: ** Call MDMcreateCSVfiles :: Call to the file and displays.

:: ** echo Returned from bat file call - continuing.... >> %loglocation% :: Keep file running after it returns

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof) :: Checks to see if file is there; if not display the following messages.

:: *** Call the subroutine; :: Calls another batch file and then returns to current batch file to continue.



:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig email email :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig Warningemail Warningemail :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig extension extension :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig MinFreeSpacePrcnt MinFreeSpace :: Calls another batch file and then returns to current batch file to continue.

echo Log space on server.... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace >> %loglocation% :: Calls another batch file and then returns to current batch file to continue.

setlocal EnableDelayedExpansion :: Inserts strings into the command environment. The set values can be used later by programs.

FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i :: Executable statement

call :ReadConfig Source!ind! source :: Calls another batch file and then returns to current batch file to continue.

call :ReadConfig OlderThan!ind! olderthan ::Calls another batch file and then returns to current batch file to continue.

echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation%
cd %source% :: Displays messages, or turns command-echoing off/on.

echo . >>%loglocation% :: Displays messages, or turns command-echoing off/on.
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% ::executable statement





echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% ::Displays messages, or turns command-echoing off/on.

echo Delete finished... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

echo. >>%loglocation%
) :: Displays messages, or turns command-echoing off/on.

echo. :: Displays messages, or turns command-echoing off/on.
echo All Deletes complete.... >> %loglocation% :: Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace>> %loglocation% :: Calls another batch file and then returns to current batch file to continue.

date /t >> %loglocation% ::Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% :: Appends output to the named file if it exists or creates the file and then writes to it.

echo >>%loglocation% :: Displays file.

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
) :: Executable statement

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof ::Executable statements

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof :: Executable statements

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION :: Allows you to change one variable or string to another.

::@SETLOCAL ENABLEEXTENSIONS :: Allows you to change one variable or string to another.

@CLS ::

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p ::

@SET /A TotalSpace=!TotalBytes:~0,-9! :: Allows you to change one variable or string to another.

@SET /A FreeSpace=!FreeBytes:~0,-10! :: Allows you to change one variable or string to another.

@SET /A TotalUsed=%TotalSpace% - %FreeSpace% :: Allows you to change one variable or string to another.

@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! :: Allows you to change one variable or string to another.

@SET /A PercentFree=100-!PercentUsed! :: Allows you to change one variable or string to another.
@ECHO Total space: %TotalSpace%GB :: Displays messages
@ECHO Free space: %FreeSpace%GB ::Displays messages
@ECHO Used space: %TotalUsed%GB :: Displays messages

@ECHO Percent Used: %PercentUsed%%% :: Displays messages

@ECHO Percent Free: %PercentFree%%% :: Displays messages

::ENDLOCAL ::

ENDLOCAL &set "%~1=%PercentFree%" ::
goto :eof ::
Just to make sure you get this through:
Quote from: BC_Programmer on June 10, 2010, 08:21:18 AM
batch has no provision for inline comments.

So,

echo Job starting.... >> %loglocation% :: Displays messages, or turns command-echoing on

needs to become:

echo Job starting.... >> %loglocation%
rem Displays messages, or turns command-echoing on


You have been told this already... don't use double colons ( for comments! Use rem or REM. Using a broken LABEL (that is what :: is) causes problems in parenthetical structures, is unsupported, deprecated and is FROWNED UPON.
ECHO OFF REM Displays messages, or turns command-echoing off.
set ConfigFile=config.cfg REM Allows you to change one variable or string to another.
set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt REM Allows you to change one variable or string to another.
set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt REM Allows you to change one variable or string to another.
set wmailto=c:\windows\wmailto.exe REM Allows you to change one variable or string to another.

set "ExistFreeSpace=0" REM Allows you to change one variable or string to another.

echo Job starting.... >> %loglocation% REM Displays messages, or turns command-echoing on

date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it.

:: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation% REM Call to the file and displays.

:: ** Call MDMcreateCSVfiles REM Call to the file and displays.

:: ** echo Returned from bat file call - continuing.... >> %loglocation% REM Keep file running after it returns

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof) REM Checks to see if file is there; if not display the following messages.

:: *** Call the subroutine; REM Calls another batch file and then returns to current batch file to continue.



:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo REM Calls another batch file and then returns to current batch file to continue.

call :ReadConfig email email REM Calls another batch file and then returns to current batch file to continue.

call :ReadConfig Warningemail Warningemail REM Calls another batch file and then returns to current batch file to continue.

call :ReadConfig extension extension REM Calls another batch file and then returns to current batch file to continue.

call :ReadConfig MinFreeSpacePrcnt MinFreeSpace REM Calls another batch file and then returns to current batch file to continue.

echo Log space on server.... >> %loglocation% REM Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace >> %loglocation% REM Calls another batch file and then returns to current batch file to continue.

setlocal EnableDelayedExpansion REM Inserts strings into the command environment. The set values can be used later by programs.

FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i REM Executable statement

call :ReadConfig Source!ind! source REM Calls another batch file and then returns to current batch file to continue.

call :ReadConfig OlderThan!ind! olderthan REMCalls another batch file and then returns to current batch file to continue.

echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation%
cd %source% REM Displays messages, or turns command-echoing off/on.

echo . >>%loglocation% REM Displays messages, or turns command-echoing off/on.
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation% REM executable statement





echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation% REM Displays messages, or turns command-echoing off/on.

echo Delete finished... >> %loglocation% REM Displays messages, or turns command-echoing off/on.

echo. >>%loglocation%
) REM Displays messages, or turns command-echoing off/on.

echo. :: Displays messages, or turns command-echoing off/on.
echo All Deletes complete.... >> %loglocation% REM Displays messages, or turns command-echoing off/on.

call :FreeSpace ExistFreeSpace>> %loglocation% REM Calls another batch file and then returns to current batch file to continue.

date /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it.

time /t >> %loglocation% REM Appends output to the named file if it exists or creates the file and then writes to it.

echo >>%loglocation% REM Displays file.

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
) REM Executable statement

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof REM Executable statements

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof REM Executable statements

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION REM Allows you to change one variable or string to another.

::@SETLOCAL ENABLEEXTENSIONS REM Allows you to change one variable or string to another.

@CLS REM

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p REM

@SET /A TotalSpace=!TotalBytes:~0,-9! REM Allows you to change one variable or string to another.

@SET /A FreeSpace=!FreeBytes:~0,-10! REM Allows you to change one variable or string to another.

@SET /A TotalUsed=%TotalSpace% - %FreeSpace% REM Allows you to change one variable or string to another.

@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace! REM Allows you to change one variable or string to another.

@SET /A PercentFree=100-!PercentUsed! REM Allows you to change one variable or string to another.
@ECHO Total space: %TotalSpace%GB REM Displays messages
@ECHO Free space: %FreeSpace%GB REM Displays messages
@ECHO Used space: %TotalUsed%GB REM Displays messages

@ECHO Percent Used: %PercentUsed%%% REM Displays messages

@ECHO Percent Free: %PercentFree%%% REM Displays messages

::ENDLOCAL ::

ENDLOCAL &set "%~1=%PercentFree%" REM
goto :eof REM




Now can someone please tell me how to create a zip file using this code?

Thanks! Quote
set ConfigFile=config.cfg REM Allows you to change one variable or string to another.

You have also been told that you can't have inline comments! Don't you read the answers? Your configfile variable is going to be "config.cfg REM Allows you to change one variable or string to another." All those CHARACTERS.

What are all those lines starting :: ** ?

You are not going the right way to get your batch file fixed.


ECHO OFF
set ConfigFile=config.cfg
set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt
set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt
set wmailto=c:\windows\wmailto.exe
set "ExistFreeSpace=0"

echo Job starting.... >> %loglocation%
date /t >> %loglocation%
time /t >> %loglocation%

:: ** echo Calling MDMcreateCSVfiles bat file.... >> %loglocation%
:: ** Call MDMcreateCSVfiles
:: ** echo Returned from bat file call - continuing.... >> %loglocation%

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof
)

:: *** Call the subroutine;
:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo
call :ReadConfig email email
call :ReadConfig Warningemail Warningemail
call :ReadConfig extension extension
call :ReadConfig MinFreeSpacePrcnt MinFreeSpace

echo Log space on server.... >> %loglocation%
call :FreeSpace ExistFreeSpace >> %loglocation%

setlocal EnableDelayedExpansion
FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i
call :ReadConfig Source!ind! source
call :ReadConfig OlderThan!ind! olderthan
echo Deleting files older than !olderthan! days with the file extension *.%extension% located at !source! >> %loglocation%
cd %source%
echo . >>%loglocation%
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation%
echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation%
echo Delete finished... >> %loglocation%
echo. >>%loglocation%
)

echo.
echo All Deletes complete.... >> %loglocation%
call :FreeSpace ExistFreeSpace>> %loglocation%
date /t >> %loglocation%
time /t >> %loglocation%
echo >>%loglocation%

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
)

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION
::@SETLOCAL ENABLEEXTENSIONS
@CLS

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!

@ECHO Total space: %TotalSpace%GB
@ECHO Free space: %FreeSpace%GB
@ECHO Used space: %TotalUsed%GB
@ECHO Percent Used: %PercentUsed%%%
@ECHO Percent Free: %PercentFree%%%

::ENDLOCAL
ENDLOCAL &set "%~1=%PercentFree%"
goto :eof


Here it is! Please help me correct this.
Replace the Code: [Select]:: *** with Code: [Select]REM.



Sorry Patio, just had to..He's now been told 3 times... methinks this is going to go nowhere...
No problem MacDad...
2781.

Solve : MS Dos Bate File?

Answer»

These directories are only SET up on one test and one production server. We would like to have a job we can use to ALLOCATE these directories on a different server in case we would need to switch to a different server. Below is a list of the directories we would need. For each set of directories we would ALSO need the higher lever directory allocated, i.e.. For the MDMSPROJECT\PPL_BILL_REQUESTS\FAILED - LOADED - SQLLDR directories we would also have to have the MDMSPROJECT\PPL_BILL_REQUEST directory created first.

Help out Please? Advice &AMP; hints. :d

D:\MDMSPROJECT\PPL_BILL_REQUESTS\FAILED
D:\MDMSPROJECT\PPL_BILL_REQUESTS\LOADED
D:\MDMSPROJECT\PPL_BILL_REQUESTS\SQLLDR
D:\MDMSPROJECT\PPL_CSS_CUST_ACCT\EXCLUDE
D:\MDMSPROJECT\PPL_CSS_CUST_ACCT\FAILED
D:\MDMSPROJECT\PPL_CSS_CUST_ACCT\LOADED
D:\MDMSPROJECT\PPL_CSS_CUST_ACCT\SQLLDR
D:\MDMSPROJECT\PPL_CSS_METER\EXCLUDE
D:\MDMSPROJECT\PPL_CSS_METER\FAILED
D:\MDMSPROJECT\PPL_CSS_METER\LOADED
D:\MDMSPROJECT\PPL_CSS_METER\SQLLDR
D:\MDMSPROJECT\PPL_CSS_PREMISE\EXCLUDE
D:\MDMSPROJECT\PPL_CSS_PREMISE\FAILED
D:\MDMSPROJECT\PPL_CSS_PREMISE\LOADED
D:\MDMSPROJECT\PPL_CSS_PREMISE\SQLLDR
D:\MDMSPROJECT\PPL_DATA_TRANSFER\FAILED
D:\MDMSPROJECT\PPL_DATA_TRANSFER\LOADED
D:\MDMSPROJECT\PPL_LMPP_PRICE\FAILED
D:\MDMSPROJECT\PPL_LMPP_PRICE\LOADED
D:\MDMSPROJECT\PPL_LOADSTUDY_BILLING_TOTALIZATION_RESULTS\FAILED
D:\MDMSPROJECT\PPL_LOADSTUDY_BILLING_TOTALIZATION_RESULTS\LOADED
D:\MDMSPROJECT\PPL_MV90\FAILED
D:\MDMSPROJECT\PPL_MV90\INFO Files
D:\MDMSPROJECT\PPL_MV90\LOADED
D:\MDMSPROJECT\PPL_NYPA_GENERATION_DATA_LOAD\FAILED
D:\MDMSPROJECT\PPL_NYPA_GENERATION_DATA_LOAD\LOADED
D:\MDMSPROJECT\PPL_PJM_ZONAL_LOAD\FAILED
D:\MDMSPROJECT\PPL_PJM_ZONAL_LOAD\LOADED
D:\MDMSPROJECT\PPL_PRS_RTO_TOTALIZATION_RESULTS\FAILED
D:\MDMSPROJECT\PPL_PRS_RTO_TOTALIZATION_RESULTS\LOADED
D:\MDMSPROJECT\PPL_READS_ONLY_TNS_DAILY_SHIFT\FAILED
D:\MDMSPROJECT\PPL_READS_ONLY_TNS_DAILY_SHIFT\LOADED
D:\MDMSPROJECT\PPL_SHOPPER_TOTALIZATION_RESULTS\FAILED
D:\MDMSPROJECT\PPL_SHOPPER_TOTALIZATION_RESULTS\LOADED
D:\MDMSPROJECT\PPL_TNS_15_MIN\FAILED
D:\MDMSPROJECT\PPL_TNS_15_MIN\LOADED
D:\MDMSPROJECT\PPL_TNS_60_MIN\FAILED
D:\MDMSPROJECT\PPL_TNS_60_MIN\LOADED
D:\MDMSPROJECT\PPL_TNS_BLINK\FAILED
D:\MDMSPROJECT\PPL_TNS_BLINK\LOADED
D:\MDMSPROJECT\PPL_TNS_DAILY_SHIFT\FAILED
D:\MDMSPROJECT\PPL_TNS_DAILY_SHIFT\LOADED
D:\MDMSPROJECT\PPL_TNS_TAMPER\FAILED
D:\MDMSPROJECT\PPL_TNS_TAMPER\LOADED
D:\MDMSPROJECT\PPL_WEATHER\FAILED
D:\MDMSPROJECT\PPL_WEATHER\LOADED
D:\MDMSPROJECT\PPL_WEATHER_OUTPUT\FAILED
D:\MDMSPROJECT\PPL_WEATHER_OUTPUT\LOADED
D:\MDMSPROJECT\PPL_WV_SCADA\FAILED
D:\MDMSPROJECT\PPL_WV_SCADA\LOADED
D:\MDMSPROJECT\PPL_WV_SCADA\SQLLDR

2782.

Solve : Help with bcdedit, Adding Startup from WIM file?

Answer»

Hello

Im trying to EDIT my boot settings with bcdedit im trying to create a boot entry to my DEFAULT drive N: to a WIM FILE \boot\sources\boot.wim , to start the WINDOWS 7 recovery console disc that ive extracted from iso onto drive N: how can i do this ? im USING windows 7 professional x64 and a dual operating system with windows 7 ultimate x64

2783.

Solve : Batch file to split a string into multiple strings?

Answer»

Hi. I need a script that will take a string and split it up by " %% " with no quotes. It would be very easy if you could output them on different lines (displayed).

Thank you in advance.Please explain a bit more what you want, and preferably give an example of input and desired output.
I want so that when I input "Hello %% Person %%"(no quotes) , it would give me the following:
Hello
PersonWill there always be 2 names?
No. There is no way to tell.Is it possible to use VBScript?
I would prefer to have them as one file, but it is ok to use it.

Also, the input needs to come from the batch file.Batch script that creates and runs VBscript in same folder

Code: [Select]
@echo off
echo MyString=wscript.arguments(0)>splitter.vbs
echo MyArray = Split(MyString, "%%%%", -1, 1)>>splitter.vbs
echo last=UBound(MyArray)>>splitter.vbs
echo For j = 0 To last>>splitter.vbs
echo wscript.echo MyArray(j)>>splitter.vbs
echo Next>>splitter.vbs

REM Testing example string
REM note that a % SIGN is a control character in batch so needs to be escaped
REM by another % sign (i.e. doubled)

set Longstring=Cat%%%%Dog%%%%Horse%%%%BIRD%%%%Fish%%%%Chicken

for /f "delims=" %%A in ( 'cscript //nologo splitter.vbs "%Longstring%" ' ) do echo %%A


REM at end of batch (if desired)
DEL splitter.vbs
Thank you, but it just says "Echo is off".Quote from: flytothemoon on June 11, 2010, 01:41:07 PM

Thank you, but it just says "Echo is off".

I ran this batch file...

Code: [Select]@echo off
echo MyString=wscript.arguments(0)>splitter.vbs
echo MyArray = Split(MyString, "%%%%", -1, 1)>>splitter.vbs
echo last=UBound(MyArray)>>splitter.vbs
echo For j = 0 To last>>splitter.vbs
echo wscript.echo MyArray(j)>>splitter.vbs
echo Next>>splitter.vbs
set Longstring=Cat%%%%Dog%%%%Horse%%%%Bird%%%%Fish%%%%Chicken
echo Longstring=%Longstring%
for /f "delims=" %%A in ( 'cscript //nologo splitter.vbs "%Longstring%" ' ) do echo %%A
del splitter.vbs

and this was the output...

Code: [Select]Longstring=Cat%%Dog%%Horse%%Bird%%Fish%%Chicken
Cat
Dog
Horse
Bird
Fish
Chicken

If you will show me the code you have used I will try to advise. Where are you getting the long string from?


It changed on me. Now it is working. But one problem. I am getting the longstring from a file that I know exists (I entered the path in windows explorer) but it says the file is not found. Any ideas?Quote from: flytothemoon on June 11, 2010, 02:22:11 PM
Any ideas?

Be thorough and careful and check what you are doing.
2784.

Solve : Batch file write variables to file?

Answer»

Quote from: Linux711 on June 09, 2010, 07:21:57 PM

The problem is that it does not write the variables to the file. It only partially works when I remove the whole if statement. . I thought this was because I have a space before the >>, but when I remove the space it doesn't work at all. So can someone that understands this convoluted language HELP me figure this out?

There is no problem. A TRAILING space for a redirect ( >> )
does not CAUSE a problem. There is no need to remove
the trailing space. This complete thread is nonsense.


Quote from: marvinengland on June 11, 2010, 01:16:23 PM
This complete thread is nonsense.

The parts that you contributed are. Why don't you leave? Please.
Quote
There is no problem. A trailing space for a redirect ( >> )
does not cause a problem. There is no need to remove
the trailing space.

Don't you REALIZE that there might be something other than human eyes reading this file.



@BC_Programmer

Thank you. The escape ^ works. I adjusted the code a little. Removed the !in! !in2! !in3! and just made everything !in! because there is no point in using a new variable each time. I also fixed the file name issue.

Here is the final code. It works perfectly. No need for any more arguments.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /p yorn=Would you like to setup the server name etc.(y/n)?
if /i %yorn%==y (
set /p in=Maximum clients:
echo maxclients !in!> bla.cfg
set /p in=Bot limit:
echo serverbotlimit !in!>> bla.cfg
echo publicserver ^0>>bla.cfg
set /p in=Server title:
echo serverdesc "!in!">> bla.cfg
) else (
echo said no.
)

PS: Does anyone know how to mark resolved on this forum?Quote from: marvinengland on June 11, 2010, 01:16:23 PM
A trailing space for a redirect ( >> )
does not cause a problem. There is no need to remove
the trailing space.
@echo off
echo Comparing requires no trailing spaces > file.txt
set /p var=if not "Comparing requires no trailing spaces"=="%var%" echo FAIL!
pause

It is also affects FTP scripts, too. Just so you know.
2785.

Solve : i n33d h3lp w/ security batch?

Answer»

can someone help me with this?
i can't get it to work...

Code: [Select]@echo off
color 02
title Security
set files=0
set eliminated=0
set unable=0
cd C:\DOCUME~1\UBERHA~1\STARTM~1\PROGRAMS\STARTUP
for %%a in (*.bat) do (
SET /A files=%files%+1 &
if %%a==security.bat set clear=yes &
if %%a==ubermegasuperstartup.bat set clear=yes &
echo %%a &
if not %clear%==yes set /p acceptable= is this file accepted? : &
if %acceptable%==no del /f /q %%a &
if %acceptable%==n del /f /q %%a &
if %acceptable%==N del /f /q %%a &
if %acceptable%==No del /f /q %%a &
if %acceptable%==NO del /f /q %%a &
if exist %%a (
if not %clear%==yes (
if not %acceptable%==yes (
cacls %%a /e /g %USERNAME%:F &
attrib -r -s -h %%a &
del /f /q %%a &
if not exist %%a (
echo file deleted (%%a) &
set eliminated=%eliminated%+1
) &
if exist %%a (
echo unable to delete file (%%a) &
set /a unable=%unable+1
)
)
)
)
)
pause
for %%b in (*.vbs) do (
set /a files=%files+1% &
echo %%b &
set /p acceptable= is this file accepted? : &
if %acceptable%==no del /f /q %%b &
if %acceptable%==n del /f /q %%b &
if %acceptable%==N del /f /q %%b &
if %acceptable%==No del /f /q %%b &
if %acceptable%==NO del /f /q %%b &
if exist %%b (
if not %acceptable%==yes (
cacls %%b /e /g %USERNAME%:F &
attrib -r -s -h %%b &
del /f /q %%b &
if not exist %%b (
echo file deleted (%%b) &
set eliminated=%eliminated%+1
)
if exist %%b (
echo unable to delete file (%%b) &
set unable=%unable%+1
)
)
) &
)
cd C:\DOCUME~1\ALLUSE~1\STARTM~1\PROGRAMS\STARTUP
for %%c in (*.bat) do (
set /a files=%files%+1 &
if %%c==security.bat set clear=yes &
if %%c==ubermegasuperstartup.bat set clear=yes &
echo %%c &
if not %clear%==yes set /p acceptable= is this file accepted? : &
if %acceptable%==no del /f /q %%c &
if %acceptable%==n del /f /q %%c &
if %acceptable%==N del /f /q %%c &
if %acceptable%==No del /f /q %%c &
if %acceptable%==NO del /f /q %%c &
if exist %%c (
if not %clear%==yes (
if not %acceptable%==yes (
cacls %%c /e /g %USERNAME%:F &
attrib -r -s -h %%c &
del /f /q %%c &
if not exist %%c (
echo file deleted (%%c) &
set /a eliminated=%eliminated%+1
)
if exist %%c (
echo unable to delete file (%%c) &
set /a unable=%unable%+1
)
)
)
) &
)
for %%d in (*.vbs) do (
set /a files=%files%+1 &
echo %%d &
set /p acceptable= is this file accepted? : &
if %acceptable%==no del /f /q %%d &
if %acceptable%==n del /f /q %%d &
if %acceptable%==N del /f /q %%d &
if %acceptable%==No del /f /q %%d &
if %acceptable%==NO del /f /q %%d &
if exist %%d (
if not %acceptable%==yes (
cacls %%d /e /g %USERNAME%:F &
attrib -r -s -h %%d &
del /f /q %%d &
if not exist %%d (
echo file deleted (%%d) &
set /a eliminated=%eliminated%+1
)
if exist %%d (
echo unable to delete file (%%d) &
set /a unable=%unable%+1
)
)
) &
)
cd C:\DOCUME~1\UBERHA~1\MYDOCU~1
echo Scanning Complete.
echo Number of files found:%files%
echo Number of files deleted:%eliminated%
echo Number of files that could not be deleted:%unable%
echo ---------------------------------------->>Securitylog.txt
echo %TIME% %DATE%>>Securitylog.txt
echo Scanning Complete.>>Securitylog.txt
echo Number of files found:%files%>>Securitylog.txt
echo Number of files deleted:%eliminated%>>Securitylog.txt
echo Number of files that could not be deleted:%unable%>>Securitylog.txt
pause

help plzzzzzzzzzzzzYuk.
Well, Well... We have someone trying to be smart and make a "virus"... Mate, don't post stuff LIKE that. You will just be ignored or your post will be removed

Merlynno this is kinda the opposite...Quote

cd C:\DOCUME~1\UBERHA~1\MYDOCU~1
echo Scanning Complete.
echo Number of files found:%files%
echo Number of files deleted:%eliminated%
echo Number of files that could not be deleted:%unable%
echo ---------------------------------------->>Securitylog.txt
echo %TIME% %DATE%>>Securitylog.txt
echo Scanning Complete.>>Securitylog.txt
echo Number of files found:%files%>>Securitylog.txt
echo Number of files deleted:%eliminated%>>Securitylog.txt
echo Number of files that could not be deleted:%unable%>>Securitylog.txt

Number of files found
Number of files deleted
Number of files that could not be deleted

Scary?Well, it appears as if it was intended to list batch and vbs scripts which are in various locations and ask the user if each is OK, and if the user says no, delete it. The trouble is that the OP wants a hundred-dollar batch script but only has fifty-cent programming ability.

Some advice: Indent your parenthetical STRUCTURES, learn about delayed expansion, learn when to use &. Start SIMPLE and work up to bigger and more complex scripts.

could you define:"delayed expansion"??and parenthetical structureQuote from: person1234 on June 22, 2010, 04:09:59 PM
could you define:"delayed expansion"??

expansion that occurs in a delayed fashion.

Quote from: person1234 on June 22, 2010, 05:40:31 PM
and parenthetical structure

a structure of a parenthetical nature.Quote from: BC_Programmer on June 22, 2010, 05:44:45 PM
expansion that occurs in a delayed fashion.

a structure of a parenthetical nature.
Because we know the OP n33ds h3lp w/ this INFORMATION I can see that you are trying to delete the files.

But, this is not a security breach or something.
However, let me know where would be the destination folder you are acting on?Quote from: vishuvishal on June 22, 2010, 06:30:12 PM
I can see that you are trying to delete the files.

But, this is not a security breach or something.
However, let me know where would be the destination folder you are acting on?
what's that mean??
Quote
However, let me know where would be the destination folder you are acting on?
the startup folder (C:\%USERPROFILE%\STARTM~1\PROGRAMS\STARTUP)
2786.

Solve : Network should return value?

Answer»

Hi folks,

I wondering if network COULD return value to my program.
If network become disconnected or no CONNECTIVITY it should return a value to my program.

Like if it is not there value for a = 0 or 1

However, I am thinking to ping the network default gateway.
And it destination host unreachable or time out comes start

Shutdown.exe -s

Thanks and regards
VishThis is the kind of question you could have tested from the command LINE and seen the results in action.

Code: [Select]@echo off
ping 192.168.2.1
if ERRORLEVEL 1 shutdown -s

Replace the IP address with your gateway IP.

Any reason you want to shutdown the machine if you can't reach the gateway? Couldn't you simply power cycle the device?

Just asking.

2787.

Solve : command line search and copy?

Answer»

Hey there.

This is my first post so I apologize ahead of time if I completely missed where someone might have asked a similar question. I've search but haven't really come up with results.

I work as a technical assistant at a small business doing general fixings on whatever needs to be done at the time. However, I am not a programmer. I can't really stress this enough to people. But, this time they want me to create a batch file that will do a search for any number of keywords, output it to a file, and then copy the results found in the file to specified location while preserving the file structure. I've got the searching done, i'm able to toss it out into a text file...

Problem comes when I'm told to copy the files specified in the results. I'm pretty much just stuck and got told to use robocopy.

I've posted what I have so far. If anyone has a recommendation I'd be more than happy to take anything into consideration. Again, programming, not something I do.

Finddata.txt is just a file listing search terms so the person using it can switch it up a bit.

@echo off

::Variables
set default=/s /i /m /g:finddata.txt

echo Welcome to the string search and copy batch!
echo.

REM This is to specify the queries and create an output file of results

set /p drive=Please specify the location of the search:

echo Searches are contained in the file finddata.txt. Make changes as necessary and save the text file.
@pause

findstr %default% %drive%\*.* > results.txt

results.txt

set /p answer=Would you like to perform a copy of the results now? (Y/N):

if %answer% == Y robocopy.exe
if %answer% == y robocopy.exe
if %answer% == N exit
if %answer% == n exitI admit I did not test this, so you get the honor.

Code: [Select]@echo off

set default=/s /i /m /g:finddata.txt

echo Welcome to the string search and copy batch!
echo.

REM This is to specify the queries and create an output file of results

set /p drive=Please specify the location of the search:

echo Searches are contained in the file finddata.txt. Make changes as necessary and save the text file.
pause

findstr %default% %drive%\*.* > results.txt

set /p answer=Would you like to perform a copy of the results now? (Y/N):

if /i %answer%==Y (
for /f tokens=* delims=" %%v in (results.txt) do robocopy.exe %%v %destination%
) else ( exit )

You mentioned that you get the results.txt file OK, so I just added some code after the findstr instruction. You will have to define or replace the %destination% variable with a drive:\path. Robocopy requires a souce and destination as a minimum. Why not use just plain copy?

Good luck. Using robocopy so I can preserve the structure of the folders. Not really sure how to accomplish the same thing with copy. In any case, THANKS for the added lines you gave me but it's not copying anything... as soon as I TYPE in "Y" it closes cmd and nothing happens.

Also, how do I exclude folders from a search, such as the system folder and program files? I can see where I can REMOVE them from the results after I copy them but I'm beginning to get some machines that error out when the file paths get too long (basically hidden files)I found a potential error which has been fixed. There was also a problem (fixed) with the for LOOP which threw an error. That was an important piece information to know.

Code: [Select]@echo off

set default=/s /i /m /g:finddata.txt

echo Welcome to the string search and copy batch!
echo.

REM This is to specify the queries and create an output file of results

set /p drive=Please specify the location of the search:

echo Searches are contained in the file finddata.txt. Make changes as necessary and save the text file.
pause

findstr %default% %drive%\*.* > results.txt

set /p answer=Would you like to perform a copy of the results now? (Y/N):

if /i .%answer%==.Y (
for /f "tokens=* delims=" %%v in (results.txt) do robocopy.exe "%%v" %destination%
)
exit

You're right, COPY will not meet your needs. XCOPY can keep the directory structure and you can use an exclude file for filtering out program files and switches for ignoring system files/folders. ROBOCOPY is also an option. Both XCOPY and ROBOCOPY have a truckload of options. Type XCOPY /? or ROBOCOPY /? at a command prompt and pick your poison.

Good luck.

2788.

Solve : ver in ver?

Answer»

how do i GET the echo command in this FILE to work
:a
set a1=a
set a2=b
set a3=c
set a4=d
set a5=e
set /p b=1-5:
echo %a%b%%
goto a
(note this is just an example so don't tell me to use
:a
set /p b=1-5:
if %b%=1 echo a
if %b%=2 echo b
if %b%=3 echo c
if %b%=4 echo d
if %b%=5 echo e
goto a
)
Quote from: mat123 on June 11, 2010, 06:48:23 PM

how do i get the echo command in this file to work
:a
set a1=a
set a2=b
set a3=c
set a4=d
set a5=e
set /p b=1-5:
echo %a%b%%
goto a
(note this is just an example so don't tell me to use
:a
set /p b=1-5:
if %b%=1 echo a
if %b%=2 echo b
if %b%=3 echo c
if %b%=4 echo d
if %b%=5 echo e
goto a
)

What are you trying to accomplish?

echo %a%%b%

will echo whatever the contents of %a% and %b% on the screen.Quote
echo %a%b%%

The syntax of the command is incorrect.
Try echo %a%%b%

But the environment variables a thru' e haven't been set so how can they be echo'd?

desired
make the ver b=1
echo %a%b%%
ver b expands first making it
echo %a1%
which is aQuote from: mat123 on June 11, 2010, 08:35:40 PM
desired
make the ver b=1
echo %a%b%%
ver b expands first making it
echo %a1%
which is a

This will make it clear. Batch language does not have arrays, and since variables are expanded at parse time, it is necessary to use call to echo the created variable in a new process, doubling % or ! characters as necessary.

Code: [Select]@echo off
:a
set a1=a
set a2=b
set a3=c
set a4=d
set a5=e
set /p b=1-5:
echo 1 %%a%b%%%
call echo 2 %%a%b%%%
goto a
Code: [Select]1-5:1
1 %a1%
2 a
1-5:2
1 %a2%
2 b
1-5:3
1 %a3%
2 c
1-5:4
1 %a4%
2 d
1-5:5
1 %a5%
2 e
1-5:
I figured out a way a couple years back, and used it in a simulation game. Anyway, look at the code, specifically what I highlighted:

@echo off
Echo Coin flipper
pause > nul
set t1g4=0
set t1g5=0
set t1g6=0
set t1g7=0
set t2g4=0
set t2g5=0
set t2g6=0
set t2g7=0
cls
:begin
set /a scriptcount+=1
set /a rnd=%random%%%2
set /a gc+=1
if %rnd% equ 1 (set /a t1+=1) else (set /a t2+=1)
if "%t1%"=="4" set t1=0 & set t2=0 & set /a t1g%gc%+=1 & set gc=0
if "%t2%"=="4" set t1=0 & set t2=0 & set /a t2g%gc%+=1 & set gc=0
set /a total1=%t1g4%+%t1g5%+%t1g6%+%t1g7%
set /a total2=%t2g4%+%t2g5%+%t2g6%+%t2g7%
cls
echo Team 1 Wins: %t1%
echo Team 2 Wins: %t2%
echo -----
echo Amount of games it took to win series:
echo -----
echo Team 1 4 Games: %t1g4%
echo Team 1 5 Games: %t1g5%
echo Team 1 6 Games: %t1g6%
echo Team 1 7 Games: %t1g7%
echo -----
echo Team 2 4 Games: %t2g4%
echo Team 2 5 Games: %t2g5%
echo Team 2 6 Games: %t2g6%
echo Team 2 7 Games: %t2g7%
set /a total=%total1%+%total2%
if %total%==1000 goto done
goto begin
:done
pause > nulQuote from: Helpmeh on June 12, 2010, 07:51:26 PM
look at the code, specifically what I highlighted:

So how do we use that to do what the OP asks? Because I can't get it to work without doubling up the % signs, and using CALL.
Use the set command to make a new variable who's NAME contains the other variables.what i REALLY need it for is if statments
example

set a=1
:a
if %b%==5 goto b
set /a r%a%=%random% %%5
if %r%a%%==1 set b=a
if %r%a%%==2 set b=b
if %r%a%%==3 set b=c
if %r%a%%==4 set b=d
if %r%a%%==5 set b=e
set /a a=%a%+1
goto a
echo %r1% %r2% %r3% %r4% %r5% Quote from: Helpmeh on June 13, 2010, 06:34:49 AM
Use the set command to make a new variable who's name contains the other variables.

I see, you are using the fact that set /a does not need percent signs on the variable name on the left hand side of the equals sign. But if you aren't using numbers, you have to use call and the doubled percent signs I posted above.


2789.

Solve : MS Dos Deletes files from the directories on one of the servers?

Answer»

NEED HELP! This is the commands i have:



ECHO OFF
set ConfigFile=config.cfg
set loglocation=d:\PPLSCRIPTS\PPL_LOGS\MDMLog%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt
set AlertEmail=D:\PPLSCRIPTS\AlertEmail.txt
set wmailto=c:\windows\wmailto.exe
set "ExistFreeSpace=0"

echo Job starting.... >> %loglocation%
date /t >> %loglocation%
time /t >> %loglocation%

:: ** echo CALLING MDMcreateCSVfiles bat file.... >> %loglocation%
:: ** Call MDMcreateCSVfiles
:: ** echo Returned from bat file call - continuing.... >> %loglocation%

:: ***Check if config file is there
if not exist %ConfigFile% (
echo UNABLE TO FIND THE CONFIG FILE - %ConfigFile% , used the delete the logs on MDM server. The file has been re-named or deleted. >>%loglocation%
%wmailto% -t%loglocation% %email% "-s Config file is missing"
goto :eof
)

:: *** Call the subroutine;
:: *** first argument: the name of the var in the config file to look for
:: *** second argument: the batch variable that should have the value assigned.
call :ReadConfig TotalDirs TotalNo
call :ReadConfig email email
call :ReadConfig Warningemail Warningemail
call :ReadConfig extension extension
call :ReadConfig MinFreeSpacePrcnt MinFreeSpace

echo Log space on server.... >> %loglocation%
call :FreeSpace ExistFreeSpace >> %loglocation%

setlocal EnableDelayedExpansion
FOR /L %%i IN (1,1,%TotalNo%) DO (
SET ind=%%i
call :ReadConfig Source!ind! source
call :ReadConfig OlderThan!ind! olderthan
echo Deleting files older than !olderthan! DAYS with the file extension *.%extension% located at !source! >> %loglocation%
cd %source%
echo . >>%loglocation%
::FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C Echo "@FILE" >> %loglocation%
echo Starting delete... >> %loglocation%
FORFILES -p !source! -d -!olderthan! -m *.%extension% -c "CMD /C del !source!\@FILE /q & echo !source!\@FILE deleted." >> %loglocation%
echo Delete finished... >> %loglocation%
echo. >>%loglocation%
)

echo.
echo All Deletes complete.... >> %loglocation%
call :FreeSpace ExistFreeSpace>> %loglocation%
date /t >> %loglocation%
time /t >> %loglocation%
echo >>%loglocation%

if %ExistFreeSpace% leq %MinFreeSpace% (
echo Existing free space is at %ExistFreeSpace% percent. This is less than %MinFreeSpace% percent set as the min required free space. >> %loglocation%
%wmailto% -t%AlertEmail% %Warningemail% "-s Job MDMServerSpace: Not enough disk space on MDM server"
)

%wmailto% -t%loglocation% %email% "-s Files deleted on MDM server"
goto :eof

:: **** Subroutines start here; no changes below this line ******
:ReadConfig
for /f "tokens=2 delims==" %%a in ('type "%ConfigFile%" ^| find /i "%~1="') do set %2=%%a
goto :eof

:FreeSpace
@SETLOCAL ENABLEDELAYEDEXPANSION
::@SETLOCAL ENABLEEXTENSIONS
@CLS

@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "D:""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!

@ECHO TOTAL space: %TotalSpace%GB
@ECHO Free space: %FreeSpace%GB
@ECHO Used space: %TotalUsed%GB
@ECHO Percent Used: %PercentUsed%%%
@ECHO Percent Free: %PercentFree%%%

::ENDLOCAL
ENDLOCAL &set "%~1=%PercentFree%"
goto :eof
2790.

Solve : batch job to show files from network folders from today and yeasterday?

Answer»

Hi

I need some kind of batch script which I can run everyday to check what kind of new files we have in network folders. I should be able to see *.xml files only from today and yesterday (without deleting OLDER files - we have to keep all files as history) The best if serch results can be moved to txt file with current date and time as a name.
Is possible to prepare such script?

I was thinking to use dir /b but I do not know how to specify serch results, can you help?
Do you know how to prepare such stript??

If you can help would I really appreciate that.

Thank you in advance.

BR
RafalQuote from: silberzin on June 02, 2010, 03:25:28 AM



The best if serch results can be moved to txt file with current date and time as a name.
Is possible to prepare such script?

I was thinking to use dir /b but I do not know how to specify serch results, can you help?
Do you know how to prepare such stript??



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

for /f "delims=" %%i in ('cscript //nologo c:\test\evaluate.vbs "date -1"' ) do (
set yesterday=%%i
)

for /f "tokens=1,2,3,4 delims=/ " %%a in ("%yesterday%") do set wday=null&set month=%%a&set day=%%b&set year=%%c
if %month% LSS 10 set month=0%month%
if %day% LSS 10 set day=0%day%
set yesterday=%month%/%day%/%year%
echo yesterday=%yesterday%

set Today=%DATE%
set Today=%DATE:~4,10%

echo Today=%Today%

dir /OD /A-D | findstr "%yesterday% %Today%"

rem evaluate.vbs furnished by Salmon Trout
rem evaluate.vbs
rem Wscript.echo eval(WScript.Arguments(0))
Output:

C:\test>yesterdayfiles.bat
yesterday=06/08/2010
Today=06/09/2010
06/08/2010 02:46 AM 7 seq.txt
06/08/2010 07:04 PM 8 text1.txt
06/08/2010 07:04 PM 8 text2.txt
06/08/2010 07:04 PM 8 text3.txt
06/08/2010 07:37 PM 379 sw68.bat
06/08/2010 08:10 PM 10 text4.txt
06/08/2010 08:12 PM 339 sw268.bat
06/08/2010 08:59 PM 81 text.txt
06/08/2010 09:34 PM 323 sw4.bat
06/09/2010 08:14 AM 369 sw69.bat
06/09/2010 11:07 AM 184 yesterday.bat
06/09/2010 11:11 AM 3 filecount.txt
06/09/2010 01:11 PM 563 yesterdayfiles.bat
C:\test>Hi

Thank you very much for replay.

I would like to ask you when I run it I have info:
-------------------------------------------
yesterday=Input/Error:/Can
Today=-06-10
2010-06-10 14:08 603 check files in ready_staying too long.bat
----------------------------

Do you know what can be the reason?
I also do not know from where to take: evaluate.vbs - it is in your script.

Many thanks for your replay

BR
RafalAlmost certainly something to do with the date format!

Remove the @Echo Off from the top and the commands being processed will be SEEN, not just the error.

Note that Marvin's example expects US date formats, you appear to be using military format - you will need to change the order of assignments of day, month and year values to match your locale

GrahamQuote from: silberzin on June 02, 2010, 03:25:28 AM

I need some kind of batch script which I can run everyday to check what kind of new files we have in network folders. I should be able to see *.xml files only from today and yesterday.

Sib,

Gpl is correct. We need the date format for files on your machine.

cd to the directory you are working with.


C:\>cd c:\test\

c:\test>

Do a dir /OD *.xml and | pipe to more. Copy and paste part of that page here.

For example:

C:\test>dir /OD *.bat | more
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test

04/24/2010 02:39 PM 1,018 x.bat
04/24/2010 02:39 PM 1,018 buildlog.bat
04/24/2010 06:37 PM 199 matt.bat
04/25/2010 11:27 AM 260 matt5.bat
04/25/2010 11:27 AM 260 matt2.bat
04/25/2010 11:34 AM 307 matt3.bat
04/25/2010 11:41 AM 224 matt4.bat
04/25/2010 02:17 PM 125 ver61.bat
04/25/2010 02:33 PM 190 ver612.bat
04/25/2010 05:14 PM 235 helpme.bat
04/27/2010 12:06 PM 32 chtoE.bat
04/27/2010 07:33 PM 89 fil.bat
04/27/2010 09:52 PM 631 cmpfil.bat
04/27/2010 10:18 PM 698 cmplist.bat
05/05/2010 04:52 PM 192 filefromstr.bat
05/06/2010 12:37 PM 199 hannes.bat
05/06/2010 01:06 PM 194 erasedir.bat
05/07/2010 10:57 AM 229 sw57.bat
05/07/2010 02:16 PM 85 sw58.bat
-- More --

also do an echo %DATE%

c:\test>echo %DATE%
Thu 06/10/2010

c:\test>

Create a test directory and copy about 30 of the files you are concerned with. Don't run the code on the large folders until the code is working correctly.

( Forget the vbs code for finding yesterday's date. Enter yesterday's date manually until everything else works. We can find an easier way to find yesterday's date later. ( Or Salmon Trout might show you how to set up the vbs code later. ))

Good LuckQuote from: silberzin on June 02, 2010, 03:25:28 AM


I need some kind of batch script which I can run everyday to check what kind of new files we have in network folders. I should be able to see *.xml files only from today and yesterday

The copy and paste from the command window is different than from a web page or word processor.

1) Right click the bar in an open spot at the top just left of the red X. A dropdown MENU will indicate choices:

Quote from: silberzin on June 10, 2010, 06:04:32 AM
yesterday=Input/Error:/Can
Today=-06-10
2010-06-10 14:08
Do you know what can be the reason?

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

rem dir /OD /A-D > dateformat.txt

set Yesterday=2010-06-10
set Today=2010-06-11

echo Yesterday=%Yesterday%
echo Today=%Today%

findstr "%Yesterday% %Today%" dateformat.txt
C:\test>dayfiles.bat
Yesterday=2010-06-10
Today=2010-06-11
2010-06-10 12:17 PM 3,173 srcfiles.txt
2010-06-10 03:31 PM 2 bla.cfn
2010-06-11 03:48 AM 17 bla1.txt
2010-06-11 03:48 AM 16 bla2.txt
2010-06-11 01:37 PM 1,624 redirect.bat
2010-06-11 06:09 PM 413 sib611.bat
2010-06-11 06:24 PM 959 yesterdayfiles.bat
C:\test>Quote from: silberzin on June 10, 2010, 06:04:32 AM

yesterday=Input/Error:/Can
Today=-06-10
2010-06-10 14:08


C:\test>type dayfiles.bat
Code: [Select]@echo off
rem This program will run automatically at 11:30pm everyday

dir /OD /A-D > dateformat.txt

dir /OD /A-D > Fdateformat.txt

set /p Yesterday=<yesterday.txt


for /f "tokens=1,2,3,4 delims=/ " %%a in ("%DATE%") do (
set wday=null&set month=%%b&set day=%%c&set year=%%d
set Today=%month%/%day%/%year%

set Ftoday=%year%-%month%-%day%
)

echo Yesterday=%Yesterday%
echo Today=%Today%
echo Ftoday=%Ftoday%

findstr "%Yesterday% %Today%" dateformat.txt

rem echo %Today% > yesterday.txt
rem remove "rem" when the program is set to run automatically at 11:30 pm
Output:

C:\test>dayfiles.bat
Yesterday=06/11/2010
Today=06/12/2010
Ftoday=2010-06-12
06/11/2010 03:48 AM 17 bla1.txt
06/11/2010 03:48 AM 16 bla2.txt
06/11/2010 01:37 PM 1,624 redirect.bat
06/11/2010 06:09 PM 413 sib611.bat
06/11/2010 09:10 PM 285 trail.bat
06/11/2010 09:13 PM 39 filehel.txt
06/12/2010 07:23 PM 509 yesterdayfiles.bat
06/12/2010 07:33 PM 14 yesterday.txt
06/12/2010 08:01 PM 7,146 Fdateformat.txt
06/12/2010 08:06 PM 602 dayfiles.bat
06/12/2010 08:07 PM 0 dateformat.txt

C:\test>Hi

Thank you very much for all your replay. I have a filling that I am close to have solution but unfortunatelly I got lost

Is possible for you to publish full code which I should use ??

We would like to schedule this code to be run automatic on one of my colleagues machine, therefore the best is if this program do not require any manual entry and show results on screen + create txt log. Hope that is possible to make

Thank you in advance for help

BR
RafalQuote from: silberzin on June 14, 2010, 12:12:37 AM


Is possible for you to publish full code which I should use?


I don't know the date format for your files. The following method for finding yesterday's date is not as good as the Salmon Trout method furnished above.
But the vbs code was difficult to follow.


C:\test>type fday.bat
Code: [Select]@echo off
echo 2010-06-13 > yesterday.txt
rem remove above line after test phase
dir /OD /A-D > dateformat.txt

set /p Yesterday=<yesterday.txt




for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do set wday=%%a&set month=%%b&set day=%%c&set year=%%d
echo.Weekday: %wday%
echo.Month : %month%
echo.Day : %day%
echo.Year : %year%

set Today=%year%-%month%-%day%

echo Yesterday=%Yesterday%
echo Today=%Today%

findstr "%Yesterday% %Today%" dateformat.txt

echo %Today% > yesterday.txt
rem only do the above at 11:30 pm
Output:

C:\test>fday.bat
Weekday: Mon
Month : 06
Day : 14
Year : 2010
Yesterday=2010-06-13
Today=2010-06-14
2010-06-13 07:23 PM 509 yesterdayfiles.bat
2010-06-13 10:10 PM 722 dayfiles.bat
2010-06-13 10:10 PM 7,146 Fdateformat.txt
2010-06-14 01:05 PM 448 fday.bat
2010-06-14 01:08 PM 10 yesterday.txt
2010-06-14 01:23 PM 0 dateformat.txt

C:\test>Quote from: silberzin on June 14, 2010, 12:12:37 AM
Is possible for you to publish full code which I should use?




C:\test>schtasks /create /SC DAILY /TN test1 /TR c:\test\date.bat /ST 19:35
SUCCESS: The scheduled task "test1" has successfully been created.

C:\test>type yesterday.txt
The system cannot find the file specified.

C:\test>type yesterday.txt
06/14/2010

C:\test>dir /OD yesterday.txt
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test

06/14/2010 07:35 PM 12 yesterday.txt
1 File(s) 12 bytes
0 Dir(s) 295,454,244,864 bytes free

C:\test>

Use 23:30 not 19:35
2791.

Solve : xcopy without replacement?

Answer»

I'm trying to write a .bat file (I just started learning msdos and scripting tonight so bear with me) that will backup/copy any new files placed on my jump DRIVE onto my home computer. To do this, right now I'm just running a xcopy command from the command line. However, is there a switch that will tell dos not to copy if the file already EXISTS and hasn't been modified? I was able to copy all the files, but I thought it might be time consuming if everytime I plug it in it has to copy the ENTIRE jump drive, instead of the new files.

/U seems to have exactly what I NEED, just opposite

Thanks for any help
Have a look at the Xcopy /M switch.

Hope this helps.That didn't seem to work, it still asks me if I'd like to overwrite the file, which I don't. Right now I'm using this as the script, which gets the job done, it just takes about 2 MINUTES to sync everything up.

@echo off
xcopy e:\jumpdrive c:\documents /s /m
xcopy c:\documents e:\jumpdrive /s /m

I'd like it to only copy new files, instead of copying 533 files (last run) each time it executes. The switch /y seems like it should work, but it tells it to overwrite it, which is opposite of what I actually want also.Figured it out. If you use the switch /d without a date specified, it will copy only files that have changed at some point. Works perfectly now.

2792.

Solve : matrix effect.?

Answer»

Hi folks (experts)

Actually i am trying to show some matrix effect.

I have done with the help of few coding but need same effect.

@echo off
:1
type effect.txt
color 2
goto:1

Actually i want to use some good animation character or square block like USED in film .

I want to make it startup
i know that we can KEEP the file in startup FOLDER for it.
But, need a better suggestion.
And can we make is .scr (screen saver)


I know you know all these stuff or can FIGURE out.

Thanks vishu
http://download.cnet.com/The-Matrix-Screen-Saver/3000-2257_4-10067722.htmlThanks folk but, I am not able to view that linkWhat do you mean? What browser?

2793.

Solve : Run Dialup Networking Using Batch File?

Answer»

Hi, I need help, please

How to :
- I want to running or start dial up networking using batch FILE
- DISCONNECTED the dial up networking using batch file

Thanks

This can be done using rasdial, EXAMPLE:


rasdial entryname /DISCONNECT
rasdial entryname USERNAME password* /phone:1888yourisp


entry name is the name of the actual connectionThanks, For your help

it's working

2794.

Solve : Save folder with date?

Answer»

here's the code... but the question is...
what if i back-up the folder at the same date?


@ECHO OFF
echo Y | xcopy /e D:\APPS\RBA-VRSN.330\*.* C:\BACK-UP\RECENT-BK-UP\*.*>NUL
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "C:\BACK-UP\RECENT-BK-UP" %%e-%%f-%%g
exit



what I want is SOMETHING like this...
let's say 06-04-2010 already exist and I back-up at the same date...
then I want to rename "RECENT-BK-UP" TO 06-04-2010.a or if exist
06-04-2010.b or if exist
06-04-2010.c or if exist
06-04-2010.d and so on...

thanks in advance!

Quote from: night-rider on June 04, 2010, 09:19:05 PM


What if I back-up the folder at the same date?


@ECHO OFF
echo Y | xcopy /e D:\APPS\RBA-VRSN.330\*.* C:\BACK-UP\RECENT-BK-UP\*.*>NUL
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "C:\BACK-UP\RECENT-BK-UP" %%e-%%f-%%g
exit


Use a UNIQUE sequence number. A number will work better than a,b,c ...


C:\test>type nightrider.bat

Code: [Select]@ECHO OFF
setlocal enabledelayedexpansion
cd C:\test\
type c:\test\backseq.txt
SET /p backseq=<backseq.txt
echo backseq=%backseq%

xcopy c:\test\*.txt C:\backup\recent\*.*> nul

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do (
set /a backseq=!backseq! + 1
echo backseq=!backseq!
md c:\backup\%%e-%%f-%%g%-!backseq!
set newdir=%%e-%%f-%%g%-!backseq!
copy c:\backup\recent\ c:\backup\!newdir!\>nul
echo Y | rd /s C:\backup\recent\
echo !backseq! > backseq.txt
)

cd c:\backup
dir
Output:

C:\test>nightrider.bat
27
backseq=27
backseq=28
C:\backup\recent\, Are you sure (Y/N)? Y
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of c:\backup

06/15/2010 06:29 PM .
06/15/2010 06:29 PM ..
06/15/2010 06:14 PM 06-15-2010-23
06/15/2010 06:17 PM 06-15-2010-24
06/15/2010 06:17 PM 06-15-2010-25
06/15/2010 06:21 PM 06-15-2010-26
06/15/2010 06:22 PM 06-15-2010-27
06/15/2010 06:29 PM 06-15-2010-28
0 File(s) 0 bytes
8 Dir(s) 295,186,542,592 bytes free
C:\test>Quote from: night-rider on June 04, 2010, 09:19:05 PM
What if back-up the folder at the same date?


@ECHO OFF
echo Y | xcopy /e D:\APPS\RBA-VRSN.330\*.* C:\BACK-UP\RECENT-BK-UP\*.*>NUL
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "C:\BACK-UP\RECENT-BK-UP" %%e-%%f-%%g



We may also use time /t instead of sequence number


C:\test>type nnrider.bat
Code: [Select]@ECHO OFF
setlocal enabledelayedexpansion
cd C:\test\
time /t > ftime.txt
set /p ftime=<ftime.txt

set ftime=%ftime::=%
echo.%ftime%
echo ftime=%ftime%

set ftime=%ftime:~0,4%
echo ftime=%ftime%

xcopy c:\test\*.txt C:\backup\recent\*.*> nul

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do (

md c:\backup\%%e-%%f-%%g%-!ftime!
set newdir=%%e-%%f-%%g%-!ftime!
copy c:\backup\recent\ c:\backup\!newdir!\>nul
echo Y | rd /s C:\backup\recent\
)

cd c:\backup
dir
Output:

C:\test>nnrider.bat
0832 AM
ftime=0832 AM
ftime=0832
C:\backup\recent\, Are you sure (Y/N)? Y
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of c:\backup

06/16/2010 08:32 AM .
06/16/2010 08:32 AM ..
06/16/2010 07:45 AM 06-16-2010-0745
06/16/2010 07:52 AM 06-16-2010-0752
06/16/2010 07:54 AM 06-16-2010-0754
06/16/2010 08:05 AM 06-16-2010-0805
06/16/2010 08:08 AM 06-16-2010-0808
06/16/2010 08:24 AM 06-16-2010-0824
06/16/2010 08:26 AM 06-16-2010-0826
06/16/2010 08:32 AM 06-16-2010-0832
0 File(s) 0 bytes
10 Dir(s) 294,352,437,248 bytes free

C:\test>
2795.

Solve : Batch help: run script only for specific folder?

Answer»

Hello all. NEED some help.

I wrote a script that calls an EXE to do its stuff. So far so good.
Now I tried (without success) to modify the script so that I can place it into the windows SendTo FOLDER and right-click it - by that I mean I wnat to select one or many files from a folder and then right-click to call my script to do its stuff.
The PROBLEM: I can't get to assign into the script a way to acquire the PATH of the SELECTED files and run the exe only for THOSE selected files.

When I run it runs for all the root folder, recursively.

I am trying something like this:

Code: [Select]for /R %%i in (*.*) do exce

of course, that is the main loop through the files, but it doesn't work "on-the-fly", but rather only if I tell the script which folder (set folder=c:\...\blah\...\bla\...).

Any light on this??

Thanks!I apparently solved this with a simple line: CD %~dp1

BUT THEN:::::: if I highlighted more than 23 files and right-click in my bat (located in the SendTo folder) I get the following error message, something like this because I run windows in a language other than ENGLISH: "Windows cannot access the device, path or file you specifies. Maybe you do not have the permissions to acess the item."

What the heck does that mean?? and how to get around it?? ;(

2796.

Solve : how to make batch file for all files in faster way?

Answer»

i got 10 TEST files to send over lpt1 (copy 1.txt lpt1)
any better WAY to buld a BATCH file quickly?
because the files name always different and copy /paast those name really consume lots of time<<<" Igot 10 test files to send over lpt1 (copy 1.txt lpt1)
any better way to buld a batch file quickly?
because the files name always different and copy /paast those name really consume lots of time">>

Code: [Select]@echo off
dir /B *.txt > cpfiles.txt

for /f "delims=" %%i in (cpfiles.txt ) do copy %%i lpt1
I have not tested the above code.

Look at for /? for more options.

good luck

if dir /b *.txt > cpfiles.txt gives more files than needed try:

echo 1.txt > cpfiles.txt
echo 2.txt >> cpfiles.txt
.
.
.
Then the above for loop

2797.

Solve : Running Shortcut in batch File?

Answer»

Hi, I need help, please

I want to running shortcut (the name file with extension lnk) in batch file
So If I run the batch file, the script will be call the shortcut like example i want to run winzip.lnk (not exe file)

thanksPath-to-file\winzip.lnk



Quote from: T.C. on June 14, 2010, 05:06:35 PM

Path-to-file\winzip.lnk





Thanks T.C

That's already tested but not working Try this:
rundll32 shell32.dll,ShellExec_RunDLL "C:\YOURSHORTCUTHERE.lnk"
or if it's a web shortcut, replace .lnk with .url .Quote from: djj99 on June 14, 2010, 07:20:47 PM
That's already tested but not working

Please explain what happens when you try it, post your script.

Quote from: T.C. on June 14, 2010, 07:33:38 PM
Please explain what happens when you try it, post your script.



Thanks T.C
the error same (see below)

Quote from: Helpmeh on June 14, 2010, 07:28:22 PM
Try this:
rundll32 shell32.dll,ShellExec_RunDLL "C:\YOURSHORTCUTHERE.lnk"
or if it's a web shortcut, replace .lnk with .url .

thanks helpmeh
I already tested and still not working
The error SAID " windows cannot open this file : YOURSHORTCUTHERE.lnk "



Please help me

when T.C said:

Quote
Path-to-file\winzip.lnk


you'll notice that you probably don't have a folder called "path-to-file" and that your winzip.lnk is certainly not in it. additionally, when Helpmeh said

Quote
YOURSHORTCUTHERE.lnk

he actually meant for you to put your shortcut's name there.

Short story: you can run a lnk/shortcut just as easily as you can a executable. just type the name.Here's ANOTHER example. When running as Administrator I have a shortcut to Winzip.exe on my desktop. To access the file Winzip.lnk in a batch script I would use:

"c:\documents and settings\administrator\desktop\Winzip.lnk"

where c:\documents and settings\administrator\desktop\ is the path-to-file and winzip.lnk is the filename of the shortcut to Winzip.exe.

The " " are necessary as there are spaces in the path, standard requirement of the command shell.Quote from: djj99 on June 14, 2010, 09:24:21 PM
The error said " windows cannot open this file : YOURSHORTCUTHERE.lnk "

Now I put the shortcut in drive c in root

and I put the screen capture the error message

[recovering disk space - OLD attachment deleted by admin]Did you create a new file and forced it to have a .lnk extension, or did you properly create a new shortcut?Djj99 - How did you create this shortcut? Did you right click the Winzip.exe file and use SEND To Desktop (Create Shortcut) or Create Shortcut then COPY it to the root of C: or right click on a space on the desktop and create your own shortcut manually or open C: and create a new shortcut there??

No-one has reported any problems in creating or executing shortcuts so what procedure are you using to create them?

If you really want help you have to tell us what you are doing...


Have you read this or any of these?
2798.

Solve : Result of batch file execution?

Answer»

Hi all,

I want to know how to determine the result of batch FILE execution. whether the batch file EXECUTED correctly or not. i mean fi the batch file has to START some PROCESS, how can we ENSURE the process is started.
Your guidance will be very helpful.

Regards,
Prasad

2799.

Solve : remove empty subfolders?

Answer»

I have a main folder called : basic and under it are subfolders 1, 2, 3. What I would like to do is remove all the subfolders under "basic" that are empty. Is there are batchfile command that can do this? I've tried: rd c:\basic /s but that removes even "basic".Is this an exercise? Is this needed often?
Why don't you like empty folders?
at the command line type
xcopy /?
Or look HERE

If can copy files and directories and ignore empty directories.

Quote from: pearlyshells on June 21, 2010, 11:57:20 AM

I have a main folder called : basic and under it are subfolders 1, 2, 3. What I would like to do is remove all the subfolders under "basic" that are empty. Is there are batchfile command that can do this? I've tried: rd c:\basic /s but that removes even "basic".

rd /s basic is the secret. Then make new basic directory. md basic

C:\>rd /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.

/Q Quiet mode, do not ask if ok to remove a directory tree with /S

C:\>rd /S basicthis would be a daily routine task so I prefer not to leave the empty folders there. It is part of a backup routine that backs up folders and files to a central repository and then another application moves it directly to tape. So, every night, a new folder is created. When the tape move OCCURS the files are purged but the folder remains..

I see the second replies suggestion is to remove the entire folder including basic with the RD command and then in the batchfile force the creation of another Basic folder. I thought of that earlier but thought there might be another command that would not require me to recreate the BASIC folder again.

ThanksThis may help.

Code: [Select]@echo off
pushd c:\basic

for /r %%r in (.) do (
DIR /b "%%r" | find /v "" > nul && echo %%r NOT empty || rd %%r && echo %%r IS empty...DELETED
)

popd

You may have to change c:\basic to the correct path.If the subfolders are ALWAYS just 1 LEVEL down from the folder called basic then a simple script like this should do the trick, run from the basic folder

Code: [Select]@echo off
echo Remove empty folders
echo Press a key to start...
pause>nul
for /f "delims=" %%D in ('dir /b /ad') do (
dir "%%D" | find "0 File(s)">nul && (
rd "%%D" && echo Removed empty directory: %%D
)
)
echo Finished
echo Press a key to quit...
pause>nul

it worked. the folders that were not empty stayed and those that were are GONE. Many , many thanks.
2800.

Solve : Limit of number of files for which a Batch script will run onto???

Answer»

Hi all.

So, I wrote a batch that runs another exe to do stuff with other files. I copied this SCRIPT to the Windows\SendTo fodler, so I can activate my batch wherever I am, right-clicking on one or many files and then on my batch.

It WORKS in practice, BUT only up to 23 files! If I click on 24 files and then run the batch script it pops up a message saying "Windows cannot access teh device, path ou file you want. Maybe you don't have permission to access such file"

Any ideas???

tnksThere is a MAXIMUM number of file names you can use with Send To. It is much greater than 23 however. I just send 100 filenames to this batch file via Send To

Code: [Select]@echo off
echo %*
pause

But the message suggests you need to SORT out your file and folder permissions.




I hope there is something missing. However, I used many times.

It runs the batch file as a program.
That executes and terminates immediately

Once, you call the exe file on the location. It runs that. I mean batch calls.

So, it should work all the while.Hey vishuvishal, did you post a batch (ATTACH) on this thread? I did not understand your msg.
cheers