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.

6101.

Solve : Importing password to batch script?

Answer»

I am a beginner - please be patient. I work for a small firm that UTILIZES about 100 batch files to pull data from a main database. Database requires a user name and password each time when CONNECTING via ftp. We have been listing the user name and password in the ftp script file and they work fine until we need to change the password again. Then it is a tedious task to open all 100 files and change the password. Is there a way that the batch file can look up or import a password from one location thus eliminating the need to open all the batch files when the password changes? Thanks in advance for your help!Are you saying that you have multiple FTPs and each has a different log-in name/pass?Multiple FTPs pulling different data but with the same user name and password..I don't know if batch can be set to automatically change like that but you may be able to have a batch log into all of the FTPs and change the the batch their. I don't know if that is actually possible but I am shour someone knows if it is, and how to do it, if it is. Was that confusing?If you dont mind the password being held in clear text, store it in a 1 line file (call it password.txt) then have this line
Set /P password=which reads the first line from the file and puts it in the environment variable %password%
you then refer to %password% in your batchfile
Ok but were would you keep the password.txt file? If its right NEXT to the batch file then he would still have to update every single one. If it is in one location for all of the batch files to read then what is the code to make it read from the remote location.Thought it would be helpful to show an example of what we are working with.. Batch files are LOCATED in many locations but would like to draw the password from just one..

Example.bat
ftp -s:"C:\Hold\TestHold.txt" gsystcp1.sys.narley.com

TestHold.txt
DB101
Password
get 'Test.xDB101.PulledData.txt' "C:\wlldb2101\Info\PulledData.txt"
Quitwell, drawing from gpl's idea; would it be possible to setup a network share- (or use an existing network share) and place the file "testhold.txt" there?This seems like a similar idea. Maby you could build off of that.gpl - Thanks for your response-Its beginning to make some sinse to me. I'm still not sure where to plug in the set /p Password=GrahamExample posted earlier with disguised info....Whoops, missed it

Try something like this
Code: [Select]Example.bat
-----------
@Set /P Password=<C:\Hold\pw.txt
> C:\Hold\cmds.ftp echo DB101
>> C:\Hold\cmds.ftp echo %Password%
>> C:\Hold\cmds.ftp echo get 'Test.xDB101.PulledData.txt' "C:\wlldb2101\Info\PulledData.txt"
>> C:\Hold\cmds.ftp echo Quit

ftp -s:"C:\Hold\cmds.ftp" gsystcp1.sys.narley.com
Code: [Select]pw.txt
------
MyPasswordIsSecret
gpl - You NAILED it! Works perfectly! Thanks......

6102.

Solve : Booting from USB to DOS - how to logout?

Answer»
Hi,
I have CREATED a bootable USB great - I can also run Ghost from this USB great. However when I'm finished I still have a C prompt and I haven't been able to work out how to "logoff" or if I need to. I am not booted into XP/Vista/Wind 7 just using dos from my USB which gives me access to the NTFS disks (VIA NTFS4DOS or Ghost) and the cd drive. So what do I do not sure if just powering off is safe. The boot is done using the Win98 boot disk files on the USB. I see there are commands logoff and shutdown although neither are listed in my XP dos help but anyway these are to shutdown windows I'm not running windows,

Anyone know the answer to this,
Cheers,
GrahameYou should be able to just power off your computer and restart.The proper way to shut down from DOS is to save any FILE you are working on, then exit back to the prompt from whatever app you are running (you can only run one at a time) and FINALLY switch off. We used to listen for HDD activity to stop.

Of course, if you wish to reboot the MACHINE, you can do Ctrl-Alt-Delete or even press the reset button. This might be handy if you want to first remove the USB drive so that the machine will reboot from the next drive in the boot order list.

6103.

Solve : Backup Files under another users profile?

Answer» THANKS for taking the time to read my question.

I've made a .bat file that I can run that backs up folders under my user profile, and All Users. My .bat file however, does not back up my wife's folders. I have the security on, so I'm guessing that's why it doesn't work.

Is there a way I can put her PASSWORD in the .bat file so that it will reference it, and then back her FILES up?

Thanks,

BradQuote
My .bat file however, does not back up my wife's folders.


... or a colleague's or business rival's? hmmm, hadn't thought of that. I suppose my only option is to assign admin privelages back to my wife and I.

Thanks for the help???

BradHere is an idea.
Log on as the Administrator.
Set up a scheduled task to start that batch under the Administrator.
Switch user to your account. Leave the administrator "logged in" and let the computer run unattended. At the right time the backup well start automatically.
I have not personally TRIED this. Maybe SOMEONE else has a better idea.
6104.

Solve : Is there any way to Install the Application by default ??

Answer»

Is there any way to Install the Application by default without user intervention or Automatic installation by passing the Exe in command line ,or Autoinstaller kind of thingFor what reason? Insufficent information.
I need help on opening/getting to a MS-DOS window on my computer I'm using windows vista. I'm just trying to test a program but I'm also just learning how to do it I just want to learn how to make a program so any help will be HELPFUL If I can just use something else instead of MS-DOS window then I'd like to know.. Thanks!http://www.wikihow.com/Write-a-Batch-File


For Windows
1.Open up Notepad in Windows. You can do this by navigating to Start > Programs > Accessories > Notepad, or simply by entering notepad under Start > Run.
2.Or open up notepad by C:\WINDOWS\system32\notepad.exe
3.Save your file before anything, so be sure to follow the instructions closely.


1.Go to File > Save As... and chose a file name.
2.Choose your desktop as the location to save, for now. Don't click Save just yet.
3.Click on the dropdown MENU next to "File name". Select "All files" instead of Text Document".
4.Add .bat to the end of your file name before you save. For example, you would type example.bat.
5.Click on Save. If you did this correctly, you should see your file name in the title of Windows Notepad. Make sure that it reads as example.bat—not example.bat.txt. Now you are ready to create your batch file.
4.Type "@echo off" on the first line of your batch file. This will prevent any spaces in the batch file to be read by the program when executed.
5.Enter your commands. The following example below will show you how to create a batch file that will AUTOMATICALLY load wikiHow.com using Internet Explorer.
◦@echo off.
◦REM The following will open wikiHow.com in a new Internet Explorer window.
◦"start Iexplore.exe www.wikihow.com"
◦REM The following will open wikiHow.com in your default BROWSER, but if it is IE and you have ANOTHER IE window open, then it will hijack that window.
◦"start www.wikihow.com"
6.Save the file by going to "File>Save" and type in "wikihow.bat".
7.Run the file by double clicking the file on your desktop.


6105.

Solve : Eject Pen drive?

Answer»

hi,

how i eject pen drive thought DOS. if possible or not ??Why do you need it through batch? Can't you just go to, file > eject?Download eject.zip I did not make that.

Look here for help with it:
http://quick.mixnmojo.com/usb-disk-ejector

[attachment deleted by admin]You can't "eject" a USB drive; there is no way to push the plug out. The right word is "stop". Then you can PULL the plug out by hand.

You can bring up the Safely Remove Hardware box from a batch file with this code

Code: [Select]RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll
Usually my pen drive wouldn't eject when some virus affected with it. At that time when i like to eject it won't allow, even any application isn't ASSOCIATED with. Is there any command to eject safely at that time in dos. kalraj, see above. Salmon Trout is 100% correct on the Eject/Stop front... but in defence of Deadly D's question, if you have a Pen Drive plugged in and you right click on it under my computer, you are presented with 'Eject' as an option.



6106.

Solve : Generating one batch file from another?

Answer»

Folks,

Sorry for asking the question, as I am sure the answer is out there somewhere - I just don't know the right way to phrase this in a SEARCH:

I would like to run a batch file from a scheduled TASK to create a NEW batch file in the Startup folder and to reboot. The PURPOSE of this is to force an interactive login and action some commands, in a completely hands off fashion.

Because their are several minor variations to the batch files I want to create, I currently have several similar files that I copy to Startup at different times. But this feels untidy. I would rather have the contents of the new files that I want to create stored "in stream" in the main file.

I think that this is possible in Linux Bash script using a "<<<" to an end point, but again, I can't find the details.

Again, sorry for the vague question - flame away one step at a time:

1) create a batch that calls another batch. Get that working and then schedule with the at command.

2) CALL all batch files from a main batch or call the the next batch from the last batch. I believe a main batch offers better control and flow.

C:\>exit /?
Quits the CMD.EXE program (command interpreter) or the current batch
script.

EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.

C:\>

C:\>type main.bat
Code: [Select]@echo off
call wait1.bat
echo this line will execute when wait1.bat is finished
call wait2.bat
echo this line will execute when wait2.bat is finished
Output:

C:\>main.bat
waitbat1 will sleep 1
this line will execute when wait1.bat is finished
waitbat2 will sleep 2
this line will execute when wait2.bat is finished

C:\>type wait1.bat
Code: [Select]echo waitbat1 will sleep 1

C:\batextra\sleep 1

exit /b
C:\>
C:\>type generatebat.bat
Code: [Select]@echo off

Rem We may generate a new batch file
Rem with redirect (>) and append (>>)


echo echo Hello > newbat.bat
echo date /T >> newbat.bat
echo c:\batextra\sleep 3 >> newbat.bat
echo exit /b >> newbat.bat

C:\>
C:\>type newbat.bat
Code: [Select]echo Hello
date /T
c:\batextra\sleep 3
exit /b
Output:

C:\>newbat.bat

C:\>echo Hello
Hello

C:\>date /T
Tue 09/22/2009

C:\>c:\batextra\sleep 3

C:\>exit /b

C:\>

6107.

Solve : move a hidden folder?

Answer»
how can i move a hidden folder using ms dos batch command move
i TRIED but it worked only with unhidden folder
please help
thanksTry using xcopy then deleting the original. You may change the attributes of the hidden files and FOLDERS:


C:\>attrib /?
Displays or changes file attributes.

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [drive:][path][filename]
[/S [/D]]

+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
[drive:][path][filename]
SPECIFIES a file or files for attrib to process.
/S PROCESSES matching files in the current folder
and all SUBFOLDERS.
/D Processes folders as well.

C:\>

The copy and delete method suggested above is safer.
6108.

Solve : Auto run .exe file and answer yes to questions?

Answer»

Except with %1, %2, etc. anyway, no biggie. Quote from: Helpmeh on September 20, 2009, 03:24:02 PM

Except with %1, %2, etc. anyway, no biggie.

That's with batch files, not EXE's.Batch files CONVERTED to exe?Quote from: macdad- on September 20, 2009, 03:21:33 PM
Besides piping, you cant send KEYS to an exe.

If it is a console .exe which takes input from stdin, you can sometimes redirect stdin like this

program.exe < input.txt

Quote from: Helpmeh on September 20, 2009, 03:27:24 PM
Batch files converted to exe?

Exactly.
Well YES, but still haven't checked into Batch-To-Exe, from prior testing it had a few bugs.
6109.

Solve : How to copy & run batch file remotely?

Answer»

I have created one batch file on server, such that -
If the client is logged in into server for more than 8 HRS then kill the perticular task of that client remotely.
server = has a log of CLIENTS - i am reading the client login & logout logs from the log file.
Uptill this all ok..
----
problem 1) = But for killing the task i need to run taskkill cmd on client pc,
i have created that file also, but the problem is How do i send that file to the client machine? because i do not have the folder shared in my client pc & sharing permissions are also not there.
problem 2) = and also for executing taskkill batch file remotely - i can use PSexec cmnd. but for sending that cmnd, i have to pass on the client domain credentials(username & password) which i do not have, I have the credentials of administrator account but system doesn't accept those.
eagerly waiting for the answer, thankyou in advance.Are you the IT guy or something? Maybe you're doing something you're not allowed to do in the first place.Why do u think so?
As i said folder sharing is not allowed, it means i'm working in domain & domain is not having sharing rights, so my quastion was without folder sharing - How would i transfer files on remote machine.
& secondly about omiting credentials means i cannot enter all the domain users credentials in a batchfile, so quastion was - Can i make use of administrator password which is comman for all.YES you can. It would need to be a local or service account that every PC has been set up to give admin rights. You could also prompt for the domain/userid and password in the batch and use variables so the password is not HARD coded in the batch. If you do not have admin right then you will not be able to do this. Dear wbrost,
Yes iam having the administrator username & password of those client machines,
and It is ok for me to hardcode the variables (username & password) because all my client machines are having same administrator username & password.(administrator account is also exists).
Note:- all the machines are using domain account
but how would i go forward.you could try the following:

map the network drive to the remote system.
copy down the batch or using echo make on on the client system.
set up a scheduled task using the at command to start the batch at the desired time.
remove the mapped network drive and move on the the next system.

rinse and repeat

or you could ask the domain admin to set up a service account to use fro the PSexec commands.Quote from: wbrost on September 17, 2009, 07:01:34 AM

you could try the following:

map the network drive to the remote system.
copy down the batch or using echo make on on the client system.
set up a scheduled task using the at command to start the batch at the desired time.
remove the mapped network drive and move on the the next system.

rinse and repeat

or you could ask the domain admin to set up a service account to use fro the PSexec commands.

Dear wbrost,
I have created batch file on my server m/c, The operation of my batch file is like this,

1) I have log file in my server which records client login logout time, For particular user if the logout log is not exist(means application is still on & it is consuming license from the license server) then i am reading the clients last login time & date,
2) Checking the date & time difference with current date & time
3) If the time difference is greater than 8 hrs & date difference is greater than 1 day
4) Then, copy the killprocess.bat file from server to client machine & execute that batch file on client machine remotely to kill that perticular process.
-----

killprocess.bat file has one liner code,
cd\
taskkill /F /IM processname.exe
------
Issues/ Problem i am facing are,
1) for copying killprocess.bat from server to client machine requires shared folder on client pc. as said earlier my domain restrictions doesn't allow me to share folders in client pc.
2) even if i manage to copy the killprocess.bat file somehow, for executing that batch file remotely using PSEXEC command also requires the shared path where the killprocess.bat is located - How can i execute process remotely without having shared folder in client pc? is there any alternate to execute batch file remotely?

I thing now i have explained my problem in more detailed.
Eagarly waiting for the reply, Thanks in advance. 1) if you have access to the system you can map a network drive using the administrative share.
example: \\computername\c$
this will give access to the root of the c drive on the system computername


2) using the at command you can schedule a remote task to execute at a specific time.

The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.

if you still have questions please let me know.Dear wbrost,
You are correct,
but as i said earlier my domain client pc doesn't have share folders, instead the sharing permission is not exist.
and i suppose the mapping drive is possible only if the client machine has the shared folders in it.
pls correct me if i am wrong.there is actually a shared folder by default. This is called an administrative share. The administrative shares can be accessed by putting a dollar sign ($) after the drive letter.

example for the administrative share for the C drive would be: \\computer\C$

to see if the system has the administrative share active do the following:

Right click on my computer
click on manage
expand shared folders
click on shares.Dear Wbrost,
I'm getting following error while accesing those folders,
Error 5: Access Is Denied.

Is there any other alternate to copy file remotely (without sharing)
------
Can i make use of FTP for pushing batch file?
But i suppose FTP doesn't pushes anything, somebody has to push data to him & Pull data from him,
pls correct me if i am wrong.
(If above happens through FTP, i can make use of AT command to schedule that batch script as suggested by you.)How are you thrying to access the computer when you get the error message?

you can test access out side the command line by doing the following:

click on start
click on run
type in \\computername\C$

when prompted enter the following:
user name - computername\accountname
password - password for account


you need to make sure you are connecting as the account on the remote system.

please see the below command switches for reference:

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[[emailprotected] domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]

6110.

Solve : How to run a command in bat file..???

Answer»

Dear All,

I want run below command in .bat file but i have no idea how to make it Thur. Please help me on my question.

C:\Program Files\PrintFile>prfile32.exe /s:c:\test\*.txt


Thanking you

BR ShrinetWelcome to the CH forums.

Quote

C:\Program Files\PrintFile>prfile32.exe /s:c:\test\*.txt

Why are you using the redirection symbol > should this not be a backslash?

Quote from: Dusty on September 18, 2009, 04:23:33 PM

Why are you using the redirection symbol > should this not be a backslash?


It's not a redirection symbol; it's the last character ($g) of his console prompt.
=Code: [Select]@echo off
cd C:\Program Files\PrintFile\
prfile32.exe c:\test\*.txt

Rem Or
REM cd \
REM C:\Program Files\PrintFile\prfile32.exe c:\test\myfile.txt

Rem Test ONE file first and then use wildcard *
print32.exe is a third party program not on my machine and I cannot test the above. I do not want to download. Might work better with linux?Quote from: billrich on September 19, 2009, 01:47:17 AM
Might work better with linux?

You cannot run .exe files in Linux. (except with WINE)
Quote from: Salmon Trout on September 19, 2009, 02:10:32 AM
You cannot run .exe files in Linux. (except with WINE)



It worked ok with Hieneken Beer. Quote from: Salmon Trout on September 19, 2009, 01:24:32 AM
It's not a redirection symbol; it's the last character ($g) of his console prompt.


Did I misunderstand the OP's request or is it just a language interpretation thing?

Quote from: BRSHRINET on September 18, 2009, 08:58:43 AM

I want run below command in .bat file but i have no idea how to make it Thur. Please help me on my question.

C:\Program Files\PrintFile>prfile32.exe /s:c:\test\*.txt

Quote from: Dusty on September 19, 2009, 04:59:54 PM
Did I misunderstand the OP's request or is it just a language interpretation thing?

It seemed clear to me that the OP had either copied and pasted or else typed afresh what they could see in the command window:

C:\Program Files\PrintFile>prfile32.exe /s:c:\test\*.txt

The prompt shows that the CURRENT directory is C:\Program Files\PrintFile. Having logged into that directory, the OP then issued the command prfile32.exe /s:c:\test\*.txt

The default prompt format that which is obtained by issuing the command PROMPT $P$G, where $P means the current drive letter, path and folder, and $G means the > character*.

That is where your "redirection character" comes from.

Code: [Select]C:\>prompt /?
Changes the cmd.exe command prompt.

PROMPT [text]

text Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

$A & (Ampersand)
$B | (pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (greater-than sign)
$H Backspace (erases previous character)
$L < (less-than sign)
$N Current drive
$P Current drive and path
$Q = (equal sign)
$S (space)
$T Current time
$V Windows XP version number
$_ Carriage return and linefeed
$$ $ (dollar sign)


Quote from: Salmon Trout
It seemed clear to me that the OP had either copied and pasted or else typed afresh what they could see in the command window:

Ahhh, darnit, why didn't I think of that? Seems Billrich didn't either as he also suggests replacing the > char with the \ char.

Thank you for your clarification.

Quote from: Dusty on September 19, 2009, 09:55:00 PM
Ahhh, darnit, why didn't I think of that? Seems Billrich didn't either as he also suggests replacing the > char with the \ char.

But Billrich was on the right TRACK. Consider: You have a command window in a folder, D:\Path\folder. Here is the prompt that you see:

(1)

Code: [Select]D:\Path\folder>

You want to run a program called Program.exe (which is in that folder) so what do you type at the prompt? Why, its name (and extension probably). So, just before you hit Enter the command window looks like this:

(2)

Code: [Select]D:\Path\folder>Program.exe

You want to supply it with with a PARAMETER string: /a:b:\cdef\*.ghi so you add that after the program name:

(3)

Code: [Select]D:\Path\folder>Program.exe /a:b:\cdef\*.ghi

Now: how do you put all that in a one line batch file so that you can just e.g. plonk it on your desktop and thereafter double CLICK its icon when you want to perform the operation? Why, you need the path to the program, its name and extension, and the parameter string:

(4)

Code: [Select]D:\Path\folder\Program.exe /a:b:\cdef\*.ghi

The only difference visually between (3) and (4) is that the final > character from the prompt has been replaced by the final \ character of the program folder path. What Billrich needed to add were the double quotes necessary because "Program Files" contains a space.

Code: [Select]"C:\Program Files\PrintFile\prfile32.exe" /s:c:\test\*.txt



Ahah! Thank you again for the clarification...

6111.

Solve : help with some things in dos?

Answer»
C:\>type htmldrive.bat
Code: [Select]REM htmldrive.bat E
@echo off

%1:
For /f "delims=" %%a in ('dir /B /s *.htm') do echo %%a
Output:

C:\>
C:\>htmldrive.bat E

C:\>REM htmldrive.bat E
E:\bookmark.htm
E:\ETRUST EZ AntivirusS.htm
E:\maukiegrey.htm
E:\signature.html
E:\so.htm
E:\South.htm
E:\upgrade.htm
E:\walkthetalk_swf.htm
E:\CH.pps\aP LITE Flash\index.html
E:\CH.pps\PowerPoint\index.html

E:\>
6112.

Solve : Batch sounds.?

Answer»

Quote from: BC_Programmer on September 19, 2009, 12:10:51 PM


if memory serves it is the ASCII "bell" code [...] early electric typewriters... WELL, and printers.

The three letter mnemonic for CTRl-G, ASCII 07, is actually BEL, and it goes right back to teletypewriters (TTY) which predated (any) computers by some decades, although the ASCII code set only superseded Baudot in the 1960s.
Quote
author=Boozu link=topic=92191.msg623779#msg623779 date=1253384501]
billrich: You have to do the ^G through the comand prompt window for it to do anything.

Billrich wrote:

I was able to hear by running beep.bat on my machine ( see above post )Quote from: Boozu on September 19, 2009, 12:21:41 PM
Salmon TROUT: the built in one may not be standard but if the pc has any speakers then you will hear SOMETHING.

Nope. I don't hear CTRl-Gs through my external speakers linked to the sound card, and never have. I think you may be mistaken?Ya I was. I thought you ment something ells.Quote from: Boozu on September 19, 2009, 12:34:10 PM
Ya I was. I thought you ment something ells.

I just tried it & got QUITE excited in case it would work...
6113.

Solve : Problem with FTP?

Answer»

So wouldn't that be the first clue that the school has locked down FTP access to any server ...or am i missing a minute detail not yet provided ? ?

I thought you said you were good in another Post and laughed at all the script kiddies...

THIS ISN'T AT SCHOOL! I said that the script was to test if the host works properly under normal conditions. Aparently not. Quote from: Helpmeh on September 17, 2009, 04:41:19 PM

A test file. It says "Hello World". But it says connection closed by the host.

I don't see any filename specified in the batch file...Quote from: Helpmeh on September 17, 2009, 05:35:19 PM
THIS ISN'T AT SCHOOL! I said that the script was to test if the host works properly under normal conditions. Aparently not.

You may not be doing this at school right now but according to the below quote taken from reply #19 you do plan on using this at school.

Quote
There is currently no rule against using a computer to communicate to an other computer. And this was at home. I want to make sure it works before I check it at school to see if its blocked.

If you want to see if it is blocked at school ask the teacher if it is blocked. If they don't or wouldn't know you can turn this into a class project to see who can write the batch file to find out. Heck if you get the right teacher you might even be ABLE to get extra CREDIT for it.

If you don't want to bring this up to the teacher then you need to give us a good reason why as it sounds like you are trying to do something you shouldn't be.Quote from: Helpmeh on September 07, 2009, 02:19:14 PM
@echo off
:loop
cls
echo open>C:\schoolchatdatar.oti
echo USERNAME>>C:\schoolchatdatar.oti
echo PASSWORD>>C:\schoolchatdatar.oti
echo get test.txt>>C:\schoolchatdatar.oti
echo bye>>C:\schoolchatdatar.oti
pause
ftp -i -s:C:\schoolchatdatar.oti 0catch.com
pause
del C:\schoolchatdatar.oti
type test.txt
rem The above confirms that the FTP is working correctly and the file exists.
pause
goto loop


That's the code I started with. I haven't even started my real code because I need this to work first.
Try reading the bolded text.

Mroilfield, NICE idea. I would do that if the teachers knew how to find out what sites are blocked without checking by hand. I ALSO don't have a comtech course this year , nor do I have a death wish. I don't know about highschools you went to, but here, if you're smart, you only show it on tests. Or else. Quote from: Helpmeh on September 18, 2009, 08:25:44 PM
Try reading the bolded text.

How silly of me to not trust what you are trying to do just because you named a txt file "Test"

Quote from: Helpmeh on September 18, 2009, 08:25:44 PM
I would do that if the teachers knew how to find out what sites are blocked without checking by hand.

Once again here is your own reference to the fact that you are tying to circumvent something that you think might be blocked at school.

Here is a little educational fact for you:

If the school has it blocked then they don't want you to use it. Hence any attempt to get around it would be violating school policy.If it is blocked, and the host works normally, then I would use it outside of school, which would be fine too. I'm trying to find out if the host works properly.

Quote from: BC_Programmer on September 17, 2009, 07:41:56 PM
I don't see any filename specified in the batch file...
This was why I said read the bolded text, not to you mroilfield.
6114.

Solve : copying a directory to an other one using a batch file?

Answer»

Hi Guys
I have made a modification of a game (Battlefield 2) and am trying to create a BATCH file from a directory to a new one, so i don't have to putthose files in the installer and reduce the DOWNLOAD size.
The directories i want to copy are located in: "C:\Program Files\EA Games\Battlefield 2\mods\bf2\Levels" and i want to copy them to: "C:\Program Files\EA Games\Battlefield 2\mods\reality\Levels". This reduces the download size with about 1.3GB so i really NEED it.

Please Help.
Thanks in advance.
C:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/E]]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.

/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
C:\>

6115.

Solve : Setting IE Proxy Server?

Answer»

Is ther any way to SET IE Proxy Server setting thro COMMAND line ( MS DOS) Option.
Not with registry change. i think you can, there is this inetcpl.cpl in nt for ie options.
you just have to google for the argument you need to pass to inetcpl.cpl.I want perform the same in command lineIs there any way to Install the Application by default without user intervention or Automatic INSTALLATION by passing the Exe in command line ,ETC...

6116.

Solve : Geting command on .txt file:)?

Answer»

that's better. but some countries in latin america speak portuguese. So it's simply extending the blanket.

Additionally neither mexicans, nor any other spanish speaking person I know pronounces it that way; it was more or less a REVERSE plug on the common problem "I'd like 10 chicken fa-jite-ahhs" or pronouncing "Jalapeno" with the J sound, but in the reverse direction; or any number of english words that are derived from foriegn languages and retain the inconsistent pronounciation rules of their mother language, not a plug against mexicans, who have no compass to know how a j is pronounced in english.
So, then, being the topic is:
Quote

Re: Geting command on .txt file:)
We need to know if the version of Windows he is using was sold in Latin America. That WOULD make a BIG difference in the BAT file. -Right?
Oh, I mean ¿Cierto? ahh muy ciertoCuándo el poder del AMOR vence el amor de enchufa el mundo sabrá la paz

Cuándo Infierno se hiela

Del dicho al hecho, hay mucho trecho.Je déteste tout le vous, avec votre Espagnol. Je me demande également quand j'ai appri le français…I THOUGHT Americans said "GeeBus".
Quote from: billrich on September 15, 2009, 11:03:04 PM
Cuándo el poder del amor vence el amor de enchufa el mundo sabrá la paz

Cuándo Infierno se hiela



se supone que ser una broma?Quote from: BC_Programmer on September 15, 2009, 10:37:28 PM
Additionally neither mexicans, nor any other spanish speaking person I know pronounces it that way

In Chile and in the Rioplatense dialect spoken in parts of Argentinia J becomes like German 'ch' in ich when it precedes palatal vowels [i, e] for example: gente, jinete.
6117.

Solve : [SOLVED] Question about FOR?

Answer»

I REALLY HATE seeing that dumb question smiley you get when people type ???. Why can't people just use ONE question mark? In FACT I hate smileys in general*. There's NO NEED for that weeping sad face, we KNOW you're upset your computer doesn't WORK!

*Except the rolling eye one.


what are you talking about?

people don't use too many smileys!


saying this makes me sad

but it's our opinion that's cool


heh, couldn't help myself there.i opened a thread in off topic if you want to discuss this further....... just please: stop bumping

THANKS
Two-Eyes %

6118.

Solve : How to find automatically the path for an appli ??

Answer»

Hi all!

I'm searching for a way to find automatically an apllication's path. What I have to do is to go inside the directory to launch a command, like :

cd C:\Program Files\VLC
vlc test.mpg -f

That works well, but what if it's not INSTALLED here ? To scan the whole disk is the only solution ?

Thanks in advance
rekamIs this your homework?

euhm, why ?

it's just because I'm trying to make a CD-ROM with an UI in which you'll have a little button and when you press it, it OPENS a specific program (which has to be installed before) with some specific option commands.

The thing is, I don't know where the program will be installed. It should be Program Files if nothing is changed during the install, but who knows...

Is there a way to do that ?Windows maintains a data store of all the file names on the system. A user can query this data store and extract all sorts of interesting information.

Code: [Select]strComputer = "."

Set WshShell = CreateObject("Wscript.Shell")
Set objWMIService = GETOBJECT("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'vlc' and Extension = 'exe'")

For Each objFile in colFiles
WshShell.Run objFile.Name & " test.mpg -f"
Next

Save the script with a vbs extension and run from a command prompt as cscript scriptname.vbs

Good luck.
Quote

That works well, but what if it's not installed here ? To scan the whole disk is the only solution ?
i am afraid so. you can try the vbscript posted, or do the same with batch
Code: [Select]dir /B /S /A-D | findstr /I "yourfilename.ext"
You search like that?

An alternative would be (in a batch file):
Code: [Select]for /f %%I in ('dir "C:\file.txt" /s /b') do echo %%IYou can just use one % if you do it directly from Command Prompt.

If you want to just find the path (not to DISPLAY the filename), do this:
Code: [Select]for /f %%Iin ('dir "C:\file.txt" /s /b') do echo %%~dpIQuote from: Dark Blade on June 18, 2007, 05:27:30 PM
You search like that?
yes, that's my way of doing it when i have more search requirements that can't be accomplished just by cmd.exe's wildcard globbing.Okay, thanks!

for /f %%I in ('dir "C:\testasgi.txt" /s /b /p') do echo %%~dpI

I'm near the solution, now. I still have a problem with spaces. If the program is installed in "Program Files", the echo %%I display only "C:\Program" which is not very nice, at least from my point of VIEW...

Any idea ?Quote from: rekam on June 19, 2007, 01:47:03 AM
I'm near the solution, now. I still have a problem with spaces. If the program is installed in "Program Files", the echo %%I display only "C:\Program" which is not very nice, at least from my point of view...


You need to set a DELIMS switch appropriately to avoid the FOR command halting at the first space.

like this

for /f "delims==" %%I in ('dir "C:\testasgi.txt" /s /b /p') do echo %%~dpI

Type FOR /? at the prompt for more information.

Also, do you REALLY need the /p switch with DIR? This does not always work well in batch files. I can't see what use it is, unless it's left over from debugging. You're trying to find one file, right? You're never going to have a screenful of information.


6119.

Solve : rename file with file counter?

Answer»

i wanted to rename all my img001.jpg files to a more descriptive name like bday_001.jpg, bday_002.jpg

here is the LOGIC that I have in mind...

counter=000
for JPG files in folder PICTURE
do
counter = counter + 001
rename *.JPG to BDAY_.JPG
done

I can only code this in UNIX... I do not know how to do it in DOS. Please help.

Thank you.
Just save as filename.bat...

Code: [Select]@Echo Off
Echo.
If not exist %~f1.\*.JPG (Echo no .JPG files found in %~f1 & GoTo

:EOF)

Set Count=0
For %%A in (%~f1.\*.JPG) Do CALL :REN %%A
Set Count=
GoTo :EOF

:REN
Set /A Count=%Count%+1
Ren "%*" BDAY_00%Count%.JPG
Echo Ren "%*" %Count%.JPG
GoTo :EOF
Hope this helps .

8-)fffreakQuote

Just save as filename.bat...

Code: [Select]@Echo Off
Echo.
If not exist %~f1.\*.JPG (Echo no .JPG files found in %~f1 & GoTo

:EOF)

Set Count=0
For %%A in (%~f1.\*.JPG) Do Call :REN %%A
Set Count=
GoTo :EOF

:REN
Set /A Count=%Count%+1
Ren "%*" BDAY_00%Count%.JPG
Echo Ren "%*" %Count%.JPG
GoTo :EOF
Hope this helps .

8-)fffreak


Thanks! it worked!!!

However, after it renames the 10th file to BDAY_0010.jpg instead of BDAY_010.jpg. Is there a way that I can have it set to to start from 000 to 999.

Thank you!how can i specify folder in loop, what command i have to use.

for example i NEED to do this in c:\t3\test1.txt


If not exist %~f1.\*.JPG (Echo no .JPG files found in %~f1 & GoTo

Kindly do the needful.

Regards,
Mohamed Asif KPQuote from: MOHAMED ASIF KP on June 18, 2007, 04:53:40 AM
Kindly do the needful.



Mohammed, you need to note...

You should start a new topic. This belongs to somebody else.

In your new topic, post much more of your code.


sorry ... kindly appologies.... me henceforth i will do it.

Regards,
Mohamed Asif KPQuote from: tads98 on February 14, 2007, 11:58:54 AM
i wanted to rename all my img001.jpg files to a more descriptive name like bday_001.jpg, bday_002.jpg

here is the logic that I have in mind...

counter=000
for JPG files in folder PICTURE
do
counter = counter + 001
rename *.JPG to BDAY_<counter>.JPG
done

I can only code this in UNIX... I do not know how to do it in DOS. Please help.

Thank you.

sorry no dos for you. But vbscript
Code: [Select]Dim FSO,NewPrefix, OldPrefix, oDir, objFolder,NewFileName,counter
NewPrefix="bday_"
Set FSO = CreateObject("Scripting.FileSystemObject")
sDir = "C:\temp"
Set objFolder = FSO.GetFolder(sDir)
counter = 1
For Each Files In objFolder.Files
If FSO.GetExtensionName(Files) = "jpg" Then
NewFileName = NewPrefix & Padding(3,counter) & ".jpg"
Files.Name = NewFileName
counter=counter+1
End If
Next

Function Padding(ValueToPad, TheDigits)
theLen = Len(TheDigits)
If theLen < ValueToPad Then
Padding = STRING(ValueToPad-theLen,"0") & TheDigits
Else
Padding = TheDigits
End If
End Function
if you want to use it, save it as somename.vbs, then on command prompt, type cscript somename.vbs. Of course, you must change the sDir value to suit your case.


You did know, didn't you, that Windows Explorer has a built-in feature that will do 99% of what you want?

Let's say you have these files in a folder

img001.jpg
img002.jpg
img003.jpg

If you highlight them ***all*** and invoke rename (by hitting F2 or by right clicking the selection and choosing rename from the context menu), the first file in the selection opens the rename box. If you type "bday(0).jpg", the others will be renamed bday(1).jpg and bday(2).jpg.

I'm surprised, if you "code" in "UNIX", you don't know about Bash, which is very like DOS and NT, and you could then learn DOS command prompt in about 30 minutes.

Or is this your homework? Sorry if I'm being cynical here.

The NT prompt code for your logic above would look very similar to what you have written.




May This Help :

..TESTED..
Code: [Select]@echo off
REM set counter variable
set first=0
set second=0
set third=0
set path=C:\Picture

for /f "delims==" %%a in ('dir "%path%\*.jpg" /a:-d /b') do (
set pict=%%a
call :next
)
if /i "%first%"=="0" set first=
if /i "%second%"=="0" set second=
set /a third-=1
echo Total : %first%%second%%third% Picture was Succesfully Renamed
pause
exit

:next
if /i "%third%"=="9" set /a second+=1&&set third=0
if /i "%second%"=="9" set /a first+=1&&set second=0
ren "%path%\%pict%" "BDAY_%first%%second%%third%.jpg"
set /a third+=1
goto :eof

6120.

Solve : Get fullpath of Process/Image?

Answer»

Hello...

I just want to ask about qprocess or tasklist :
display output like this :
----------------------------------------------------------------------------
USERNAME SESSIONNAME ID PID IMAGE
Fen_Li CONSOLE 0 1412 explorer.exe
Fen_Li console 0 1300 firefox.exe
Fen_Li console 0 1760 cmd.exe
Fen_Li console 0 1472 qprocess.exe
-----------------------------------------------------------------------------
How to GET fullpath of (ex: firefox.exe) ??
I thing use %%~fI but does't WORK..
thnx b4don't know about tasklist but you can get fullpath using this
Code: [Select]strComputer = "."
Set objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcessList
WScript.Echo objProcess.Description &"->" & objProcess.ExecutablePath
Next

6121.

Solve : connecting to remote windows system from DOS batch file?

Answer» HI,

I need to connect 20 remote systems very often by USING IP address and LOGIN credentials. Can you please suggest how this can be done using DOS batch file?

how are you using your login credentials? Do you have an IDEA yet of using what technologies? FTP?TELNET? SSH?Network Mapping? etc...
6122.

Solve : copy file with success counter else failure counter.?

Answer»

HI All,

I want to copy the file to a folder with success counter and else failure counter.
if the file already exists it should sleep for few seconds. then it should continue till the numbers which i had entered as a 1st parameter.

i was trying this as below program, i was not correct, i am missing some thing. kindly guide where i am doing the error.

regards,
mohamed asif kp


@Echo Off
Echo.

SET /P COPIES=Please enter the number of files to copy (numbers only) :
SET /P SRCDIR=Please enter source Directory(example c:\t3\) :
SET /P SRCFILE=Please Enter Source File Name (example TEST) :
SET /P DESDIR=Please enter Destination Directory(example c:\t3\) :


:CONTINUE
If EXIST %SRCDIR%%SRCFILE%
(
SLEEP 2
copy %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%%%A.txt
SUCCESS = SUCCESS + 1
)
ELSE
(
FAILURE = FAILURE + 1
TOTAL = SUCCESS+FAILURE
IF TOTAL != COPIES GOTO CONTINUE ELSE GOTO END

:END

ECHO SUCCESS
ECHO FAILURE

There are easier ways to do this, but I just followed along your train of thought. %%A is not a defined name so I improvised a bit.

Code: [Select]@Echo Off
Echo.

SET /P COPIES=Please enter the number of files to copy (numbers only) :
SET /P SRCDIR=Please enter source Directory(example c:\t3\) :
SET /P SRCFILE=Please Enter Source File Name (example test) :
SET /P DESDIR=Please enter Destination Directory(example c:\t3\) :

set /a success=0
set /a failure=0
set /a total=0

:CONTINUE
If exist %SRCDIR%%SRCFILE% (
SLEEP 2
call set /a SUCCESS=%%SUCCESS%%+1
copy %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%%success%.txt
) ELSE (
call set /a FAILURE=%%FAILURE%%+1
)
call set /a TOTAL=%SUCCESS%+%FAILURE%

IF %TOTAL% neq %COPIES% (GOTO CONTINUE) ELSE GOTO END

:END
ECHO %SUCCESS%
ECHO %FAILURE%

Try checking out the for command with the /L switch which would provide a token to make the output files unique and COULD double as the counter for the loop.

Good luck. @ECHO Off

SET /P COPIES=Please enter the number of files to copy (numbers only) :

SET /P SRCDIR=Please enter source Directory (example c:\t3\) :

SET /P SRCFILE=Please Enter Source File Name (example test) :

SET /P DESDIR=Please enter Destination Directory (example c:\t3\) :

SET /A SUCCESS=0

SET /A FAILURE=0

ECHO %DESDIR%%SRCFILE%.txt
ECHO %SRCDIR%%SRCFILE%.txt

IF NOT EXIST %DESDIR%%SRCFILE%.txt (GOTO :ONE) ELSE GOTO :TWO

:ONE
COPY %SRCDIR%%SRCFILE%.txt %DESDIR%%SRCFILE%.txt
SET /A SUCCESS=%SUCCESS%+1
ECHO SUCCESS%SUCCESS%
GOTO END

:TWO
:CONT
SET /A FAILURE=%FAILURE%+1
SLEEP 9


IF NOT EXIST %DESDIR%%SRCFILE%.txt (GOTO :ONE) ELSE GOTO :TWO
ECHO FAILURE%FAILURE%

GOTO END

:END


6123.

Solve : How to copy some information with DOS Commands to a specific line??

Answer» HELLO,
I am trying to copy some information to a specific file that has already information (around 100 lines) but I only want to replace some strings in a specific lines without "touching" the rest of the file.

ANYONE has ideas how to do this with DOS Commands?

thxsee here for a start. I submitted a vbscript to replace strings in files. Also there are other batch SOLUTIONS on that thread. this will give you a start.There is also an MS-DOS utility called "fart.exe" (Find And Replace TEXT) which may do what you need.

As far as I know it replaces all occurrences of one sub-string with another sub-string.

I don't think you can specify a "range of text lines" to search, but it may do what you need.

Goto http://fart-it.sourceforge.net and follow the sourceforge link.

Hope that helps,
JAMES
6124.

Solve : Tricky file rename -> using WinXP and Win 2003 server?

Answer»

Hello group.

I've done a quick search for an answer to my problem but could't find one...

I have a file: URNT40.d20061101-t182300
The extension is the date and time, but I would like to either:

1. replace the "." with a "-" and give it a .txt extension
2. add a .txt as an additional extension (URNT40.d20061101-t182300.txt)

I would like to be able to do this WITHIN a batch file if possible.
Thanks for any suggestions.
Regards,
BryanQuote from: BryanRay67 on June 20, 2007, 07:57:13 AM

Hello group.

I've done a quick search for an answer to my problem but could't find one...

I have a file: URNT40.d20061101-t182300
The extension is the date and time, but I would like to either:

1. replace the "." with a "-" and give it a .txt extension
2. add a .txt as an additional extension (URNT40.d20061101-t182300.txt)

I would like to be able to do this within a batch file if possible.
Thanks for any suggestions.
Regards,
Bryan

(2)

for /f "delims=" %%F in ('dir /b') do ren "%%F" "%%F.txt"
Quote from: BryanRay67 on June 20, 2007, 07:57:13 AM

1. replace the "." with a "-" and give it a .txt extension


Code: [Select]Dim theFile
Set objArgs = WScript.Arguments
Set FSO = CreateObject("Scripting.FileSystemObject")
theFile=objArgs(0)
If InStr(1,theFile,".") > 0 Then
Set objFile = FSO.GetFile(theFile)
newString = Replace(theFile,".", "-")
objFile.Move(newString & ".txt")
End If
save as myscript.vbs, type cscript myscript.vbs URNT40.d20061101-t182300 on the command prompt. Works for this file naming format.
Quote
(2)

for /f "delims=" %%F in ('dir /b') do ren "%%F" "%%F.txt"

Thanks for your suggestion. This seems to work with the exception of it ALSO renames my batch file that is in the same folder.
Is there a way to have this batch file in a parent folder and only call the rename for the CONTENTS of a specified CHILD folder?

Thanks!
Bryan
method (1)

This batch file excludes itself from its operation

(thisfile.bat is whatever the batch file is called)

for /f "delims=" %%F in ('dir /b ^| find /v "thisfile.bat"') do ren "%%F" "%%F.txt"

method (2)

place this or the the older batch file in a folder somewhere on your PATH, eg C:\Windows, and call it by name at the command prompt from the directory to be OPERATED upon.


Thanks for your outstanding help!!!!

Regards,
Bryan
6125.

Solve : HOW TO READ INPUTS FROM FILE.?

Answer»

Hi all,

I need to read input from file as variable. Is there is any dos command available for this. i want to perform this in sequence. (Line by Line)

Regards,
Mohamed Asif KPthe usual command is FOR. Type FOR /? at the command prompt for more information. PLEASE give more information.

Code: [Select]@echo off
set /a LNE=0
:find
set /a LNE=%LNE%+1
for /f "skip=%LNE% delims=" %%m in ('FINDSTR /n . "C:\test.txt"') do goto find


set /a SKP=0

:begin
if %SKP% GTR %LNE% goto end
if %SKP% GTR 0 goto SECOND

:first

for /f "delims=" %%i in ('findstr . "C:\test.txt"') do (

echo %%i
goto second
)

:second
set /a SKP=%SKP%+1
for /f "skip=%SKP%" %%i in ('findstr . "C:\test.txt"') do (

echo %%i
goto begin
)

:end
echo.
echo Done!
echo.
@pause
That's kinda general, it just diplays, line by line, the lines of test.txt. Reply if you want something different.Darkblade, that's all very fine and all, and I salute the code wizardry, but why all those labels and gotos and fancy stuff? What's wrong, as a demo to a learner, with this...

for /f "delims=" %%F in (c:\test.txt) do (
echo %%F
)

Nothing. But if he WANTED to do something with the lines, findstr WOULD have to be used.Using the brackets like that makes the code shorter but as long as the work gets done, I don't see a problem. Dark Blade, I find in very long codes it's less complicating to use gotos but that's just me.
Everyone has their way.Quote from: Dark Blade on June 21, 2007, 02:54:56 AM

Nothing. But if he wanted to do something with the lines, findstr would have to be used.

Not necessarily.

Code: [Select]@echo off
REM create demo csv file
echo eggs,flour,milk > demo.txt
echo cream,butter,sugar >> demo.txt
echo vanilla,lemon,chocolate >> demo.txt
REM mmm...!

REM show first item in each line
for /F "delims=," %%L in (demo.txt) do (
echo %%L
)


result...

Code: [Select]eggs
cream
vanilla

i am actually curious what OP is going to do with those lines being read
6126.

Solve : creating a log.txt for each command ???

Answer»

a file that have been del, copy a file,TASKLIST PROGRAM, or etc....

every time the COMMAND above have been MADE then it will save to log.txt

6127.

Solve : first lines of a file using type?

Answer»

Hi,
I try to look for a way to look only for the first lines of a file.
Is it can be done using type or is there is another command?
TNX
can't remember who, but someone says this can do it.
Code: [Select]set /p var=< filename
You could DOWNLOAD one of the many DOS/WIN equivalents to the Unix HEAD command or you could save this batch file somewhere on your path

If you call it htype.bat the usage would be htype "filename.txt" N where N is the NUMBER of lines you want to see. Use quotes if the filename contains spaces. Use CALL if from a batch file.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /a lin=1
set /a MAX=%2
for /f "delims=" %%L in (%1) do (
echo %%L
set /a lin+=1
if !lin! GTR %max% goto end
)
:end
Quote from: contrex on June 26, 2007, 04:23:42 AM

You could download one of the many DOS/WIN equivalents to the Unix HEAD command or you could save this batch file somewhere on your path

If you call it htype.bat the usage would be htype "filename.txt" N where N is the number of lines you want to see. Use quotes if the filename contains spaces. Use CALL if from a batch file.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set /a lin=1
set /a max=%2
for /f "delims=" %%L in (%1) do (
echo %%L
set /a lin+=1
if !lin! GTR %max% goto end
)
:end


Tanks, it WORK beautiful, it as been a great help
6128.

Solve : Grabbing the directory name...?

Answer»

I'm writing a batch file that will copy a certain file into every sub-folder of a PARTICULAR folder. Here's what I have, but I'm not sure how to complete it:

For /f %%a in ( ) do (
SET Folder=%%a
Copy C:\Files\File.txt C:\Directory\%Folder&AMP;\
)

I'm not sure what to put in PLACE of "( )" that will get the folder name and then DROP it into the variable "Folder" for me. Any help is appreciated.
Thanks! In DOS and a batch program I believe
Code: [Select]%cd%Is the environment variable for the current folder?Figured it out:

C:
CD C:\Directory
For /D %%a in (*) do XCopy C:\Files\File.txt C:\Directory\%%a /y


Thanks

6129.

Solve : Moving back dir?

Answer»

Ok i'm new to does my problem is say i i'm here in does:

e:\folder1\folder2

how would i get back to folder1

ThanksQuote from: afcbob on June 25, 2007, 01:23:48 PM

Ok i'm new to does my problem is say i i'm here in does:
this part i'm not so sure about.. you might want to try rephrasing that
Quote
e:\folder1\folder2

how would i get back to folder1

Thanks
this part i think i get
there's a yellow folder icon in the top left of the EXPLORER or ''my computer'' WINDOW that has an arrow going to the left and then up, which will take yout to the parent directory of the folder you're in, is that what you want?
for example you will go from C:\My Documents\My Music
to
C:\My Documents

does this help? Sorry ment in does command.cd..

That's the letters c &AMP; d and 2 dots

goes up 1 level

It's not 'does' it's DOS.

Code: [Select]
c:\batch\ftp>cd..

c:\batch>cd..

c:\>
ahh... in DOS.. this can be CALLED a ''CD'' command , or just a ''CHANGE directory'' command.

Once you have located the directory you want, you may move from directory to directory using the ''CD'' command (''change directory'')

Example:

* C> cd furniture
* Moves you to the directory called 'FURNITURE'
* C> cd \furniture\chairs
* Moves you to the directory called 'CHAIRS' under the directory called 'FURNITURE'.
* C> cd ..
* Moves you up one level in the path.
* C> cd \
* Takes you back to the root directory (c: in this case).
Quote from: contrex on June 25, 2007, 01:54:18 PM
cd..

That's the letters c & d and 2 dots

goes up 1 level

It's not 'does' it's DOS.

Code: [Select]
c:\batch\ftp>cd..

c:\batch>cd..

c:\>


hehe oops you got to it first Great thanks thats the one.Quote from: afcbob on June 25, 2007, 02:52:05 PM
Great thanks thats the one.

I see you said you are new to using DOS.

You might like to bookmark these pages, for future reference. They really are helpful.

>Click here<
and
>here,too<


6130.

Solve : flash drive backup batch file?

Answer»

I think this would be the right place for this.

I'm trying to create a simple batch file to copy everything on drive I: to a massively buried subdirectory on drive C: and keep a log of it. Here's the gist of what I tried:

backup.bat
copy I:\ C:\Documents and Settings\Desktop\blah\bla_bla\youGetThePoint\flash backup /y
call C:\Documents and Settings\Desktop\blah\bla_bla\youGetThePoint\log.bat

log.bat
echo. |time |find "current" >> bacuplog.txt

log.bat works fine, just the main copy function isn't working. I thought about using I:\*.* rather than just plain I:\, but I want the copy command to take care of all subdirectories, hidden and otherwise.

Any help or suggestions would be greatly appreciated, thanks for your time.Quote from: Computer_Hopeless on June 27, 2007, 06:13:34 AM

I think this would be the right place for this.

I'm trying to create a simple batch file to copy everything on drive I: to a massively buried subdirectory on drive C: and keep a log of it. Here's the gist of what I tried:

backup.bat
copy I:\ C:\Documents and Settings\Desktop\blah\bla_bla\youGetThePoint\flash backup /y
call C:\Documents and Settings\Desktop\blah\bla_bla\youGetThePoint\log.bat

log.bat
echo. |time |find "current" >> bacuplog.txt

log.bat works fine, just the main copy function isn't working. I thought about using I:\*.* rather than just plain I:\, but I want the copy command to take care of all subdirectories, hidden and otherwise.

Any help or suggestions would be greatly appreciated, thanks for your time.

You should use xcopy, which is designed for this task.

Xcopy I:\*.* "C:\Documents and Settings\Desktop\blah\bla_bla\youGetThePoint\flash backup" /E /Y

Many thanks. I'd never heard of the xcopy command (too much work with older computers, I guess) ,so I looked up the SWITCHES and syntax, played around with them, and now it's working quite nicely.

However, log.bat isn't executing when called upon. Even when I changed the command to "call log.bat" since they are in the same directory. It works just fine when run by itself, so I must have messed up the call command syntax or something. I doubt this'll help with the problem SOLVING any, but the contents of log.bat have been changed for the better.

log.bat
echo @prompt set date=$d$_set time=$t$h$h$h > {a}.bat
%comspec% /e:2048 /c {a}.bat > {b}.bat
for %%v in ({b}.bat del) do call %%v {?}.bat
echo %date% %time% >> bacuplog.txtThat batch file looks scarily complex. What is it meant to do? What's in the batch file that calls it?I didn't write log.bat, I copied it off of the batch file help page and changed the name of the text file at the end. Its purpose is to write to a text file (bacuplog.txt) the time and date at which I last ran the file. I came across it when I was trying to solve my earlier problem and thought, "Hmm, that might be a neat feature..."The problem I'm having is when, in backup.bat, I write "call log.bat" it doesn't call log.bat. Perhaps if I threw the text in at the end, instead of having it call on the file, it might work. I'll edit this post or make a new ONE (depending on if you beat me to the post) to tell you if that works, but I'd still like to know how I messed up a command with a 4-letter keyword.

OK, this may take a little longer than I thought. Since the call command line is at the end of the batch file, I have to wait for the copy function to finish. I've got a PLETHORA of files on my flash drive, a binary smorgasbord.

Weird... I executed backup.bat from the command prompt without making any changes from before, and the call command worked.

Alright, now I really feel like an idiot. It works just fine. Thanks again for your time, your help, your effort, and INTRODUCING me to the xcopy command.
6131.

Solve : Trouble with DOS application installion on Pentium?

Answer»

I have a NUMBER of old DOS programming language programs and C++ libraries that I would like to archive and use, e.g., Turbo C++, Turbo Pascal, MASM, LISP, Ada, etc. I bought a new hard drive and formatted 100 MB with FAT and installed MS-DOS 6.22 with no problems. However, I cannot get the programs to install. When I try to install, e.g., Turbo C++ 3.1, the floppy drive will run but NOTHING will happen and I get the "C:\>" prompt back. With other APPLICATIONS, e.g., Microsoft Assembler, the machine will hang. I can look at the directories on the disks and perform other DOS functions. If I try to install MASM from the "A:\>" drive, I get a "Divide overflow" message. The most puzzling thing is that I successfully installed the programs going to the command prompt in Windows XP home edition, and they seem to work in the LIMITED amount I have played with them, but would like to run in DOS (or at least know why it doesn't work). It must be something in the way Windows emulates the 16 bit environment.

My computer is an HP model a1340n, Pentium 4, 3.2 GHz, 2 GB RAM, BIOS ver. 3.03 11/18/05. The hard drive is a Samsung 250 GB SATA. The floppy drive is 3 1/2" with USB connection.

The AUTOEXEC.BAT is:
C:\DOS\SMARTDRV.EXE
@ECHO OFF
PROMPT $P$G
PATH=C:\DOS

The CONFIG.SYS is
DEVICE=C:\DOS\HIMEM.SYS
FILES=30
STACKS=12,256
BUFFERS=30

There are not many things to try in the BIOS: Block (Multi-Sector Tranfer), PIO Mode, DMA Mode, and 32 Bit Data transfer. I have tried every combination without success.

I have tried installing "MO-SLO", a program to slow down DOS applications, but this does not affect anything.

I have tried copying the files from the installation under the Windows XP cmd prompt installation to a floppy disk and then copying them to the hard drive. The copying is successful, but the programs will not run.

Initially, I used PartitionMagic 8.0 to create DOS 6.22 and Windows XP partitions. When I was not able to install the DOS programs, I though it might have something to do with the partitioning or booting up process, so I bought a new hard drive just for DOS.

I was able to install a GENUS GRAPHICS library with no trouble.

I have tried connecting the hard drive with DOS installed to a Gateway 3.0 MHz Pentium 4 machine. It was able to install the first Turbo C++ disk but did not recognize additional disks as correct.

If anybody has any suggestions, I would love to hear them.

6132.

Solve : cd-room not detected?

Answer»

Hi, I got an old laptop,which can use only cd-room or only floppy-drive. It has to be changed. I wanna install win98 OS on it. if I use windows startup floppy,then I cant use cd-room, if I change it, it will not detect it. I have to restart, but then I cant use floppy. I used sys c: command and now the computer can boot from hardrive, but cd-room cant be seen on dos prompt. Well, I hope I made this problem clear to understand, can somebody help me, pls?[/email]1st you gotta check the boot sequence in the CMOS. MAKE sure CDRom is the 1st in the sequence. While using win98 CD, it should prompt you 3 options to startup. choose the one run with CDRomQuote from: lisatka on June 23, 2007, 02:24:01 AM

... I used sys c: command and now the computer can boot from hardrive, but cd-room cant be seen on dos prompt. Well, I hope I made this problem clear to understand, can somebody help me, pls?

So if you could boot DOS from the hard drive with CDRom support, then you'd be able to proceed - correct?

If so, you need to install CD drivers while booting.

Even THOUGH this references XP/2000, the principle is the same.
>Click Here&LT;

Read it all, of course. But I think you've done everything down through section 2, step I.

Examine the steps carefully, beginning with J.
Basically, you need to locate the CD driver file on your bootable floppy, and COPY it to your hard drive. Then you need to edit config.sys and autoexec.bat on your hard drive - so that the driver is loaded during boot up. This is what the above linked page is stepping you through.

You can get more info, SYNTAX, examples: >Click here<


I hope this helps.

Which version of Win98 ? ?

If the CD is from MS it should be bootable...Quote from: patio on June 23, 2007, 09:39:41 AM
Which version of Win98 ? ?

If the CD is from MS it should be bootable...


The OP may be like me - my original is on a shelf somewhere for safe keeping.
I use a copy I burned, that I keep handy. If it gets scratched, it is not the end of the world.

It won't boot. I never really spent any time to figure it out.


You need to burn an iso copy of the windows 98 bootdisk
and an iso copy of windows 98 to a cd then use it bootable.hi all, thank you for your help! especially to willy, because I used his tip and it worked. I had known about this method, but I didnt remember exactly, so his commands were very helpful!now I am running installation of windows 98 and it saved me some money, because I was running out of ideas.Quote from: lisatka on June 25, 2007, 06:43:04 AM
hi all, thank you for your help! especially to willy, because I used his tip and it worked.

Excellent!
It is always nice to hear success stories. Thanks for the follow up post.

Quote
..., but I didnt remember exactly,

It is also nice to know that I am not the only one that does this.

Quote
so his commands were very helpful!now I am running installation of windows 98 and it saved me some money, because I was running out of ideas.

You came to the right place for ideas. Join us here whenever you like.



6133.

Solve : MORE file renaming help needed?

Answer»

For me to rename a set of rar files to remove a single space and replace it with a more compliant underscore so that I could then do a batch unrar to individual folders with names that I wanted to specify with a loop;

I did this:

Code: [Select]@setlocal
@echo off
echo renaming archives to remove SPACES...
for /F "tokens=1-3 delims=. " %%i in ('dir /b *.rar') do call :do_rename "%%i" "%%j" "%%k"
echo extracting archives to separate directories...
for /F "tokens=1,2 delims=." %%i in ('dir /b *.rar') do call :do_extract "%%i" "%%j"
goto :eof

:do_rename
ren "%~1 %~2.%~3" "%~1_%~2.%~3"

:do_extract
echo extracting %~1.%~2
mkdir "%~1"
unrar e -inul "%~1.%~2" "%~1"
But what if I have FILENAMES with an arbitrary number of spaces in the filename? Obviously I can't pass in an arbitrary number of parameters into the label call. Or can I? I would like to avoid parsing the data and storing count data in a temporary file. Ideally, it would best to do it all in a single loop traversal but is batch file processing that powerful? I am guessing it is but I don't know. Any help would be greatly appreciated. Have I made myself CLEAR enough?

Egads,

JoshIf you are using Windows XP, then you could do something like this...?
Code: [Select]@echo off
echo Renaming archives to remove spaces...
for /F "eol= delims=" %%i in ('dir /b *.rar') do call :do_rename "%%i"
goto :eof

:do_rename
set RENVAR=%1
ren %RENVAR% %RENVAR: =_%

Here is an example of this code being run...
Code: [Select]D:\test>dir /b
a b c dddd e.rar
a b c dddd.rar
a b c.rar
a b.rar
a.rar
test.bat

D:\test>test
Renaming archives to remove spaces...

D:\test>dir /b
a.rar
a_b.rar
a_b_c.rar
a_b_c_dddd.rar
a_b_c_dddd_e.rar
test.bat

D:\test>

Please NOTE this code fails to rename filenames which contain percent (%) ...
Code: [Select]D:\test>dir /b
% b.rar
a b c dddd e.rar
a b c dddd.rar
a b c.rar
a.rar
test.bat

D:\test>test
Renaming archives to remove spaces...
The system cannot find the file specified.

D:\test>dir /b
% b.rar
a.rar
a_b_c.rar
a_b_c_dddd.rar
a_b_c_dddd_e.rar
test.bat

D:\test>

Hope that helps,
JamesA very elegant solution. I was not familiar with the SET function nor the use of the surrounding % character so I'll look them up to understand how it works. Thanks for the assistance. =)

Josh.how about a vbscript. doesn't break on %
Code: [Select]Dim Spaces, ReplaceMent,FSO ,sDir
Spaces=" "
ReplaceMent = "_"
sDir="c:\temp" 'Directory to search files
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder(sDir)
For Each Files In objFolder.Files
If Right(Files.Name,4) = ".rar" Then
If InStr(1,Files.Name,Spaces) > 1 Then
NewName = RenameFile(Files.Name,Spaces,ReplaceMent)
WScript.Echo "NewName is ",NewName
Files.Name = NewName
DoUnrar(Files.Path)
End If
End If
Next

Function RenameFile(TheFile,Pattern,ReplacePattern)
FileBaseName = FSO.GetBaseName(TheFile)
FileExt = FSO.GetExtensionName(TheFile)
If Len(FileExt) = 0 Then
FileExt = ""
Else
FileExt = "."&FileExt
End If
NewFileName = Replace(FileBaseName,Pattern,ReplacePattern,vbTextCompare)
NewFileName = NewFileName & NewChars & FileExt
RenameFile = NewFileName
End Function

Function DoUnrar(TheFile)
Dim Command
Set WSHShell = CreateObject("Wscript.shell")
Command = "unrar e -inul " & TheFile & " c:\temp" 'extract to c:\temp
WScript.Echo Command
Set execObj= WshShell.Run(Command)
End Function

6134.

Solve : bat to exe program-exe file cannot run under DOS?

Answer»

after i CONVER my .bat file to .exe file,the file cannot run under DOS.
why?
What OPERATING System, What program did you USE and what was in your code?
Batch programs on XP might not work on 2000 for example.
Some programs don't work properly for conversion.Most batch file compilers don't work very WELL. They can only compile simple batch files and don't correctly compile complex batch files, with nested for loops, XP FEATURES, etc.

Personally I use Brandon Dargo's Batch File Compiler, which seems to work pretty well.

You can download an evaluation version from www.BDargo.com.

Hope that helps,
James

6135.

Solve : File Renaming help needed. (SOLVED)?

Answer»

I have a daily file from my system that comes like the following:

ttx_export_20070622.txt
ttx_export_20070621.txt
ttx_export_20070620.txt

As you can see the above 3 files for 3 DAYS 20th, 21st and 22nd June 2007.

I need a BAT file or any tool that can automatically rename these files as follows:

0120070622.txt
0120070621.txt
0120070620.txt

What I am doing now is replacing the text "ttx_export_" with "01"

How can I ACHIEVE it?

Thank you.
You could do something like this:

copy "location\of\file\ttx_export_20070622.txt" "location\of\file\0120070622.txt"Quote from: Carbon Dudeoxide on June 22, 2007, 03:04:56 AM

You could do something like this:

copy "location\of\file\ttx_export_20070622.txt" "location\of\file\0120070622.txt"
that won't really do what OP requested, although it can be done manuallyNo, that won't do.

To make it simple this is what I want.

Original file name "ttx_export_20070622.txt"
I want a script to rename it to "01_20070622.txt"

Tks
Sometimes it is easier to do ONE file at a time.

Code: [Select]@echo off
for /f "tokens=1-3 delims=_"" %%i in ('dir *.txt /b /s') do (
ren %%i 01_%%k
)

You really didn't give us enough info on your directory structure and your first request has no underscore in the renamed file but your last post does. I'll let you fix up the code as you see fit.

Quote from: Sidewinder on June 22, 2007, 04:52:32 AM
Sometimes it is easier to do one file at a time.

Code: [Select]@echo off
for /f "tokens=1-3 delims=_"" %%i in ('dir *.txt /b /s') do (
ren %%i 01_%%k
)

You really didn't give us enough info on your directory structure and your first request has no underscore in the renamed file but your last post does. I'll let you fix up the code as you see fit.



Thanks for this help. Here is the directory info and my real file names. I would really appricate if you can help me on this:

Directory = c:\bat\export
Org File = ttx_export_20070622.txt
Expected File = 0120070622.txtI just noticed my first reply was a little heavy on the keyboard. This might work for your situation:

Code: [Select]@echo off
for /f "tokens=1-3 delims=_" %%i in ('dir c:\bat\export\*.txt /b /s') do (
ren %%i 01%%k
)

Good luck. I created a batch file CALLED do.bat with the following contents:
Quote
@echo off
for /f "tokens=1-3 delims=_" %%i in ('dir c:\bat\export\*.txt /b /s') do (
ren %%i 01%%k
)

When I execute the do.bat file I am getting the following error:
Quote
The system can not find the file specified
Code: [Select]@echo off
for /f "tokens=1-3 delims=_" %%i in ('dir c:\bat\export\*.txt /b') do (
ren %%i_%%j_%%k 01%%k
)

I need more sleep.

Great, works file.

Thanks a lot!This thread was useful for me to rename a set of rar files to remove a single space and REPLACE it with a more compliant underscore so that I could then do a batch unrar to individual folders that I wanted to specify numerically with a loop.

Like this:

Code: [Select]@setlocal
@echo off
echo renaming archives to remove spaces...
for /F "tokens=1-3 delims=. " %%i in ('dir /b *.rar') do call :do_rename "%%i" "%%j" "%%k"
echo extracting archives to separate directories...
for /F "tokens=1,2 delims=." %%i in ('dir /b *.rar') do call :do_extract "%%i" "%%j"
goto :eof

:do_rename
ren "%~1 %~2.%~3" "%~1_%~2.%~3"

:do_extract
echo extracting %~1.%~2
mkdir "%~1"
unrar e -inul "%~1.%~2" "%~1"
But what if I have filenames with an arbitrary number of spaces in the filename? Obviously I can't pass in an arbitrary number of parameters into the label call. Or can I? I would like to avoid parsing the data and storing count data in a temporary file. Ideally, it would best to do it all in a single loop traversal but is batch file processing that powerful? I am guessing it is but I don't know. Any help would be greatly appreciated. Have I made myself clear enough?

Egads,

Josh
6136.

Solve : Edit GPO from cmd?

Answer»

Is there any tools or FUNCTION with which i can EDIT Group POLICY (LOCAL or Domain) from COMMAND prompt.

6137.

Solve : P3P?

Answer»

I am looking to open the P3P file in the registry and remove the contents , I have done this before and I am unable to remember the COMMAND to make the contents VISIBLE . If anyone KNOWS the command to do so i WOULD be most grateful .
The location of the file in the registry is . . .

HKEY/CURRENT_USER/SOFTWARE/MICROSOFT/WINDOWS/CURRENT_VERSION/INTERNET_SETTINGS/P3P/HISTORY

Any help will be greatly appreciated.Open regedit go to the key right click on it and then delete it.

6138.

Solve : Command Prompt - add date?

Answer»

Hello all,

I am stuck on writing a .bat where i need to include the current date.

The script goes;
cd c:\ndfd\degrib18\bin
perl get_gfs.pl data yyyymmdd06 6 180 3 all "TMP.2 m|UGRD.10 m|VGRD.10 m|PRMSL.MSL|RH.2 m|4LFTX.SFC|CAPE.sfc" c:\ndfd\degrib18\data\GFS

Note:
Where the yyyymmdd is where the current date needs to be dispalyed in that format.

Any help would be really great

Thank

Ianwhat is your regional date format :

I'am use "Day dd/mm/YYYY"
so, to get yyyymmdd format :
Code: [Select]@echo off
set year=%date:~10,4%
set month=%date:~7,2%
set day=%date:~4,2%
set fdate=%year%%month%%day%
cd c:\ndfd\degrib18\bin
perl get_gfs.pl data %fdate%06 6 180 3 all "TMP.2 m|UGRD.10 m|VGRD.10 m|PRMSL.MSL|RH.2 m|4LFTX.sfc|CAPE.sfc"
c:\ndfd\degrib18\data\gfs
Hi, thanks for replying.

This still does not work for me, it returns the date as %year%006/06%

I need it to reurn as 20070623

IanQuote from: gucci_406 on June 22, 2007, 02:01:55 PM

Hello all,

I am stuck on writing a .bat where i need to include the current date.

The script goes;
cd c:\ndfd\degrib18\bin
perl get_gfs.pl data yyyymmdd06 6 180 3 all "TMP.2 m|UGRD.10 m|VGRD.10 m|PRMSL.MSL|RH.2 m|4LFTX.sfc|CAPE.sfc" c:\ndfd\degrib18\data\gfs

Note:
Where the yyyymmdd is where the current date needs to be dispalyed in that format.

Any help would be really great

Thank

Ian
dude, you can do the date calculation in your Perl script.
Code: [Select]$nowdate= strftime "%Y%m%d", localtime;

add that into your perl script, and you don't need to use DOS to get the date.Quote from: ghostdog74 on June 23, 2007, 12:53:55 AM
Quote from: gucci_406 on June 22, 2007, 02:01:55 PM
Hello all,

I am stuck on writing a .bat where i need to include the current date.

The script goes;
cd c:\ndfd\degrib18\bin
perl get_gfs.pl data yyyymmdd06 6 180 3 all "TMP.2 m|UGRD.10 m|VGRD.10 m|PRMSL.MSL|RH.2 m|4LFTX.sfc|CAPE.sfc" c:\ndfd\degrib18\data\gfs

Note:
Where the yyyymmdd is where the current date needs to be dispalyed in that format.

Any help would be really great

Thank

Ian
dude, you can do the date calculation in your Perl script.
Code: [Select]$nowdate= strftime "%Y%m%d", localtime;

add that into your perl script, and you don't need to use DOS to get the date.

Hi Mate,

I am not really able to write in perl, the script was writtern by some one else, so i dont really know where to place it.

I have tied a couple times, but get errors. Would it be possible for you to have a look. I have inculded the script below.

#!/usr/bin/perl -w
# w. ebisuzaki CPC/NCEP/NWS/NOAA 10/2006
#
# simple script to download gfs files
# inspired by Dan Swank's get-narr.pl script
# this script uses the tecnique described in
# http://www.cpc.ncep.noaa.gov/products/wesley/fast_downloading_grib.html
#
# ARGUMENTS: action YYYYMMDDHH HR0 HR1 DHR VAR_LIST LEV_LIST DIRECTORY
#
# action = inv (display inventory of 1st file)
# data (get data)
#
# HR0, HR1, DHR: forecast hour parameters
# do f_hour = HR0, HR1, DHR (fortran)
# for (f_hour = HR1; f_hour <= HR1; f_hour = f_hour + DHR) (C)
#
# VAR_LIST: list of variable separated by colons, blanks replaced by underscore
# ex. HGT:TMP:OZONE
# LEV_LIST: list of levesl separated by colons, blanks replaced by underscore
# ex. 500_mb:sfc
#
# DIRECTORY: name of the directory in which to place the files
#
# v1.0 10/2006 who is going to find the first bug?
# v1.0a 10/2006 better help page
# v2.0beta 10/2006 no need for egrep, get_inv.pl and get_grib.pl
# v2.0beta2 10/2006 no need for egrep, get_inv.pl and get_grib.pl
# v2.0beta3 10/2006 update messages, ignore case on matches
#------------ user customization section -----------------------------------------

# location of curl
$curl="curl";

# the URLs of the inventory and grib must be defined by $URL$inv and $URL$grb
# symbolic variables supported YYYY MM DD HH FHR (forecast hour)
#
# grib2 files from www.ftp.ncep.noaa.gov $URL='http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.$nowdate= strftime "%Y%m%d", $HH/gfs.t${HH}z.pgrb2f${FHR}';
#
# grib1 files from www.ftp.ncep.noaa.gov
$URL='http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.$YYYY$MM$DD$HH/gfs.t${HH}z.pgrbf${FHR}';
#
$inv='.idx';
$grb='';

# $windows='no';
$windows='yes';
#------------- guts of script ---------------------------------------------------
$version="2.0beta2";
if ($#ARGV != 7) {
print "get_gfs.pl $version\n";
print "\nget_gfs.pl action YYYYMMDDHH HR0 HR1 DHR VAR_LIST LEV_LIST DIRECTORY\n\n";
print " action = inv (display inventory of first file)\n";
print " data (get data)\n";
print " HR0, HR1, DHR: forecast hour parameters\n";
print " do f_hour = HR0, HR1, DHR\n";
print " VAR_LIST: list of variable separated by colons, blanks replaced by underscore or all\n";
print " ex. HGT:TMP:OZONE, all\n";
print " LEV_LIST: list of levels separated by colons, blanks replaced by underscore or all\n";
print " ex. 500_mb:sfc, all\n";
print " DIRECTORY: name of the directory in which to place the files\n";
print "\n EXAMPLES\n\n Reading an inventory\n\n";
print " get_gfs.pl inv 2006101800 0 0 0 all all .\n\n";
print " Downloading 500 hPa Height and Temp 0/3/6 hours forecasts to current directory\n\n";
print " get_gfs.pl data 2006101800 0 6 3 HGT:TMP 500_mb .\n\n";
print " Downloading PRATE 12/18 hours forecasts to current directory\n\n";
print " get_gfs.pl data 2006101800 12 18 6 PRATE all .\n\n";
print " Of course the date code will have to be current.\n";
exit(;
}

$action = $ARGV[0];
$time = $ARGV[1];
$hr0=$ARGV[2];
$hr1=$ARGV[3];
$dhr=$ARGV[4];
$VARS=$ARGV[5];
$LEVS=$ARGV[6];
$OUTDIR = $ARGV[7];

$YYYY = substr($time,0,4);
$MM = substr($time,4,2);
$DD = substr($time,6,2);
$HH = substr($time,8,2);

# check values

if ($action ne 'data' && $action ne 'inv') {
print "action must be inv or data, not $action\n";
exit(;
}

if ($YYYY < 2006 || $YYYY > 2012) {
print "bad date (year) code $time\n";
exit(;
}
if ($MM < 1 || $MM > 12) {
print "bad date (month) code $time\n";
exit(;
}
if ($DD < 1 || $DD > 31) {
print "bad date (day) code $time\n";
exit(;
}
if ($HH < 0 || $HH > 23) {
print "bad date (hour) code $time\n";
exit(;
}
if ($hr0 == $hr1) {
$dhr = 3;
}

if ($dhr != 3 && $dhr != 6 && $dhr != 12 && $dhr != 24) {
print "dhr must be 3, 6, 12 or 24, not $dhr\n";
exit(;
}

if ($hr0 > $hr1) {
print "hr0 needs to be <= hr1\n";
exit(;
}
if ($dhr <= 0) {
print "dhr needs to be > 0\n";
exit(;
}
if (! -d $OUTDIR) {
print "Directory $OUTDIR does not exist\n";
exit(;
}

$VARS =~ tr/:_/| /;
if( $VARS =~ m/ALL/ig ) { $VARS = "."; }
else { $VARS = "$VARS):"; }

$LEVS =~ tr/:_/| /;
if( $LEVS =~ m/ALL/ig ) { $LEVS = "."; }
else { $LEVS = "$LEVS)" ; }

$URL =~ s/\$YYYY/$YYYY/g;
$URL =~ s/\${YYYY}/$YYYY/g;
$URL =~ s/\$MM/$MM/g;
$URL =~ s/\${MM}/$MM/g;
$URL =~ s/\$DD/$DD/g;
$URL =~ s/\${DD}/$DD/g;
$URL =~ s/\$HH/$HH/g;
$URL =~ s/\${HH}/$HH/g;

$output = '';

$fhr=$hr0;
while ($fhr <= $hr1) {
if ($fhr <= 9) { $fhr="0$fhr"; }
$url = $URL;
$url =~ s/\$FHR/$fhr/g;
$url =~ s/\${FHR}/$fhr/g;
$file = $url;
$file =~ s/^.*\///;

#
# read the inventory
# $line[] = wgrib inventory, $start[] = start of record (column two of $line[])
#

if ($windows eq 'yes') {
$err = system("$curl -f -s $url$inv -o $OUTDIR/$file.tmp");
$err = $err >> 8;
if ($err) {
print STDERR "error code=$err, problem reading $url$inv\n";
sleep(10);
exit(;
}
open (In, "$OUTDIR/$file.tmp");
}
else {
open (In, "$curl -f -s $url$inv |");
}

$n=0;
while () {
chomp;
$line[$n] = $_;
s/^[^:]*://;
s/:.*//;
$start[$n] = $_;
$n++;
}
close(In);
if ($n == 0) {
print STDERR "Problem reading file $url$inv\n";
sleep(10);
exit(;
}

#
# find end of record: $last[]
#

$lastnum = $start[$n-1];
for ($i = 0; $i < $n; $i++) {
$num = $start[$i];
if ($num < $lastnum) {
$j = $i + 1;
while ($start[$j] == $num) { $j++; }
$last[$i] = $start[$j] - 1;
}
else {
$last[$i] = '';
}
}

if ($action eq 'inv') {
for ($i = 0; $i < $n; $i++) {
print "$line[$i]:range=$start[$i]-$last[$i]\n";
}
exit(0);
}

#
# make the range field for Curl
#

$range = '';
$lastfrom = '';
$lastto = '-100';
for ($i = 0; $i < $n; $i++) {
$_ = $line[$i];
if (/$LEVS/i && /$VARS/i) {
$from=$start[$i];
$to=$last[$i];

if ($lastto + 1 == $from) {
$lastto = $to;
}
elsif ($lastto ne $to) {
if ($lastfrom ne '') {
if ($range eq '') { $range = "$lastfrom-$lastto"; }
else { $range = "$range,$lastfrom-$lastto"; }
}
$lastfrom = $from;
$lastto = $to;
}
}
}
if ($lastfrom ne '') {
if ($range eq '') { $range="$lastfrom-$lastto"; }
else { $range="$range,$lastfrom-$lastto"; }
}

if ($range ne '') {
$err = system("$curl -f -v -s -r \"$range\" $url$grb -o $OUTDIR/$file.tmp");
$err = $err >> 8;
if ($err != 0) {
print STDERR "error in getting file $err $url$grb\n";
sleep(20);
exit $err;
}
rename "$OUTDIR/$file.tmp", "$OUTDIR/$file";
$output = "$output $OUTDIR/$file";
}
else {
print "no matches (no download) for $file\n";
}
$fhr += $dhr;
}
print "\n\nfinished download\n\n$output\n";
exit(0);
the perl script can take in variable date, not just the current system date. Therefore better not to change it. However, IF only you just need system date, insert before the $YYYY,$MM,$DD declaration.
Code: [Select]...
$time= strftime "%Y%m%d%H", localtime;
$YYYY = substr($time,0,4);
$MM = substr($time,4,2);
$DD = substr($time,6,2);
$HH = substr($time,8,2);
....
the other way, is to somehow find a way to derefence the %fdate% batch variable from the DOS version.
6139.

Solve : what to code in the autoexec.bat & config.sys?

Answer»

i had created a bootable floppy disk in XP pro plaform, what should i code in the autoexec.bat & CONFIG,SYS files so that i can make a bootable CD to RUN an APPLICATION in MSDOS? example the application file name is run.exe

thank for READING

6140.

Solve : Can Batch file continue after reboot/restart??

Answer»

I'm writing a batch file to install a few pieces of software, but each require a restart, and do the restart automatically because I have them doing the installs unattended/passive/quiet. They must stay unattended/passive/quiet and must restart before the next can begin for each to install properly in order. To give an idea, the software is Windows Service pack, Program, Program.

Can the batch file continue it's process after a restart? I would also need it to auto-logon and re-establish a connection with the mapped drive.Installing something secretly..........sounds a bit strange to me..........

I think the only way to have a file start after restart is by USING Scheduled Tasks.I found the perfect solution to my problem. No secrets about the software, I just didn't think it made a DIFFERENCE what it was in the problem.

To solve my problem, I created a series of batch files that will do the whole process. First, I turned on Auto Logon so that with each restart, it'll just get BACK into the user and continue. The first batch file runs from removable media. It will MAP a network drive (/persistent:no), create the dir c:\tempdir\ and copy two files down from it's mapped drive. One named "5.BAT" to the newly created directory, and one named "start.bat" to the Startup folder in program files. Lastly, the first bat from removable media will install one program from the map drive and the computer restarts.

Start.bat:

C:\tempdir\1.bat
C:\tempdir\2.bat
C:\tempdir\3.bat
C:\tempdir\4.bat
C:\tempdir\5.bat

5.bat remaps the drive (/persistent:no), will copy 4.bat into the \tempdir\, install one program and restart.

4.bat remaps the drive (/persistent:no), will copy 3.bat into the \tempdir\, delete 5.bat, install one program and restart.

3.bat remaps the drive (/persistent:no), will copy 2.bat into the \tempdir\, delete 4.bat, install one program and restart and so on until 1.bat installs it's last program not requiring restart which ends by deleting start.bat and \tempdir\.

For some reason, it took me a while to see this plan of action. But once I started, it was very simple. The /persistent:no when mapping the drive avoids the reconnection password prompt at each restart. Hopefully this can be of help to someone else.

Cheers

6141.

Solve : Heads up about gamerx365?

Answer»

See his posts here... and here... and here...

It seems his only purpose in posting on this forum is to try to gain enough knowledge to wreck his school pc's.Yh i tryed helping this guy........ and confussed him more


But thanks for the heads up there i hate my school but i wouldnt wreck the computers. I am in 10th grade now and I am the best programmer in the grade. I want to keep learning to keep my status and so people can fear (and nerds to respect) my power and gift. Sure my creations are not the best or the most useful, but I have basically only been experimenting. I have created many websites and made games as well. You can see what I have done by going to some- http://freewebs.com/cloneshotel piczo.com/sethfilmfest. I do not want to hurt any computer at all. You have got all things wrong. I want to be a software engineer and someday own a software company. I do NOT want to be a nerd sitting at my computer in my underwear and hacking people or sending viruses. So far my topics are based on tricking my friends or trying to defeat my school computer security system because the moron IT department thinks they need to block everything including my harmless sites.Quote from: gamerx365 on July 09, 2007, 05:20:14 PM

i hate my school but i wouldnt wreck the computers. I am in 10th grade now and I am the best programmer in the grade. I want to keep learning to keep my status and so people can fear (and nerds to respect) my power and gift.

I do NOT want to be a nerd sitting at my computer in my underwear and hacking people or sending viruses. So far my topics are based on tricking my friends or trying to defeat my school computer security system because the moron IT department thinks they need to block everything including my harmless sites.

That a 10th grader would write something like this sends a SHIVER up my spine..okay but im not doing illegal stuffz here, people dont need to be scared of me, i wouldnt bring a gun to school or anything, i just want to be a great programmer and help kids at my school that want to do the same things as I. No one at school like the fact that they block any website, and we already ping them, the thing is it just takes to long.Quote from: gamerx365 on July 09, 2007, 05:43:12 PM
okay but im not doing illegal stuffz here, people dont need to be scared of me, i wouldnt bring a gun to school or anything, i just want to be a great programmer and help kids at my school that want to do the same things as I. No one at school like the fact that they block any website, and we already ping them, the thing is it just takes to long.
Erm isnt is illegal to even metion this on the site im notifying a admin , i dont really care what your intentions this is illegal topic closed........ if i really wanted to screw up the schools computers i would have by now, i have a freind that shut down the server in 7th gradeQuote from: Richenstony on July 09, 2007, 05:59:44 PM
Quote from: gamerx365 on July 09, 2007, 05:43:12 PM
okay but im not doing illegal stuffz here, people dont need to be scared of me, i wouldnt bring a gun to school or anything, i just want to be a great programmer and help kids at my school that want to do the same things as I. No one at school like the fact that they block any website, and we already ping them, the thing is it just takes to long.
Erm isnt is illegal to even metion this on the site im notifying a admin , i dont really care what your intentions this is illegal topic closed........
i wouldn't say that's illegal, and i'm sure this fella's made his intentions clear, but misunderstood. i also wanted to further my knowledge regarding computers to get around some basic security systems at school, for an entirely different reason though, main one being: the techs there can be notified of what is possible with the school computer system and find a way to block it. i think the fact that this child wants to be feared is more childish than scary. if you wanted to be feared, you should have done things differently and gone along the path Bill Gates did. i'm sure nobody wants to mess with him, despite the fact that he's generous and has rather high moral standards, so maybe you should just word things differently when you try to ask for help or try to explain your case.
whether it has been done or not, i don't think there is much of a reason to notify admin, but that's not up to me.That last part you kindly added to your lovely reply wasnt called for , i notifed the admins due to a security risk / illegal talk on this fourm , i dont think any talk like this should be tolerated in anyway , going through slight secuirty or hacking or incriping of any kind on a school computer isnt just illegal you can face a prison or a fine ..... not only is DUSTY looking out for this fourm im also looking out for this kid under the grounds of getting himself into trouble with the school / law ... if that is wrong i wont do it anymore i will just shut up and i wont speak from now on........tell me im taking this a bit to harsh well im sorry but thats just what i do , i cnt seem to understand this at all...........

I cant do jack about this thread but i can sure has *censored* give my opinion on it ......... i dont think any of this guys intentions are ligit.......no offence to him i have nofing agasint you what so ever , but as a member of this fourm i have the right to EXPRESS my opinion on this matter.


Case closed we both have the right to express our opinions and i completely support yours Tony
don't misunderstand what i said though, read through your post carefully, it seems as if you were saying that the issue with the ping was illegal? i hate to tell you... but it's not. i've been helping my school for 3 years now with dealing with internet security issues and that just sso happened to be one of the issues that came up, it is not recommended or approved of, but most certainly isn't illegal or punishable by law.
i think maybe his school should just have a logging monitoring system
but apart from that, i think this kid should be warned that any mal-intent is childish and immature, and should be discarded along with false pride.
good work though Tony you're gonna need to be a strict person if you're having a child soon well ya know lol got to look out for the kids

I just dont think its right is all......but like i said its my opinion ..... can you please find something in writeing to say it aint illegal , i dont dis-belive you but a guy from my school back in the day did the same thing and he got into deep doo doo........

I didnt miss read your post i just didnt like it when you challanged my authority to notify the admins......incase your wondernin when you did that you said you wouldnt have done it personally but as i said i just dont like it when stuff like this floats around on here....

PEACE PEOPLE NO FLAME NO WAR WANTED....... not to challenge your views once again
but:
Quote from: reaper_tbs on July 09, 2007, 07:34:12 PM
whether it has been done or not, i don't think there is much of a reason to notify admin, but that's not up to me.
i didn't say i wouldn't personally have done it, in fact, i probably would have, just because it would have been done eventually anyway. but, alas, you are older than me so challenging your opinions only brings discontented THOUGHTS i'm sure
hopefully admin will get here soon and relieve us both of the pain of constantly correcting each other
i also don't believe it's right that some things are illegal and others not, and i really couldn't be bothered going to the trouble of finding out anything regarding legalities, as i have had enough with the police for one day >.< (refer to my post about the car... my poor baby..)

too right about peace maan... have some peeeace...Topic Closed.
6142.

Solve : Stop Device?

Answer»

I have to CREATE a bunch of THUMB DRIVES. I have a batch file that will write the necessary data to the drives but then I would like to stop the drives so they can SAFELY be removed so I can start the next batch of drives.

6143.

Solve : HELP PLS.?

Answer»

i know this may sound super EASY to you guys.. but can ANYONE show me how to format the diskette on the floppy drive using batch commands... PLS. pls. pls... thanksI WISH you had chosen a better title! HELP PLS is about as BAD as it could be. "How to format a diskette in DOS" would have been so much better.

Assuming the drive letter is A:

FORMAT A:

is what you need to do.



6144.

Solve : Trying to batch copy a file into Program Files folder?

Answer»

Hello all. First post so PLEASE be gentle with me LOL
I have tried to find an answer to this but to no avail so am hoping you guys might be able to help me.
I am running WINDOWS XP SP2
I would like to be able make a batch file that will copy a file from a directory on a CD to a directory within C:\Program Files.
I believe the problem I have is that I can't seem to get around the Read only attribute of Progam files and it's sub folders.
I am new to this but find it very interesting and am keen to learn
Here is what I have so far that I know works.

XCOPY E:Test1\testfile.txt C:\ /Y

I can only go as far a the Root of the drive. Any folders I try and paste into further than C:\ don't work.
I have tried (at least I think I have) USING the attrib -r command but it doesn't seem to work for me.
Could one of you point me in the right direction please.
Kind Regards
Jimmy
What is the name of the directory in C:\Program Files?

let us suppose

(1) the target folder actually exists already
(2) its path is C:\Program Files\test1

You did know that a path or folder name that contains spaces needs to be enclosed in quotes, didn't you?

So how about this...

XCOPY E:Test1\testfile.txt "C:\Program Files\test1" /Y

Try it and report back...

Quote

I can't seem to get around the Read only attribute of Progam files and it's sub folders.

I have never heard of that before. Who told you that? Mine certainly is not read-only. How would programs ever get installed if that were true?






Thats Amazing! A little pair of quotes was my problem after all.
Many Many Thanks for helping me out. I didn't know that an existing directory had to be in quotes. Sorry but I am very much a learner.
As for the read only attrib point; I am right in thinking that when you right click on a file ot folder and select properties, if the read only box is coloured in, that means the attributes are set to read only? Is that not right then? I thought that was my problem.
Kind regards for helpjng me and I look forward to the next time I may need help.
Thank you
Jimmy
Quote from: Jamangie on July 08, 2007, 06:03:36 AM
I didn't know that an existing directory had to be in quotes.

A directory or folder or file name only has to be in quotes if it contains one or more spaces. However it is a GOOD habit to always use them.

Quote from: Jamangie on July 08, 2007, 06:03:36 AM
As for the read only attrib point; I am right in thinking that when you right click on a file ot folder and select properties, if the read only box is coloured in, that means the attributes are set to read only?


When you right click an ordinary folder (not a file) (not a system folder) in Windows Explorer, and look at the "Attributes" section at the bottom of the "property sheet" (as it is called) that appears, the "Read-only" box is filled with the highlight colour, in a pale shade. This happens whether or not the folder is read-only. If you click the check box, you can make it go clear, (not read only) or you can get a check (tick) to appear in it (read only). If you click "apply" or "OK", you would think that the folder would get its attribute changed accordingly. It doesn't. Right click the folder again, you see the colour.

This is normal Windows behaviour for folders. It is by design. (That's the way Microsoft designed things). You can't change this.

If you want to change a folder from read-only to read-write, or vice versa, you have to do it from the command line using the ATTRIB command

attrib +R "folder path\folder name" to make it read-only

attrib -R "folder path\folder name" to make it read-write.

Explanation here

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

A Great Explanation. Many Thanks again. Speak soon
Jimmy
6145.

Solve : IF NOT EXIST?

Answer»

okay so what if I wanted to make a code for a batch FILE that WOULD delete a certain folder or folders if a certain file doesnt exist. I have tried in a DOS command window and found the commands that work for this, but when i compile this into a batchfile code it does not works. This is what I have:
Code: [Select]@echo off
cd..
cd..
cd..
cd..
cd Documents and Settings
cd seth
cd desktop
IF NOT EXIST key.txt
DEL test.txt
exitdo this instead..

@echo off
cd..
cd\docume~1\
cd seth
cd desktop
if not exist key.txt del test.txt
exit@echo off

REM Place file path in VARIABLE to simplify COMAND lines.
SET Location=C:\Documents and Settings\seth\desktop

REM Use fully qualified file names in command.
IF NOT EXIST "%Location%\key.txt" DEL "%Location%\test.txt"

Here is your problem

This will not do what you intend
Quote

IF NOT EXIST key.txt
DEL test.txt
exit

In batch language you cannot WRITE multiline IF statements like that. The whole statement MUST be on one line, either an actual line or an extended line.

On one actual line...

Quote
IF NOT EXIST key.txt DEL test.txt
exit

Or on an extended line. A line is extended with an open-parentheses character "(" and the extension is finished with a close-parentheses character ")".

Quote
IF NOT EXIST key.txt (
another command if wanted
DEL test.txt
another command if wanted
)
exit

This works at the command line too, in win2K and XP

Quote
c:\>(
More? echo 1
More? echo 2
More? echo 3
More? )
1
2
3

c:\>

Note: These are parentheses ( ). These are "brackets" { }.
6146.

Solve : ping replay?

Answer»

How do I get my computer to only log the ip’s that reply’s in a ping. I’m having the batch ping series of a computers and if it replays I want it to out put it to a file, would this be a for COMMAND with | find/i "reply" do echo>> text.txt

PS
PLEASE HELP sorry if I have been asking stupid questions I learn best from example and than reading a tutorial that goes with it. THINK you for your support.
Quote

How do I get my computer to only log the ip’s that reply’s in a ping. I’m having the batch ping series of a computers and if it replays I want it to out put it to a file, would this be a for command with | find/i "reply" do echo>> text.txt

PS
PLEASE HELP sorry if I have been asking stupid questions I learn best from example and than reading a tutorial that goes with it. Think you for your support.

i assume you have a list of ips to ping. So you would do a for loop over these ips, then use the ping command.
eg for ip in list_of_ips:
ping -n 1 ips > NUL
if errorlevel is 0 then echo "ip is alive"

just a SUGGESTION...
so how would i do this i have a veriable set for the ip the VAR is ip1 so how would i make this workQuote
so how would i do this i have a veriable set for the ip the var is ip1 so how would i make this work

have not done batch for a while.guess might be something like this
@echo off
FOR /F %%i in (file_with_ip_list.txt) do (
ping -n 1 %%i > nul
if %errorlevel% == 0 (echo %%i is alive >> output_file.log )
)

think you that worked or to be simplier.
@echo off
ping (where every you want)>>log.txt
6147.

Solve : Rename file each time batch file runs?

Answer»

I am currenlty using a simple batch file:

@echo off
pdm_webstat.exe -d > c:\pdm_webstat.txt

I want to be able to rename the .txt file each time the batch file is run. How can I accomplish this?

Thanks you can keep a counter in a file, or you name your output file with some sequence. EG c:\pdm_webstat01.txt. so the next time you run the batch, check for that number and increase by 1.. I've tried this but i just overwrote the document. I will try your other solution. What do you mean by counter?

@echo off
pdm_webstat.exe -d > c:\pdm_webstat01.txt

QUOTE from: lsblanchard on July 06, 2007, 09:22:43 AM

What do you mean by counter?
it's just basically a file that contains the count.
by naming the files with a number, it should be more clean than having to maintain this counter file.This didn't work:

Name your output file with some sequence.

eg c:\pdm_webstat01.txtQuote from: lsblanchard on July 06, 2007, 10:01:08 AM
This didn't work:

Name your output file with some sequence.

eg c:\pdm_webstat01.txt
show what you have done.isblanchard, you need to use batch arithmetic.

study the /a switch of the SET command.

try this :
Code: [Select]@echo off
for /L %%a in (0,1,9) do for /L %%b in (0,1,9) do (
if not exist "c:\pdm_webstat%%a%%b.txt" (
pdm_webstat.exe -d > c:\pdm_webstat%%a%%b.txt
exit
)
)
Quote from: Fen_Li on July 07, 2007, 02:00:23 PM
try this :
Code: [Select]@echo off
for /L %%a in (0,1,9) do for /L %%b in (0,1,9) do (
if not exist "c:\pdm_webstat%%a%%b.txt" (
pdm_webstat.exe -d > c:\pdm_webstat%%a%%b.txt
exit
)
)
have you considered what happens every time this batch is run?@echo off

REM Two examples of variable file name


REM Output to file with date/time stamp. Will work for files that are greater than one minute apart

REM Get date and time and set to a variable
for /f "tokens=1,2 delims=: " %%a in ('time /t') do set t1=%%a%%b
for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do set t1=%%c%%a%%b%t1%

REM Write output with date/time stamp
pdm_webstat.exe -d > c:\pdm_webstat%t1%.txt


REM Output file with sequential numbering.

REM Self seed from script and maintain sequence of multiple runs
REM Sequence file pointer
SET Sequence=C:\Sequence.cmd
REM Get current sequence if it exists
REM MUST use CALL
IF exist %Sequence% call %Sequence%
REM Seed the sequence if it was not found, start at zero!
IF not Defined NumTimes SET /a NumTimes=0
REM Add one to the sequence. This is why started at zero.
SET /a NumTimes+=1
REM Store the value in a file for next time
ECHO SET NumTimes=%NumTimes%>%Sequence%

REM Output a sequenced file
pdm_webstat.exe -d > c:\pdm_webstat%NumTimes%.txt


REM NOTE that this does not clean up old files or ROTATE files.
6148.

Solve : how to start internet?

Answer»

im trying to start firefox w/ command prompt but i cant
im ALSO trying to start other PROGRAMS but i cant start anything besides paint and notepad and all the other default programs that come on ur computergenerally you use the START command like this, with the full PATH to the program file

Like this if you WANT the batch file to wait for the program to finish

start "C:\Program Files\Mozilla Firefox\firefox.exe"

Like this if you don't.

start "" "C:\Program Files\Mozilla Firefox\firefox.exe"i do not know anything about firefox but you can try this, it works for ie, and you can go to a specific WEBSITE too.
Code: [Select]start http://(whatever website you want).com
ie. start http://yahoo.com

6149.

Solve : Connecting to a drive help?

Answer»

how do you connect to the cd/dvd drive from cmd, to copy some files for it... i need to make a batch file the atomaticly COPIES the files into a specifyed location..

Thank you for any help

TheWingsERYou FIND out the drive letter for example by looking in My Computer.


you can find your CDROM letter programmatically, ASSUMING you have only 1 drive.
here's a vbscript
CODE: [Select]strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colCD = objWMIService.ExecQuery("Select * from CIM_CDROMDrive")
For each objCD in colCD
Wscript.Echo objCD.Drive
Next
save it as getCDRom.vbs or other names you fancy.
here's the batch to call it
Code: [Select]@echo off
for /F "tokens=*" %%i IN ('cscript /nologo getCDRom.vbs') do (
echo %%i
)

just with batch u can get CD/DVD ROM letter :
Code: [Select]@echo off
set sum=0
for /f "tokens=3,4" %%a in ('echo list volume ^|diskpart ^|find "ROM"') do (
set LTR=%%a
set LABEL=%%b
call :calsum
)
goto next
:calsum
call set /a sum+=1
call set LTR_%sum%=%LTR%
call set LABEL_%sum%=%LABEL%
goto :eof
:next
echo You Have [%sum%] CD/DVD-ROM
for /l %%l in (1,1,%sum%) do (
call echo.[%%l].[%%LTR_%%l%%:\] - [%%LABEL_%%l%%]
)
pause>nul

6150.

Solve : *Solved* Making a autoinstall batchfile?

Answer»

Hello everyone.

I'm making a INSTALL cd with a bunch of drivers for my computer.

How can i make a check that i have installed a driver, so if the computer restarts i don't have to install all of the allready installed drivers.

is it possible to write and read from a txt file ?

like:
install driver 1, write 1 to the textfile.
install driver 2, write 2 to the textfile

when i start the bat file, it will read from the textfile if no textfile is found, install from driver 1.
If it FINDS the textfile and it reads 2 from the textfile begin installing fom driver 3.

Do you understand my question, and if so, can you help me ?

_BYou could do something like:
Code: [Select]@echo off
setlocal
set NextDriverLog=C:\NextDriverLog.txt
if not exist %NextDriverLog% GOTO :Driver1
set /p NextDriver=<%NextDriverLog%
goto :%NextDriver%
:Driver01
\Driver01\setup.exe
if not ERRORLEVEL 1 echo Driver02>NextDriverLog
:Driver02
\Driver02\setup.exe
if not errorlevel 1 echo Driver03>NextDriverLog
:Driver03
\Driver03\setup.exe
if not errorlevel 1 echo Driver04>NextDriverLog
:Driver04
\Driver04\setup.exe
if not errorlevel 1 echo Driver05>NextDriverLog
:Driver05
\Driver05\setup.exe
if not errorlevel 1 echo Done>NextDriverLog
:Done
echo Done
pauseI will try that.

Thanks.

_BJust had to change this line "if not errorlevel 1 echo Driver02>NextDriverLog"
To this "if not errorlevel 1 echo Driver02>%NextDriverLog%"

Then it worked fine.

Thanks a bunch.Just a point: That is what happens, often, if you use similar names for variables and for files. You end up forgetting quotes or % signs.
Yeah, SOMETIMES I think I am good enough to post code without testing it ... but if it is more than a line or 2 it usually isn't perfect. Or maybe I do it on purpose to give the poster something to work on so they can learn instead of just copying code?