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.

201.

Solve : Complicated batch for statement help?

Answer»

doing a rework of some files and UPDATING alot of utilities,
helping a friend redo his class scheduling to incorporate some swf and pdf items into a DAILY feed for each student..

here's the "structure"
text file say Mon.txt has the directories to loop thru... for that given day..
text file 2.. student file.. has the results..if none the file is blank.....

batch should look at student file.. see the last doc read... then goback and get the next item in that folder.. refereed to in the Dayfile.. the files in the FOLDERS begin with 01, 02, 03... to maintain a order to the presentations.. so the whole file name isn't important.

i've been craming a bunch of batch work in due to a move.. in 2 weeks.. and loosin my patience :-D I get the directories to spit, but it does them all.. but I know i've got the counter messed up because I can't get it to just move one file upIf you don't post your code, that means you are expecting us to perform a nasty combination of mindreading and guesswork, which we don't like.
for /F "delims=" %%b in (%MASTERSRV%\Server\Class\%%a.txt) do (
forfiles -p "%%b" -s -m *.* /C "cmd /c echo path">>%MASTERSRV%\Server\Class\%%a-tmp.txt
)
)


I'm just going with a simpler code, this will output the directories for the student, dump it on the term and I'll use a for loop SCRIPT on the PC to allow them to keep pace.. much thanksI think you need to lose that SECOND closing parenthesis.

202.

Solve : Turn off laptop monitor?

Answer»

Hi folks,

I want to turn off laptop monitor USING dos command.
Is there any command or bat I can make?Download nircmd: http://www.nirsoft.net/utils/nircmd.html

Put it in system32

Enter this into command prompt: nircmd.exe monitor off

You can of course also put this in a batch if needed.I do not want to use others SOFTWARE. So, thought there must me something in windows.

Like shutdown.exe, logon.exe, there should be something sleep.exe, standby.exe

Regards
vishu Quote from: vishuvishal on July 24, 2010, 01:15:20 PM

I do not want to use others software. So, thought there must me something in windows.

Like shutdown.exe, logon.exe, there should be something sleep.exe, standby.exe

Regards
vishu

There is.

Shutdown.exe


C:>shutdown /?
Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]
    [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

    No args    Display help. This is the same as typing /?.
    /?         Display help. This is the same as not typing any options.
    /i         Display the graphical user interface (GUI).
               This must be the first option.
    /l         Log off. This cannot be used with /m or /d options.
    /s         Shutdown the computer.
    /r         Shutdown and restart the computer.
    /g         Shutdown and restart the computer. After the system is
               rebooted, restart any registered applications.
    /a         Abort a system shutdown.
               This can only be used during the time-out period.
    /p         Turn off the local computer with no time-out or warning.
               Can be used with /d and /f options.
    /h         Hibernate the local computer.
               Can be used with the /f option.
    /e         Document the reason for an unexpected shutdown of a computer.
    /m \\computer Specify the target computer.
    /t xxx     Set the time-out period before shutdown to xxx seconds.
               The valid range is 0-315360000 (10 YEARS), with a default of 30.
               If the timeout period is greater than 0, the /f parameter is
               implied.
    /c "comment" Comment on the reason for the restart or shutdown.
               Maximum of 512 characters allowed.
    /f         Force running applications to close without forewarning users.
               The /f parameter is implied when a value greater than 0 is
               specified for the /t parameter.
    /d [p|u:]xx:yy  Provide the reason for the restart or shutdown.
               p indicates that the restart or shutdown is planned.
               u indicates that the reason is user defined.
               If neither p nor u is specified the restart or shutdown is
               unplanned.
               xx is the major reason number (positive integer less than 256).
               yy is the minor reason number (positive integer less than 65536).



Can you give any command to turn off computer display?http://www.raymond.cc/blog/archives/2008/07/20/how-to-manually-turn-off-notebook-or-laptop-lcd-screen/As Salmon Trout said,

Shutdown /hMy guess is he wants to turn off the display of his rival's laptop so he can win a bet.
But yes, it can be done without extra software and not putting it into hi berate. Quote from: MattPwns on July 25, 2010, 01:51:52 PM
As Salmon Trout said,

Shutdown /h

That actually shuts down the computer. If he wants to blank the display but keep the computer running then this is no use!

Anyhow, another link

Turn Off LCD.exe is in this archive; can call from batch; works on 32 & 64 bit Windows

http://www.redmondpie.com/downloadscenter/TurnOffLCDv101.zip



Thank you for the replies.

I have seen that softwares already.

I would like to turn off the monitor of my laptop.

I am not right now on my desk.

So, I would like to type command on Dos and turn off the display.

Setting the Hz rate more will turn off the display but that is not the way. Cause that will try to increase the hardware functionality beyond it's limitation.

I just need to know if there is some kind on command on Dos to do it.


Like we do have screensaver blank.

If we could do something to run the blank screensaver immediately.

But, That is not what I am trying to do.
Just turn off the montor of laptop.


Thanks and regards

Vish

That will ultimately die and give you the error. Quote
If we could do something to run the blank screensaver immediately.
Yes, that works.
Find or make a SCR file that does a blank screen. It would normally be in the  WINDOWS32 area. Create a shortcut to it, a LINK file.
In this example I will use ss3dfo.scr
I will make a shortcut Shortcut to ss3dfo.scr
I will place the shortcut in a place I like.
D:\BAT  and rename it to a shorter name : s3dfo.lnk
On the local machine the command is START  s3dfo
Code: [Select]
D:\BAT>ver

Microsoft Windows XP [Version 5.1.2600]

D:\BAT>start s3dfo

D:\BAT>


That DIR will have to be shared on the network.
I would have to issue a command for remote execution.
But let let somebody else tell you how to do remote execution over a local network.
I am getting tired and need more Coffee.He he he     


I already had that.
Already done with it.

I want to let you know that there is no screensaver for blank.
However,  I tried to workaround on it.

by using "ssmarque.scr"
config it to blank and background as black.

But still your monitor will remain in use. Even if there is black display or say no display.

Even if you use black  image things will be same.


So, may I take it as "no command for in dos to turn off display"


Cause if window can turn off the display. Then dos must be having this command somewhere hidden in his heart.


if you can perform detail check.

Please read under power usage.
I hope we can find something there.

Let's hope for best.

Thanks and regards

VishuYou are right.

It does not turn off the power to the screen...
   just makes it black.

But might be enough to...
  win a bet with your fellow workers in the office!
Quote
I hope we can find something there.
Without other software, you cannot force a monitor shut-off.

Sorry to disappoint.Note a problem.

You really rock!

You have a good name as well I really liked it

Carbondudeoxide

I have seen many of your replies that are really good.

I do respect your comments.

Thanks
203.

Solve : Dos String Search & Replace Columns?

Answer»

HI 
QUESTION, is it possible to do the following example with batch file commands?

Replace all lines that start with GOTO in a file starting with column 43 to 71 that CONTAINS spaces with three variables %%u %%v %%w
(-0.7478,  0.0141,  0.6638) then add BALANCE of line (PT     7) for example below!


Example;

                    FROM
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821                              PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              PT     8

                    TO
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821   -0.7478,  0.0141,  0.6638  PT     7
GOTO  /  419.47490,  -24.89781,   19.34762   -0.7478,  0.0141,  0.6638  PT     8you can download sed or gawk for windows,  then use these one liners
Code: [Select]C:\test>sed -i.bak "/^GOTO/s/PT/-0.7478,  0.0141,  0.6638  PT/" file
PPRINT  Vue      : second
GOTO  /  409.33480,  -18.96415,    7.79821                              -0.7478,  0.0141,  0.6638  PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              -0.7478,  0.0141,  0.6638  PT     8

or

Code: [Select]C:\test>gawk "/GOTO/{$5=\"-0.7478,  0.0141,  0.6638 \"$5}1" file
PPRINT Vue : second
GOTO / 409.33480, -18.96415, -0.7478,  0.0141,  0.6638 7.79821 PT 7
GOTO / 419.47490, -24.89781, -0.7478,  0.0141,  0.6638 19.34762 PT 8
Thanks!  But that one of my problems! I'm coverting my old Unix Script to DOS!  (32bit & 64bit issues) and would like current program to be DOS only! Quote from: graymj on July 31, 2010, 09:22:36 PM

Thanks!  But that one of my problems! I'm coverting my old Unix Script to DOS!  (32bit & 64bit issues) and would like current program to be DOS only!

what problem is that ? Most unix tools are ALREADY ported to GNU win32 packages . you can download them and use it. At least, you don't have to reinvent most of the wheels... 1. Will lines starting PPRINT always have 4 space delimited tokens?

Code: [Select]
   1     2       3   4
PPRINT  Vue      : second



2. Where are you getting those 3 variables to insert? In what form will they be? Do they change each line?

Example of source file below, I extract the variables i want to insert with the
cammand:

FINDSTR /B /N /I /C:"TLAXIS/" %DOSPATH%\%FILE% > vec.txt
  for /f "tokens=1-5 DELIMS= " %%t in (%DOSPATH%\vec.txt) do (
  set Y=%%t
   echo. Located Vector Value   %%u %%v %%w
      )

And I only need to insert %%u %%v %%w  on lines that start with goto!


PPRINT  Vue      :
PPRINT                MAX FILE SIZE = 90 MEG
PPRINT
PPRINT TLAXIS = AX= -0.7478     AY= 0.0141     AZ= 0.6638
PPRINT TOOL 226109
PPRINT
HEAD/ONE
LOADTL/ 226109
SPINDL/ 800
TLAXIS/ -0.7478,      0.0141,        0.6638
FROM/   .00000,      .00000,      1100.00000
RAPID
GOTO  / -476.19460,   -2.27892,  793.84030                              PT     5
RAPID
GOTO  /  390.63990,  -18.61189,   24.39274                              PT     6
FEDRAT/500
GOTO  /  409.33480,  -18.96415,    7.79821                              PT     7
GOTO  /  419.47490,  -24.89781,   19.34762                              PT     8
GOTO  /  420.12290,  -24.80300,   20.07566                              PT     9
GOTO  /  420.75380,  -24.55062,   20.78100                              PT    10Final text file should look like below!
also lines should not exceed 80 char!

PPRINT  Vue      :
PPRINT                MAX FILE SIZE = 90 MEG
PPRINT
PPRINT TLAXIS = AX= -0.7478     AY= 0.0141     AZ= 0.6638
PPRINT TOOL 226109
PPRINT
HEAD/ONE                                                               
LOADTL/ 226109
SPINDL/ 800
TLAXIS/ -0.7478,      0.0141,        0.6638
FROM/   .00000,      .00000,      1100.00000
RAPID
GOTO  / -476.19460,   -2.27892,  793.84030   -0.7478,   0.0141,  0.6638 PT     5
RAPID
GOTO  /  390.63990,  -18.61189,   24.39274   -0.7478,   0.0141,  0.6638 PT     6
FEDRAT/500
GOTO  /  409.33480,  -18.96415,    7.79821   -0.7478,   0.0141,  0.6638 PT     7
GOTO  /  419.47490,  -24.89781,   19.34762   -0.7478,   0.0141,  0.6638 PT     8
GOTO  /  420.12290,  -24.80300,   20.07566   -0.7478,   0.0141,  0.6638 PT     9
GOTO  /  420.75380,  -24.55062,   20.78100   -0.7478,   0.0141,  0.6638 PT    10
204.

Solve : backup command cannot copy huge files??

Answer»

it stop half way. and return insufficient memory error..
i use it to copy files to external HARD disk...

Code: [Select]echo off
:: variables
SET DRIVE=D:\2
SET date="%date:~6,4%-%date:~0,2%-%date:~3,2%"

set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up your Sites directory...
%backupcmd% "C:\1"  "%drive%\%date%"

echo BACKUP Complete - Your Backup is located at %drive%
pause
if TARGET medium has FAT file system max file size is (4 GB minus 1 byte)

If it says that there is insufficient space on the disk, then there is your problem. Your external hard drive is too small. Quote

backup command cannot copy huge files?

... the topic title is possibly ambiguous? Huge files or huge number of files?
huge files and also huge number of files and with many directories....
my ext hdd is enough, i tried windows copy method, successfully....
or maybe i need to separate copy by using more batch file?what filesystem does it have?
205.

Solve : Cleaning up the output of ping?

Answer»

I need a batch file that takes the output of ping and strips out the summary info and blank LINES, leaving just the individual times captured in a file.  For example, I want to turn this:

Pinging yahoo.com [69.147.125.65] with 32 bytes of data:

Reply from 69.147.125.65: bytes=32 time=100ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53

Ping statistics for 69.147.125.65:
    PACKETS: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    MINIMUM = 100ms, Maximum = 101ms, Average = 100ms

Into this:

Pinging yahoo.com [69.147.125.65] with 32 bytes of data:
Reply from 69.147.125.65: bytes=32 time=100ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53
Reply from 69.147.125.65: bytes=32 time=101ms TTL=53

Any ideas? Code: [Select] findstr /C:"Pinging" /C:"Reply" or using gawk for windows
Code: [Select]C:\test>ping localhost | gawk "/Pinging/||/Reply/"
Quote from: ghostdog74 on July 31, 2010, 11:52:47 PM

Code: [Select] findstr /C:"Pinging" /C:"Reply"

Thanks!  The findstr method is perfect, since I don't want to rely on gawk being installed.
206.

Solve : Inserting Blank Lines in a set of text files?

Answer»

Hi,

This being my first ever post, i would want to ask for some help with Dos/Batch file.

I have a set of 20 files in a Folder in my C Drive.
these files are plain text files, i want to add a Blank line at the end of these files.

I want to create a Bath file that can open these files and insert the Blank line at the end n save the file.

Is it possible? please help me out.. im a total newbie in this field..

Thanks alot for your help.can someone please help me out.. i really need to get this working

DAILY i have to edit 20 files or more.. If all you need is a blank line on the end of all files in a folder then type this in at the command line

Code: [Select]For %A in ("*.*") do Echo. >> %A
explanation available on request! Quote from: gpl on August 03, 2010, 05:01:01 AM

If all you need is a blank line on the end of all files in a folder then type this in at the command line

Code: [Select]For %A in ("*.*") do Echo. >> %A
explanation available on request!

Hi, thanks alot for ur reply.. yes for sure i would want an explanation as im not much into scri[pting so i really dont knw how to go about doin this.
please assist me.I get the impression that you are not sure even how to get to the command prompt ?

In the start menu, click on Run and then enter cmd and press return. If you find yourself using the command prompt a lot, then there is a useful microsoft tool that adds a new option to the right-click contect menu in windows explorer called 'Command Prompt Here' which opens up a command window in the selected folder http://gallery.technet.microsoft.com/ScriptCenter/en-us/d50e36fd-0454-4df1-aa35-3416f44789cc however as even microsoft do not guarantee this for VISTA or win 7, I would hold off for now.

When the command window opens, you need to go to the folder that you wish to process the files in:

Code: [Select]cd /d "x:\PATH\to my files"the x: refers to the disk drive the files are on (if a network drive, it needs to be mapped to a drive letter) and \path\to my files refers to the folder on the drive that contains the files. the quotes around the drive and folder name are important if the path might contain spaces, it doesnt hurt to include them. CD is the command to change directory (folder) the /d parameter tells it to change the drive too.

Now for the command I told you to type in ....
the first PART
Code: [Select]For %A in ("*.*") dosets up a loop to look at all of the files in the current folder (thats the *.* part). The %A is a variable that for each iteration will hold the filename.
The last part is what we do with each file
Code: [Select]Echo. >> %AEcho is used to send a message to the screen, however you can send the message to a file (or the printer or comm port) by using the > and >> 'redirection' symbols.
> will replace the file, while >> tacks the message on to the end.
Echo on its own give the (not very) useful message 'Echo is on' - or off. Adding the dot to the end makes it send a blank line
And thats all there is to it. I recommend that you try stuff out, read the various help guides on this site and others and come back when you are stuck.

Good luck
Graham
Thanks alot gpl

It has solved my problem!To follow up my previous post, I have stumbled across this with regasrd to opening a command window in Vista and I assume Win 7 also
"Open Command Window Here" in Vista
It is now easy to open a command prompt referenced to a folder of your choice in Vista. If the Shift key is held down while right-clicking a folder, the context menu will contain an entry, "Open Command Window Here". Selecting this entry will open a command prompt with the chosen folder as the reference point for commands.

You live and learn!!
207.

Solve : Random number 40-90?

Answer»

I have been looking for a batch who random chose a number 40-90, but I can't find any command who can specify a certain number. Why I want 40-90 is because I USE 1-25 already and the 25-39 I made SPACE if I'm going to use more numbers later.

Here is how I was thinking it should look like

Code: [Select]echo off
cls

Echo Text

//The random number goes here.

If  '40' Goto '40'
If  '41' Goto '41'

//Here would the random number from 40-90 go.
:40
echo Text
GOTO start

:41
echo Text
GOTO start

:start
set /p var=

I'm still learning how to use all batch commands, I just know the basics of it, but I would be grateful if anyone have the knowledge how can help me.I found this in the snippet closet. Just a few tweaks and it is made to order:

Code: [Select]echo off
setlocal

set intLowNumber=40
set intHighNumber=90

set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1)  + %intLowNumber%
echo Random number between %intLowNumber% and %intHighNumber% is %rnd%

FYI: use rem statements for comments; // are USED in other languages, not batch

Good luck. 
Thanks for the help, but I got to a other bummer I'm trying to get that the random number it create it then will go to a number,

Code: [Select]echo off
cls
setlocal

set intLowNumber=40
set intHighNumber=90

set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1)  + %intLowNumber%
%rnd% ((<=If that number is 40 then)) GOTO 40
%rnd% ((<=If that number is 41 then)) GOTO 41

But every time I try to do that I get "GOTO was unaccepted at this time" and then it kill it self, I have tried different commands but it still wont work...have you created the LABELS :40 and :41 for it to jump to ? Quote from: gpl on August 04, 2010, 04:12:19 AM

have you created the labels :40 and :41 for it to jump to ?

yes, I also have 40-90 Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40
%rnd% ((<=If that number is 41 then)) GOTO 41

Is this really part of your "code", Frejoh466? If so, I believe I know why your script keeps crashing.
Quote from: Frejoh466 on August 03, 2010, 01:51:22 PM
I'm still learning how to use all batch commands, I just know the basics of it, but I would be grateful if anyone have the knowledge how can help me.

since you have only just started, why not learn a programming language? A good programming language such as Python (and others) provides you programming concepts and constructs, such as arrays, hashes, dictionaries that every programmer should know and many more. Plus, it comes with modules/libraries that make programming easier and fun. Here's one way
to get random number in Python.

Code: [Select]import random
random_number=random.randrange(100)
if random_number < 40:
    print "do something"
elif random_number<90:
    print "do something"   


Quote from: Salmon TROUT on August 04, 2010, 04:46:41 AM
Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40
%rnd% ((<=If that number is 41 then)) GOTO 41

Is this really part of your "code", Frejoh466? If so, I believe I know why your script keeps crashing.


That is not what my code look like, my code is kinda long so I only use the part that don't work so it wont be that long...

I'm trying to use that code in this part,

Code: [Select]if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto unlock
if NOT EXIST Hide goto create
:lock
ren Hide "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
goto End
:unlock
echo Enter password to Unlock folder
set /p "pass=>"
if NOT %pass%==lol goto exit
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Hide
goto exit
:create
md Hide
goto exit

:exit
exit

note quote marks

Code: [Select]if NOT "%pass%"=="lol" goto exit Quote from: Salmon Trout on August 04, 2010, 05:22:48 AM
note quote marks

Code: [Select]if NOT "%pass%"=="lol" goto exit

But it work without the quotes. Quote from: Frejoh466 on August 04, 2010, 06:40:44 AM
But it work without the quotes.

Try pressing ENTER when it asks for the password.
Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on?
What do you think this line is going to do? (Line 6)

Code: [Select]goto End Quote from: Salmon Trout on August 04, 2010, 07:18:42 AM
Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on?


And this is why I only post the part that don't work... Ok forget my last post, I'm trying to use that random number the %rnd% create to go to the :40 or :41 etc.

so the number that %rnd% create it will goto

Hope this get through...Whatever it is you are trying to do, I am quite sure that there is a better way. Probably involving fewer lines! The computed goto is heavily frowned upon by programming experts. However if that is what you want...

(You can change intHighNumber and put in the label sections from 51 to 90 yourself. Notice that you do not need goto end after the last number because you are going there anyway.)

Code: [Select]echo off
set intLowNumber=40
set intHighNumber=50
set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1)  + %intLowNumber%
goto %rnd%

:40
echo number=40
goto end
:41
echo number=41
goto end
:42
echo number=42
goto end
:43
echo number=43
goto end
:44
echo number=44
goto end
:45
echo number=45
goto end
:46
echo number=46
goto end
:47
echo number=47
goto end
:48
echo number=48
goto end
:49
echo number=49
goto end
:50
echo number=50

:end
208.

Solve : need some help ..thx for sample !Z?

Answer»

hi guy!how i can create a batch file unhide items inside a specified drive...can give me some examples ?like if i TYPE String like unhide foldername



why do you need this?
You can use following command.


If it is a doc file


Code: [Select]attrib -h c:\path\file name


or


attrib -h c:\path\*.doc

it will work for sure.
if you want to unhide all HIDDEN files  within folder.


Code: [Select]attrib -h c:\path\*.*

You can use any drive just CHANGE C:
give it any drive name.


Give me raise for thanks.
It will work

Regards

vishu Quote from: SALMON Trout on AUGUST 03, 2010, 03:25:17 PM

why do you need this?


doing so experiment  .. Reply for your question.

Last on for unhiding all hidden files.
209.

Solve : Can a batchfile make another file to remember something??

Answer»

Hey guys, I was wondering if it's possible to make another FILE which stores something from the original batchfile so you can skip a part of the batch file? I think it's kinda annoying if you'd have to do that.
Lol I hope you understand...


Here's the code

Code: [Select]:1
IF EXIST "" "Save" GOTO 2
ECHO What Torrent Downloader are you using?
ECHO 1: µTorrent
ECHO 2: BitTorrent
ECHO 3: Vuze
ECHO 4: BitComet
ECHO.
ECHO If there is any other Client you are using, notify me
ECHO and I'll add it to the list ;)
ECHO.
SET /P L=Type your desired number and press ENTER:
IF %L%==1 SET TORRENT=%HOMEDRIVE%\Program Files\uTorrent\uTorrent.exe
IF %L%==2 SET TORRENT=%HOMEDRIVE%\Program Files\BitTorrent\bittorrent.exe
IF %L%==3 SET TORRENT=%HOMEDRIVE%\Program Files\Vuze\Azureus.exe
IF %L%==4 SET TORRENT=%HOMEDRIVE%\Program Files\BitComet\bitcomet.exe
---------------------
---------------------            < Other part of the file, not necessary
---------------------
ECHO Start %TORRENT%?
SET /P N=Type y [yes] or n [no], then press ENTER.
IF %N%==y GOTO SBIT
IF %N%==n GOTO FOX
GOTO BIT
:SBIT
ECHO.
Start "" /min "%TORRENT%"
ECHO.
ECHO %TORRENT% started minimized.
Yeah so what I'm trying to do is making this "Save" file somehow lol
Without it, this code is useless and I have to put the number each time I start the batch file... This is what I'm trying to avoid. Code: [Select]IF EXIST "" "Save" GOTO 2This is also not for one-time usage as you might understand. I'll also use this for other programs I want to start with this batch file and for future batch files also

I've also thought about doing IF EXIST but there is a possibility the user has multiple of these programs...

I really hope you guys can help

PS: Anyone has another torrent client I need to add? In a batch you can create a variable.
If you do not release the variable, it lives forever.

As I dimly recall, there was a Broadway show ...
where the programmer sang:

   "In a clear Batch.....
   ..variables forever..."

Quote from: Geek-9pm on August 05, 2010, 10:21:47 AM

In a batch you can create a variable.
If you do not release the variable, it lives forever.

As I dimly recall, there was a Broadway show ...
where the programmer sang:

   "In a clear Batch.....
   ..variables forever..."


Can you put an EXAMPLE please?

Thanks Code: [Select]:1
IF EXIST TorrentClientChoice.txt (
    set /p L=<TorrentClientChoice.txt
    GOTO loaded
    )
ECHO What Torrent Downloader are you using?
ECHO 1: µTorrent
ECHO 2: BitTorrent
ECHO 3: Vuze
ECHO 4: BitComet
ECHO.
ECHO If there is any other Client you are using, notify me
ECHO and I'll add it to the list ;)
ECHO.
SET /P L=Type your desired number and press ENTER:
>TorrentClientChoice.txt echo %L%
echo Preference %L% saved
:loaded
IF %L%==1 SET TORRENT=%HOMEDRIVE%\Program Files\uTorrent\uTorrent.exe
IF %L%==2 SET TORRENT=%HOMEDRIVE%\Program Files\BitTorrent\bittorrent.exe
IF %L%==3 SET TORRENT=%HOMEDRIVE%\Program Files\Vuze\Azureus.exe
IF %L%==4 SET TORRENT=%HOMEDRIVE%\Program Files\BitComet\bitcomet.exe
---------------------
---------------------            < Other part of the file, not necessary
---------------------
ECHO Start %TORRENT%?
SET /P N=Type y [yes] or n [no], then press ENTER.
IF %N%==y GOTO SBIT
IF %N%==n GOTO FOX
GOTO BIT
:SBIT
ECHO.
Start "" /min "%TORRENT%"
ECHO.
ECHO %TORRENT% started minimized. Quote from: Ghosty on August 05, 2010, 10:24:34 AM
Can you put an example please?

Thanks

He is joking.
Quote from: Salmon Trout on August 05, 2010, 10:36:50 AM
He is joking.

Lol...
No
To be honest not xD
I never learned this part of batch (until now)
I'm sorry

And thanks a lot for helping

PS: what was the double post for? Quote from: Ghosty on August 05, 2010, 11:23:52 AM
PS: what was the double post for?

What double post?
Quote from: Salmon Trout on August 05, 2010, 11:27:02 AM
What double post?


Lol
First I asked for an example. Then you posted the code which helped me
Then you posted that I was joking (which I wasn't) Quote from: Ghosty on August 05, 2010, 12:37:45 PM

Lol
First I asked for an example. Then you posted the code which helped me
Then you posted that I was joking (which I wasn't)

Do you have trouble understanding how quoting works in forums? I'll try to put it simply for you.

1. Geek-9pm posted in that "batch variables live forever". This is (obviously) not true, and I think he meant it as a joke. (not very funny in my opinion.)
2. You (Ghosty) quoted Geek-9pm saying that, and underneath asked for an example, and from that it seemed that you thought he was serious (now that is funny.)
3. I (Salmon Trout) quoted you (Ghosty) asking for an example, and wrote underneath that he (Geek-9pm) was joking.



Quote from: Salmon Trout on August 05, 2010, 12:55:34 PM
Do you have trouble understanding how quoting works in forums? I'll try to put it simply for you.

1. Geek-9pm posted in that "batch variables live forever". This is (obviously) not true, and I think he meant it as a joke. (not very funny in my opinion.)
2. You (Ghosty) quoted Geek-9pm saying that, and underneath asked for an example, and from that it seemed that you thought he was serious (now that is funny.)
3. I (Salmon Trout) quoted you (Ghosty) asking for an example, and wrote underneath that he (Geek-9pm) was joking.
Lol...
Oops

Oversaw that it was him and not you lol
SORRY MY FAULT I WENT through it too quickly

HOWEVER
You DID double post
Your first post was "He is joking." The post after that you made was the code Quote from: Ghosty on August 05, 2010, 01:08:29 PM
You DID double post

You don't KNOW what "double posting" is. It is when somebody makes the same post twice, sometimes in the same THREAD, by accident, or sometimes when they start two threads with the same first post. What I did was make two separate posts, which were different from each other.

Quote
Your first post was "He is joking." The post after that you made was the code

Actually, it was the other way around.
Quote from: Salmon Trout on August 05, 2010, 01:19:33 PM
You don't know what "double posting" is. It is when somebody makes the same post twice, sometimes in the same thread, by accident, or sometimes when they start two threads with the same first post. What I did was make two separate posts, which were different from each other.

Maybe in the forums where you post, but not in mine. When I post two different posts after each other in the same topic, they count it as double post.


Quote from: Salmon Trout on August 05, 2010, 01:19:33 PM
Actually, it was the other way around.

 True about that one lol... I was editing my post and it looked the other way around, I got somewhat confused (chatting with four people at the same time ) Quote from: Ghosty on August 05, 2010, 01:22:42 PM
Maybe in the forums where you post, but not in mine.

This is a "forum where I post", in case you hadn't noticed.


Quote from: Salmon Trout on August 05, 2010, 01:29:36 PM
This is a "forum where I post", in case you hadn't noticed.
It would be dumb from me not to notice that you posted here.
The point is that I'm used to the situation I wrote about the double post.

ANYWAY let's stop this crap this is entirely off-topic


I assume that there's a way to make more than one command in a single line.
For example Code: [Select]IF this=that, then do this AND this instead of putting the commands in multiple lines.You can use the ampersand & symbol to link multiple commands on the same line

Code: [Select]if "%var%"=="egg" echo yolk & echo white
210.

Solve : Looping in a PC .bat file:?

Answer»

Can any kind fellow help me write the Loop in my PC .bat file?

echo off
change user /install
pushd  \\servername\installlib\
Set Environment=
Set /P Environment=Environment Name DV DX PY PD PZ or PY: %=%

Set NumberOfUpdates=
Set /P NumberOfUpdates=Number of package updates ( Where A=1 and Z=26 ): %=%

Echo Updating %Environment%7333 Environment with %NumberOfUpdates% update packages:
Pause

Set Update1=%Environment%7333UGA
Set Update2=%Environment%7333UGB
.
.
.
Set Update26=%Environment%7333UGZ

For X = 1 to %NumberOfUpdates%
       Echo Now applying update: %UpdateX%
       C:\Setup.exe –s –p %UpdateX% -D d:\b7
NEXT X


change user /execute
PAUSE


My Scenario: I got to rollout 6 Environments across 4 servers each with between 10-20 updates. That’s about 300 updates, luckily I found out how to do it from the command line and not go through the silly GUI Click/Point/Browse path/SELECT/ double-click etc etc  for each update. Now I want to write a .BAT to make it even easier for next time.

Batch loop syntax

FOR %I in (start,stop,STEP) DO command

I usually put the loop commands themselves in their own batch file

FOR %I in (1,1,%NumberofUpdates%) DO UpdateMachine %I

One litlle 'gotcha' is then when using a FOR Loop IN the batch file, you put %I, but if exec from the command prompt directly you put %%I so that the "%I" get's passed to the 'FOR' and not the value of I

Clear as mud :-) Quote from: BradDet on August 02, 2010, 02:40:32 PM

Batch loop syntax

FOR %I in (start,stop,step) DO command

I usually put the loop commands themselves in their own batch file

FOR %I in (1,1,%NumberofUpdates%) DO UpdateMachine %I

One litlle 'gotcha' is then when using a FOR Loop IN the batch file, you put %I, but if exec from the command prompt directly you put %%I so that the "%I" get's passed to the 'FOR' and not the value of I

Clear as mud :-)

Yeah, that won't work...

Here, NewCNCguy, this code will do what you want:

For /l %%A in (1,1,%numberofupdates%) do (
       Echo Now applying update: %UpdateX%
       C:\Setup.exe –s –p %UpdateX% -D d:\b7
)
Quote from: BradDet on August 02, 2010, 02:40:32 PM
Batch loop syntax

FOR %I in (start,stop,step) DO command


BradDet, you are quite a new member. You need to be aware that posting like that is going to cause you to get posts like this that I am writing here now. You should check what you are posting, as that way you don't post stuff which is wrong and which does the opposite of helping. With command line keywords you can just type the command followed by a space and then a slash and a question mark. Here is an example

Code: [Select]FOR /?
You get several screens of help including this

Code: [Select]FOR /L %VARIABLE IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)
As you will note, this is a lot different from what you posted. To summarise: don't post off the top of your head, check it first, preferably running any code you are going to suggest. This should the minimum standard for posting help on CH. Anything less is low quality.

Why exactly is it "a lot different?"

I admit I left out the "/L" by mistake,

and technically if I run a batch in the command I should put "call program.bat" by after the do, but I wouldn't say it was "a lot different", just a typo.

I make typo's quite frequently actually, sorry if this causes too much confusion Quote from: BradDet on August 02, 2010, 04:45:49 PM
Why exactly is it "a lot different?"

I admit I left out the "/L" by mistake,

and technically if I run a batch in the command I should put "call program.bat" by after the do, but I wouldn't say it was "a lot different", just a typo.

I make typo's quite frequently actually, sorry if this causes too much confusion

It's a "lot different" in the sense that unlike a post that includes the /L it doesn't help the OP in their question, and is more likely to cause more issues and confusion. Without the /L, the standard for command is:

Code: [Select]for %%var in (set) do command

which is clearly quite a bit different from yours. therefore, if somebody tried your Speshul version that accidentally omitted the switch, they would not have a loop going from start to end by step, but rather a 3 item loop that executes with start, step, and then end. For example:

Code: [Select]for %P in (1,1,5) do echo %P


this gives us:

Code: [Select]C:\>for %P in (1,1,%numberofupdates%) do echo %P

C:\>echo 1
1

C:\>echo 1
1

C:\>echo 5
5

C:\>


Which is clearly "a lot different" then what was intended. The OP might then assume that they made a mistake of their own- or, in the worst case, not notice that only three of their 26 updates ran through and accept the solution. Then, later down the road, much to their chagrin they discover that for every update they performed, the first update was performed twice and the last update was performed once and all the others were ignored.

Quote from: BC_Programmer on August 02, 2010, 11:23:11 PM
It's a "lot different" in the sense that unlike a post that includes the /L it doesn't help the OP in their question

There is that, which is bad enough, but another thing just as bad in its way is this

Quote
(start,stop,step)

We would have to guess that he meant "(start, step, end)". Assuming when he wrote "stop" he meant "end", that's a completely different order.

It seems clear from his reply that he still does not see what is wrong with his attitude.





, and is more likely to cause more issues and confusion. Without the /L, the standard for command is:

Code: [Select]for %%var in (set) do command

which is clearly quite a bit different from yours. therefore, if somebody tried your Speshul version that accidentally omitted the switch, they would not have a loop going from start to end by step, but rather a 3 item loop that executes with start, step, and then end. For example:

Code: [Select]for %P in (1,1,5) do echo %P


this gives us:

Code: [Select]C:\>for %P in (1,1,%numberofupdates%) do echo %P

C:\>echo 1
1

C:\>echo 1
1

C:\>echo 5
5

C:\>


Which is clearly "a lot different" then what was intended. The OP might then assume that they made a mistake of their own- or, in the worst case, not notice that only three of their 26 updates ran through and accept the solution. Then, later down the road, much to their chagrin they discover that for every update they performed, the first update was performed twice and the last update was performed once and all the others were ignored.


[/quote]Ah... My misunderstanding,

You meant that the functional execution of was a lot different, which  I agree with.  I had thought you meant literally the statement itself was a lot different.

This is indeed a very beginner mistake on my part!

Computers will ALWAYS do you tell them to do,  not necessarily what you WANT them to do  It might be worth noting that

for /L %%N in (1,1,5) do something

is functionally equivalent to

for %%N in (1 2 3 4 5) do something

the difference being that if you explicitly list every item you can do stuff like this

for %%N in (1 2 2a 3 4 5 7 99 cat dog) do something




211.

Solve : How to send details of a file into excel sheet.?

Answer»

Hi All, 

I have a file CALLED Myfile.mdl. This file is located in some  LIKE D:\Folder_Name1\Folder_Name2\Myfile.mdl.

When we see the the details of this file We find out NMAE, Size, Type, Date Modified etc...

I want to extract only that date into one Excel file called Myexcel.xls.

I have tried with some code but its giving all the details of all directories and SUB directories, but I need only that file date in the excel sheet which is located in main directory.

Your help will be appriciated more.


Thanks in advance
SarayuThis question was asked and answered yesterday. Perhaps you missed it. Click

Quote

I have tried with some code but its giving all the details of all directories and sub directories, but I need only that file date in the excel sheet which is located in main directory.

If you want to help your own cause, you might consider posting your code. It wouldn't be very much help if I told you I wrote some code for your solution and then didn't post it.

As was previously mentioned you cannot update an Excel SPREADSHEET with batch code. You need to use a Windows script language that supports Excel as an object or supports an access method for the file.

 Well, unless it's a CSV file...
212.

Solve : Batch to get file name?

Answer»

Hi everyone.
Firstable I'll like to say sorry by my awful English.
Involved elements:
External USB hard disk
Windows 2003 Server R2 standar edition
Windows XP Professional SP3
Filezilla Server 0.9.33 beta
Blat 2.6.2
Directory monitor 1.0.1.23
What I do:
I have external hard disk connected to W2003 a shared. From XP I have a mapped this hard disk using UNC and this unit is for store files that people upload to FTP server.
I need make a bat that when new file start upload make these actions:
1.-Get file name
2.-Get FOLDER name
3.-Send a email with this data (file and folder name) using Blat
4.-When upload finished send email using Blat to inform that this file is READY to start download
I've done so far:
Using Directory monitor detect that a new file is start upload and call a bat that send me an email using Blat with Folder name in a subject.
This code works:
echo off
cd folderexample
for %%* in (.) do set VAR=%%~n*
for /f %%a in ('time/t') do set vartime=%%a
set body=-body "Test|Hello World"
set [email protected]
set [email protected]
set subj=-s "Test. FTP.%var%. New Files. %vartime%"
set server=-server smtp.example.com
set user=-u userexample
set pass= -pw passwordexample
C:\Bats\Blat\full\blat %0 -f %from% -b %to% %subj% %body% %server% %user% %pass%
Thanks in advance.

213.

Solve : How to get the last modified date of a file into a textfile?

Answer»

Hi all,

I am very poor in writting batch files, but I want to get the last modified date of a file into a text file.

Could you please PROVIDE me the code for that.



THANKS in advance
SarayuThis may help:

Code: [Select]echo off
for /f "skip=5" %%x in ('dir /tw drive:\path\filename.extension') do (
  echo %%x > text.file
  goto :eof
)

Be sure to change drive:\path\filename.extension to SOMETHING appropriate.

Good luck.  Alternatively
Code: [Select]for /f %%T in ('dir /b filename.ext') do echo %%~tT>text.fileHi,

I am MODIFYING the code and when I echo the results I get unwanted lines:

:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop)

The mod date echoes correctly but I get 2 extra lines after the date is ECHOED
[myfilename] 1
[myfilename] 0

How can I eliminate those last 2 lines?

Thanks in advance

Quote from: mcgriff1969 on August 06, 2010, 09:19:23 AM

Hi,

I am modifying the code and when I echo the results I get unwanted lines:

:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (echo %plantid%%wad%.dbf %%i Laptop)

The mod date echoes correctly but I get 2 extra lines after the date is echoed
[myfilename] 1
[myfilename] 0

How can I eliminate those last 2 lines?

Thanks in advance


What is your whole code? Quote
I am modifying the code and when I echo the results I get unwanted lines:

You may have modified the code to the point of breaking it. 

Code: [Select]:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (
  echo %plantid%%wad%.dbf %%i Laptop
  goto getout
)
:getout

The for statement creates a loop. The skip parameter only skipped lines in the beginning of the directory list. The remaining lines after the one you want to process must be skipped manually.

Good luck.  Quote from: Sidewinder on August 06, 2010, 12:09:55 PM
You may have modified the code to the point of breaking it. 

Code: [Select]:laptop
set localdrv=d:\workspaces
for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do (
  echo %plantid%%wad%.dbf %%i Laptop
  goto getout
)
:getout

The for statement creates a loop. The skip parameter only skipped lines in the beginning of the directory list. The remaining lines after the one you want to process must be skipped manually.

Good luck. 
Thanks.  It works like a charm!
214.

Solve : Batch Files and Quantum?

Answer»

I'm TRYING to create a batch file that runs the program, Quantum, then creates a table of content and combines them, but the file stops running after running quantum for the first TIME.  Do I have to do something different or special b/c it's not a windows-specific program?  Thanks for your help.Can we see your CODE?

Help us, so we can help you.right now all i have is...

quantum run data
tabcon -o toc


Whats HAPPENING is its running the first LINE fine, then it just stops.  no error message or anything, it just doesn't run the 2nd line.try
start quantum run data
tabcon -o tocthanks, but that didn't work

215.

Solve : Service ID's?

Answer»

Hello people, I was wondering if it is possible to start/stop/pause certain services (the ones listed in msconfig and services.msc) with CMD and you can (using the command Net Stop [ServiceName]). However, some process names are different on each computer as it has a different language.
So maybe I thought that each service has it's own ID number or something.

Thank you. They have names e.g. AntiVirService, AudioEndPointBuilder, and you can use the sc command to control them.


Quote from: SALMON Trout on August 07, 2010, 10:45:13 AM

They have names e.g. AntiVirService, AudioEndPointBuilder, and you can use the sc command to control them.
Hm ok, thank you.

I found out the short names of the services thanks to this WEBSITE.

Also, I want to make this automated, for example that when the batch starts the services again, that it won't start the services that weren't running when it stopped the other ones. Is this possible?

And last but not least, is there any way you can you disable the notification that it STOPS the service? (For either the SC or NET STOP command).

Thank youwhy don't you just play around a bit with sc and net and find out what you need to know?
Quote from: Salmon Trout on August 07, 2010, 11:30:56 AM
why don't you just play around a bit with sc and net and find out what you need to know?
I tried for over 30 minutes with both NET and SC... This site helped me but I couldn't find a command to make it work SILENT. It doesn't recognize /S either. Quote from: Ghosty on August 07, 2010, 11:40:02 AM
It doesn't recognize /S either.

Why should it? Did you think it would read your mind?



Quote from: Ghosty on August 07, 2010, 11:40:02 AM
I couldn't find a command to make it work silent.

>nul
Quote from: Ghosty on August 07, 2010, 11:40:02 AM
I tried for over 30 minutes with both NET and SC...

And you think that's a long time?

Quote from: Salmon Trout on August 07, 2010, 11:49:18 AM
>nul
Thank you

Quote from: Salmon Trout on August 07, 2010, 11:50:22 AM
And you think that's a long time?
No but I've tried hard and looked everywhere (lots, lots of /? commands in CMD, this website, other websites...)

Quote from: Salmon Trout on August 07, 2010, 11:43:55 AM
Why should it? Did you think it would read your mind?
I had to say something...


OK I guess this is solved. Thank you very much
216.

Solve : Editting a file using a batch file?

Answer»

I changed jobs and had to switch from doing my job in LINUX to windows, and don't have much experience writing batch files. 

The part I can't figure out is how to remove all instances of a string ('CCE1', for example) from a specific file.  Could someone help me out, thanks!Please give "before and after" EXAMPLES
Quote from: kramer4717 on August 06, 2010, 11:56:00 PM

I changed jobs and had to switch from doing my job in linux to windows, and don't have much experience writing batch files. 

The part I can't figure out is how to remove all instances of a string ('CCE1', for example) from a specific file.  Could someone help me out, thanks!

since you have  linux experience, i am sure you know about *nix tools like sed, tr etc ? They have been ported to windows. you can download sed , then simply

Code: [Select]c:\TEST&GT;  sed -i.bak "s/CCE1//g" file
217.

Solve : Create file with different User name?

Answer»

Hi folks,

I am try to create a form that will create a XLS file in netowork DRIVE so that everyone can access it.

WANT to save the file with different username.

LIKE mine is vishu.xls
if any other user use the form that will create the file with different user name like maxy.xls

Code:

echo off
color f0
mode 50,30
Title HP Sales tracker


echo **********this is a form for all the users*************

echo Customer name      Phone number      Printer      Service ticket      Lead>>

"\\ndokfs03\chat\agent data\vishu.xls"

:1
Echo please enter the following details
echo.
:cn
set /p "cust_name= Pleaser enter customer name : "
if not defined cust_name goto :cn
echo.
:pn
set /p "ph_no= Pleaser enter Phone number: "
if not defined ph_no goto :pn
echo.
:pr
set /p "printer= Pleaser enter Printer: "
if not defined printer goto :pr
echo.
:s
set /p "st= Pleaser enter Service ticket: "
if not defined st goto :s
echo.
:ld
set /p "lead= Pleaser enter lead number: "
if not defined lead goto :ld



echo. >>sales.doc
echo %cust_name%      %ph_no%      %printer%      %st%      %lead%>> "\\ndokfs03\

chat\agent data\vishu.xls"



cls
:mo
set /p "mo= Do you want to add more details? y or n"
if not defined mo goto :mo
if "%mo%"=="y" goto :1
else EOF:


Thanks and regards

VishuIs this going to be used on multiple computers or profiles?

If it is, just save it as %username%.xls

If not though, you can have the user enter the name with a code like this:

Code: [Select]SET /p _username=""
ECHO %Variables%>>%_username%.xlsThank you.

Tired was not working.

But it is working now.

Please let me know if I can change font size?To my knowledge, no. You can't change the font size with a batch file.I mean dos font size.

I want to format my form.You can change the default font and font size for all command prompt windows by clicking the icon at the top left CORNER of the window and choosing "Properties" and then "Font". You cannot change the font type or size programmatically.
Is there any command. I want it to be clanged by command. Quote from: vishuvishal on August 06, 2010, 05:15:45 PM

Is there any command. I want it to be clanged by command.

He just said you couldn't.

This is like talking to first tier HP product support!
218.

Solve : I need a log after execution of my batch script. Please help!?

Answer» Hello, I have a script, GREG gave me I think. The BATCH script copy all the files from drives, for example if I want to copy all JPEG from D DRIVE, it copies all of JPEGs from D drive and so on. The thing I am looking for is when the script COMPLETES copying, I need a log showing this many files where copied on this date and time. Can anyone help me in this please. Down is the code of my script.



Code: [Select]echo off
SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
set searchdrive="E:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop%
set searchdrive="E:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop%
set searchdrive="E:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop%
set searchdrive="F:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop%
set searchdrive="F:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop%
set searchdrive="F:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop%
set searchdrive="D:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop%
set searchdrive="D:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop%
set searchdrive="D:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop%
set searchdrive="G:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop%
set searchdrive="G:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop%
set searchdrive="G:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop%
set searchdrive="E:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop%
set searchdrive="F:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop%
set searchdrive="D:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop%
set searchdrive="G:\"
for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop%



If the script is copying from D, E, F, and G drive, I need four different log sheet with copied file details.


C:\\test>type   logcp.bat

rem Use with command line arguments
rem Usage: logcp.bat  c:\\  xls
rem I used echo for copy. ( you must replace. )

echo off
set /a cnt=0
SETLOCAL EnableDelayedExpansion
set destfolder=D:\\copiedjpegs
set searchdrive=\"%1\"
for /f \"delims=\" %%i in (\'dir %searchdrive%*.%2 /s /b\') do (
echo %%i
set /a cnt=!cnt! + 1
)
echo cnt=%cnt% >  cplog.log
echo %DATE%  %TIME%   >>  cplog.log
echo type cplog.log
type cplog.log


C:\\test>logcp.bat   c:\\  xls

C:\\test>rem Use with command line arguments

C:\\test>rem Usage: logcp.bat  c:\\  xls

C:\\test>rem I used echo for copy. ( you must replace. )
c:\\Office2003SP3Changes\\Office2003_SP3Changes.xls
c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\PROTTPLN.XLS
c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\PROTTPLV.XLS
c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\XL8GALRY.XLS
c:\\Program Files\\Microsoft Office\\OFFICE11\\SAMPLES\\SOLVSAMP.XLS
c:\\Program Files\\Microsoft Office\\Office12\\1033\\PROTTPLN.XLS
c:\\Program Files\\Microsoft Office\\Office12\\1033\\PROTTPLV.XLS
c:\\Windows\\Installer\\$PatchCache$\\Managed\\9040211900063D11C8EF10054038389C\\11.0.5614\\XL9GALRY.XLS_1033
c:\\Windows\\ShellNew\\EXCEL9.XLS
type cplog.log
cnt=9
Sat 08/07/2010  15:55:41.82
C:\\test>I had too many \\ backslashes with my IE8 Browser above. I used echo for copy below.
You must CHANGE echo to copy and use source and destination.

219.

Solve : delete subdirecttory folder only?

Answer»

nice day!
CODE PLS. in deleting a SPECIFIC folder?

thanks in advance!RMDIR Foldername

For more information, LOOK at RMDIR /?

220.

Solve : How to create .bat files which create filelistings?

Answer»

Hi,

I've got no experience with batch files to speak of and want to create batch files which list the contents of my folders. I've been looking around and found d quite a few examples, some of which I tried with (some) success...I found that some different commands seem to give the same result, and others I recombined which then didn't work the way intended. So I now want to make a list with most or all the relevant commands (\a, \b and so on) and their values or results. I also would like to know if they are freely combinable or not. I've been searching the web but only come up with (sometimes conflicting) bits and pieces and would appreciate any kind of help. Are there any e-books on the subject or is anyone willing to tell me a bit? 

I'm not familiar with DOS or anything, only use Windows and other progs. But I know how to install OS and arm PCs and stuff like that...

Thanks a lot in advance!Use  only one \\  where two appear

C:\\test>type  ch88.bat

echo off

dir *.*  %1

Output:

C:\\test>ch88.bat  c:\\test 
 Volume in drive C has no label.
 Volume Serial Number is 0652-E41D

 Directory of C:\\test

08/08/2010  05:24 PM              .
08/08/2010  05:24 PM              ..
05/27/2010  07:21 PM              !Grants
07/08/2010  02:58 PM                 8 07072010timeclock.csv
07/08/2010  02:58 PM                 8 07082010timeclock.csv
07/25/2010  04:43 PM                14 1.txt
07/25/2010  04:44 PM                14 10.txt
07/25/2010  04:46 PM                14 11.txt
07/25/2010  04:46 PM                14 12.txt
07/25/2010  04:46 PM                14 13.txt
07/25/2010  04:47 PM                14 14.txt
07/25/2010  04:47 PM                14 15.txt
.
.
.Thanks a lot, Victoria

Couldn't do much with it, though...don't understand enough.
I'll post some of the info I have to let you know what it is I'm after:


A list of commands I'd like to complete as much as possible (and, of course, check for errors):

/a                    = read ALL files in folder (a = archivable files)
:d                    = directories only
-d                    = don't list the archive date/time
/s                    = include files from sub-folders
/b                    = exclude unnecessary file information such as filesize and stuff (b = bare names only)
>                     = go to the following folder (sends the output to a file instead of displaying it on the screen)
"...."                 = direction of folder to use
\.mp3               = only list .mp3 files (exclusive command for type of files to list)
:gen                 = generate



And some of the examples I have gathered and tried (but not all successfully):

dir /a /s /-p /o:gen >filelisting.txt

dir /a /b /s /-p /o:gen >filelisting.txt

dir /a /b /s /-p /o:gen >C:\Temp\filelisting.txt
start notepad C:\Temp\filelisting.txt



So, what I wanted was to print a list of all my musicfiles - some 40.000 spread over Alphabetical folders with subfolders for groups and sub-subfolders for their discs. I've managed that, but wanted to clean up the process so I only get the archives names without all the other info (like timestamps and so on)...

Then I wanted to make that command part of the Explorer Context Menu (in Win7 apparently you need programs for that, I tried Context Menu Editor but it doesn't quite work - maybe it's not 64-bit compatible or maybe I need to do sth. differently) so that I can right-click over any folder and have it's contentslist saved in a dedicated folder - and open automatically afterwards...

But, although I'd appreciate a working commandline(s) for that purpose, I now also would like to understand the whole thing a bit better - that's why I'd like a list of commands and so on. Maybe I'm a bit over the top with that one - or it's just not as simple a matter as I imagine it to be and requires proper study. But, anyway....

Thanks a lot again
http://www.robvanderwoude.com/batchcommands.php



C:\\>dir /?
Displays a list of files and subdirectories in a directory.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               I  Not content indexed files
               L  Reparse Points             -  Prefix meaning not
  /B          Uses bare format (no heading information or summary).
  /C          Display the thousand separator in file sizes.  This is the
              default.  Use /-C to disable display of separator.
  /D          Same as wide but files are list sorted by column.
  /L          Uses lowercase.
  /N          New long list format where filenames are on the far right.
  /O          List by files in sorted order.
  sortorder    N  By name (alphabetic)       S  By size (SMALLEST first)
               E  By extension (alphabetic)  D  By date/time (oldest first)
               G  Group directories first    -  Prefix to reverse order
Press any key to continue . . .



C:\\>dir /AD  /w
 Volume in drive C has no label.
 Volume Serial Number is 0652-E41D

 Directory of C:\\

[$Recycle.Bin]              [06-07-2010]                [1]                         [1100]                      [20100419]
[backup]                    [BILL-PC]                   [bin]                       [destfiles]                 [Documents and Settings]
[LaserJet517]               [logs]                      [MSOCache]                  [Office2003SP3Changes]      [PerfLogs]
[prison]                    [PROGRAM Files]             [ProgramData]               [RECENTBKUP]                [Recovery]
[System Volume Information] [temp]                      [test]                      [tmp]                       [Users]
[Windows]                   [zz]
               0 File(s)              0 bytes
              27 Dir(s)  293,475,434,496 bytes free

C:\\>

google  .wav  extention
C:\\>dir  /s  *.wav  |  more
 Volume in drive C has no label.
 Volume Serial Number is 0652-E41D

 Directory of C:\\Program Files\\Microsoft Office\\MEDIA\\CAGCAT10

03/10/1998  09:02 PM            22,618 ELPHRG01.WAV
02/16/1999  09:50 PM            26,810 J0214098.WAV
               2 File(s)         49,428 bytes

 Directory of C:\\Program Files\\Microsoft Office\\OFFICE11

02/19/2003  01:05 PM           108,800 REMINDER.WAV
               1 File(s)        108,800 bytes

 Directory of C:\\Windows\\Installer\\$PatchCache$\\Managed\\9040211900063D11C

02/19/2003  01:05 PM           108,800 REMINDER.WAV
               1 File(s)        108,800 bytes

 Directory of C:\\Windows\\Media

06/10/2009  04:22 PM           216,364 chimes.wav
06/10/2009  04:22 PM           113,964 chord.wav
06/10/2009  04:22 PM            70,060 ding.wav
06/10/2009  04:24 PM           118,060 ir_begin.wav
06/10/2009  04:24 PM           126,252 ir_end.wav
06/10/2009  04:24 PM           178,732 ir_inter.wav
06/10/2009  04:22 PM           228,396 notify.wav
06/10/2009  04:22 PM           111,788 recycle.wav
06/10/2009  04:22 PM            88,236 ringout.wav
06/10/2009  04:37 PM           153,644 Speech Disambiguation.wav
06/10/2009  04:37 PM            71,212 Speech Misrecognition.wav
06/10/2009  04:37 PM           188,460 Speech Off.wav
06/10/2009  04:37 PM           147,500 Speech On.wav
06/10/2009  04:37 PM           128,812 Speech Sleep.wav
06/10/2009  04:22 PM           285,228 tada.wav
06/10/2009  04:22 PM           178,220 Windows Balloon.wavHey,
Thanks a lot, Victoria, for your help!
I'll need to get some sleep now - gotta organize my employees tomorrow early on - but will follow up all your info as soon as I can.
I'll post another reply after to let you know!

ManasaOK, Victoria -

I'm still quite busy with work and stuff - so I haven't tried anything yet. But your list has been usefull, as well as the link you posted. I think that I will simply have to get some e-book or tutorial and learn the stuff from scratch.
Given that I started something (albeit nothing important, really) I just don't like not understanding what I'm doing.

Thanks again for your help
C:>help
For more information on a specific command, type HELP command-name
ASSOC          Displays or modifies file extension associations.
ATTRIB         Displays or changes file attributes.
BREAK          Sets or clears extended CTRL+C checking.
BCDEDIT        Sets properties in boot database to control boot loading.
CACLS          Displays or modifies access control lists (ACLs) of files.
CALL           Calls one batch program from another.
CD             Displays the name of or changes the current directory.
CHCP           Displays or sets the active code PAGE number.
CHDIR          Displays the name of or changes the current directory.
CHKDSK         Checks a disk and displays a status report.
CHKNTFS        Displays or modifies the checking of disk at boot time.
CLS            Clears the screen.
CMD            Starts a new instance of the Windows command interpreter.
COLOR          Sets the default console foreground and background colors.
COMP           Compares the contents of two files or sets of files.
COMPACT        Displays or alters the compression of files on NTFS partitions.
CONVERT        Converts FAT volumes to NTFS.  You cannot convert the
               current drive.
COPY           Copies one or more files to another location.
DATE           Displays or sets the date.
DEL            Deletes one or more files.
DIR            Displays a list of files and subdirectories in a directory.
DISKCOMP       Compares the contents of two floppy disks.
DISKCOPY       Copies the contents of one floppy disk to another.
DISKPART       Displays or configures Disk Partition properties.
DOSKEY         Edits command LINES, recalls Windows commands, and
               creates macros.
DRIVERQUERY    Displays current device driver status and properties.
ECHO           Displays messages, or turns command echoing on or off.
ENDLOCAL       Ends localization of environment changes in a batch file.
ERASE          Deletes one or more files.
EXIT           Quits the CMD.EXE program (command interpreter).
FC             Compares two files or sets of files, and displays the
               differences between them.
FIND           Searches for a text string in a file or files.
FINDSTR        Searches for strings in files.
FOR            Runs a specified command for each file in a set of files.
FORMAT         Formats a disk for use with Windows.
FSUTIL         Displays or configures the file system properties.
FTYPE          Displays or modifies file types used in file extension
               associations.
GOTO           Directs the Windows command interpreter to a labeled line in
               a batch program.
GPRESULT       Displays Group Policy information for machine or user.
GRAFTABL       Enables Windows to display an extended character set in
               graphics mode.
HELP           Provides Help information for Windows commands.
ICACLS         Display, modify, backup, or restore ACLs for files and
               directories.
IF             Performs conditional processing in batch programs.
LABEL          Creates, changes, or deletes the volume label of a disk.
MD             Creates a directory.
MKDIR          Creates a directory.
MKLINK         Creates Symbolic Links and Hard Links
MODE           Configures a system device.
MORE           Displays output one screen at a time.
MOVE           Moves one or more files from one directory to another
               directory.
OPENFILES      Displays files opened by remote users for a file share.
PATH           Displays or sets a search path for executable files.
PAUSE          Suspends processing of a batch file and displays a message.
POPD           Restores the previous value of the current directory saved by
               PUSHD.
PRINT          Prints a text file.
PROMPT         Changes the Windows command prompt.
PUSHD          Saves the current directory then changes it.
RD             Removes a directory.
RECOVER        Recovers readable information from a bad or defective disk.
REM            Records comments (remarks) in batch files or CONFIG.SYS.
REN            Renames a file or files.
RENAME         Renames a file or files.
REPLACE        Replaces files.
RMDIR          Removes a directory.
ROBOCOPY       Advanced utility to copy files and directory trees
SET            Displays, sets, or removes Windows environment variables.
SETLOCAL       Begins localization of environment changes in a batch file.
SC             Displays or configures services (background processes).
SCHTASKS       Schedules commands and programs to run on a computer.
SHIFT          Shifts the position of replaceable parameters in batch files.
SHUTDOWN       Allows proper local or remote shutdown of machine.
SORT           Sorts input.
START          Starts a separate window to run a specified program or command.
SUBST          Associates a path with a drive letter.
SYSTEMINFO     Displays machine specific properties and configuration.
TASKLIST       Displays all currently running tasks including services.
TASKKILL       Kill or stop a running process or application.
TIME           Displays or sets the system time.
TITLE          Sets the window title for a CMD.EXE session.
TREE           Graphically displays the directory structure of a drive or
               path.
TYPE           Displays the contents of a text file.
VER            Displays the Windows version.
VERIFY         Tells Windows whether to verify that your files are written
               correctly to a disk.
VOL            Displays a disk volume label and serial number.
XCOPY          Copies files and directory trees.
WMIC           Displays WMI information inside interactive command shell.

For more information on tools see the command-line reference in the online help.

C:\\>
Victoria, could you explain the reason you posted that cat picture? Have you read the forum rules?
Quote from: Salmon Trout on August 11, 2010, 03:23:57 PM

Victoria, could you explain the reason you posted that cat picture? Have you read the forum rules?


No, I have not read any rules about Cats.  Where do I read about Cats?

•Make posts / comments that only relate to the original question / topic.

I cannot DELETE the Cat Picture.  Time ran out.

Quote
No, I have not read any rules about Cats.  Where do I read about Cats?

How is that Bill has been back more than a week and nothing has been done?

very convincing, Bill.
Quote from: Manasito on August 09, 2010, 05:50:22 PM
I haven\'t tried anything yet. But your list has been usefull, as well as the link you posted.

Manasito,

Im sorry the Thread got off topic.

You should now have a better understanding how to list your folders, music files and other files.

Good Luck

Ignore the off topic posts that offer no suggestions of how to list your files.

dir /?

221.

Solve : Generate Ping Test Report?

Answer»

Hi all,

I'm a beginner of Dos Command.

I would like to WRITE a batch file to GENERATE a ping TEST report.

echo %date% %time%
ping www.netvigator.com -n 200

I can run the above command in the command promt, but after I save it on the .bat file, it cannot run PROPERLY, it seems loop continuous...

Is dos command support to generate the content to a txt file?well what "loop" are you experiencing?

the ping is set to keep pinging untill it hits 200.

CODE: [Select]-n count       Number of echo requests to send.

can you explain more of what is happening?You can make a report of ping.


Code: [Select]echo %date% %time%>>"c:\report.log"
ping www.netvigator.com -n 200 >>"c:\report.log"

You can change the path as per your requirement.

I hope you are happy


 

Thanks and regards
Vishu

222.

Solve : error command?

Answer»

Hi,

I am making a script file in wich a part of the script is formating my SD-card.
this works perfectly, but i also want to make sure its save to do without formating a wrong drive letter.

could any1 help me with a COMMAND line wich works as this:
if targeted drive for formating is lower then 2G of HD space (not free space but total space) give error and move back to the menu.

thanks in advance
-Nickhttp://www.ehow.com/how_4793481_reformat-sd-card.html

( The OS detects automatically  the drive where the SD card is ). A different drive letter might be assigned on occasion but will not interfere or effect the format procedure.) The card should work on a VARIETY of machines and slots.) By the way, the card should be formatted and ready out of the box. Do not format if not necessary

Good Luck

•Turn on your computer and put the SD card into the card reader slot on the front of your computer or the external card reader attached to a USB port. Wait to see if your operating system automatically opens a window prompting you for information. Click on the option to Open a folder to view files if the window pops up.

•Step 2
Click on the Start button if your operating system does not automatically prompt you to open a folder. Choose the My Computer option to bring up a new window.

•Step 3
Right-click on the drive bay for your card reader, and then choose the option that says \"Reformat\" from the pop-up menu. Click on the option to set the formatting to \"FAT16\" if you receive a separate pop up window asking you which file system to set the card to.



Read more: How to Reformat an SD Card | eHow.com http://www.ehow.com/how_4793481_reformat-sd-card.html#ixzz0wK41qMQW

p.s.  The 2G or 4G refers to the space on the stick not the space of the Drive Slot. Some sticks can be formatted for more bytes on the same stick. Be careful. Ask a buddy who knows.

223.

Solve : Want to delete history using bat?

Answer»

Please help


I am trying to create the bat that will delete all the following concern folders and files.

I want to delete my history on my user profile.
And want to delete folders inside application data for LOCAL settings.
And outside local settings.
I also want to delete temporary internet files using batch


Code: [Select]del /f /q %temp%
cd..
cd application data
rd /s /q mozilla
cd..
deltree application data
cd termporary internet files
del /f /q *.*
cd..
cd history
del /f /q *.*

del /f /q userdata



Thanks and regards
vishuthat is not a good idea a lot of programs will not work if you run that. Quote from: mat123 on August 10, 2010, 08:48:24 AM

that is not a good idea a lot of programs will not work if you run that.

Why? Give details.
deltree application data
programs store info in that folder. the info is  required to run Quote from: mat123 on August 10, 2010, 11:15:10 AM
deltree application data
programs store info in that folder. the info is  required to run

Absolutely correct. Deleting that folder is a quick ROUTE to a screwed up Windows system.
the given program will not work on any Windows OS.

Deltree is not a command on Windows NT systems, and windows 9x (which has deltree) doesn't have an application data folder in the user's profile directory. Which isn't relevant anyway, because command.com by default starts in the desktop folder. (C:\Windows\Desktop). Secondly, because deltree's arguments aren't quoted, it won't delete an "Application Data" folder even if one existed, it would instead delete files named either "Application" or "data" or folders with that name. that and the cd command on 9x doesn't requires quotes to CHANGE to any path with a space in it.

That COMBINED with the fact that even if there was some screwy OS configuration whereby that would work, it still wouldn't doo the steps claimed.I am THINKING if I could add exception to delete folder that is newly created after basic folder like microsoft, sun, adobe etc. Please let me know if I can manually add exception not to delete these folder. Rest I can.

Thanks and regards
vish
224.

Solve : Dosmand command sys a?

Answer»

the dos command sys a puts which files on a floppy diskis this your homework?
QUOTE from: Salmon Trout on August 18, 2010, 12:17:48 PM

is this your homework?

Probably. Purely because of the way he asked the question, sounds like the wording on an exam or something.No seeking knowledge about unix permissions and windows Dos commands   using a PC might buy a mac soon Quote from: minkah on August 19, 2010, 04:44:38 AM
No seeking knowledge about unix permissions and windows Dos commands

This has nothing to do with Unix, and is a little bit esoteric. Additionally, the files placed on the disk will differ depending on what version you are RUNNING.

Quote
   using a pc might buy a mac soon

yes. I see. "I want to learn DOS commands because I am going to be getting a mac". Right. Stellar ASSOCIATIVE reasoning there.
225.

Solve : Batch File to delete content within a folder?

Answer»

The FOLDER will be name "Scans" but I need the CONTENT to be deleted within the folder and ALSO I need it to run when the computer starts up. How do I write a batch file for this, some examples? Thanks.Easy


make a batch file open notepad enter the codes save it as del.bat and copy it to STARTUP folder.


Code: [Select]echo off
Del "drive:\path\scans\*.*"
echo   *** *** *** &&&& ||  || 
echo *** *** *** &&_ ||__||
echo   ***  *** ***   && ||  ||
echo    ***** *** &&&& ||  ||
echo ________________________________________
echo
echo Files are being deleteing will take very short time.


ping -n 1 -W 5000 1.1.1.1 >nul


please let me know the path or destination folder address. Change it by your self.

All set.

Thanks and regards
vishuThanks I will try.vish do you now that will

Code: [Select]echo   *** *** *** &&&& ||  || 
echo *** *** *** &&_ ||__||
echo   ***  *** ***   && ||  ||
echo    ***** *** &&&& ||  ||
echo ________________________________________
will contain plenty of syntax errors

226.

Solve : Push commands from a batch file to another open cmd window??

Answer» HI All,

(OS Win XP)

This might sound a little outlandish, but I wondered if it was possible.  I have googled it to death so I guess this is not the case.  You lovely people might prove me wrong!!   I can push commands to another BATCH file using echo , but my problem is the cmd window I want to use is created by a vbs. 

Hmmmm, a quandary.

Any advice would be most welcome.

Thanks in advancePost  the CODE you used?Hi, yes I should have done that, I've kind of gone down the vbs route as I REALISED I needed to objectify the cmd window, but still no joy.

First I open a cmd window with:-

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "adminconsole.svb"

The adminconsole.svb routine opens a cmd window and this is the one I want to use to push commands into onto the command line.

I've tried .Exec but this does nort work.
oshell.Exec "EMSWrapperInstall.bat" as I guess it's the wrong object.

I think this post is now a vbs post so APOLOGIES for it being the wrong placeFound the vbscript solution which runs a script that produces a window:-

CreateObject("Wscript.Shell").Run "adminconsole.svb", 0, False

Dim oshell
Set oshell = CreateObject("WScript.Shell")
oshell.Run "cmd.exe"

Do Until oshell.AppActivate("Admin C:\WINNT\System32\cmd.exe")
Loop

oshell.SendKeys "EMSWrapperInstall.bat{enter}"   

The Do Until finds the one you want via the title bar, so a distinctive title bar is required in your cmd session that is created from the adminconsole.svb.  Then I can sendkeys to that cmd box!!

HURRAH!!!   

Please feel free to move this thread to vbscript.
227.

Solve : How to capture batch commands?

Answer»

I have a batch file which performs some commands, how can i capture all the commands its performing in to a text file. Any help is highly APPRECIATED
C:test>type  capture.bat
echo off
date /t >  capture.txt
time  /t >>  capture.txt

help   >>  capture.txt
echo.

echo type capture.txt
type capture.txt  |  more

Output:
C:test>capture.bat


type capture.txt
Wed 08/11/2010
03:38 PM
For more information on a specific command, type HELP command-name
ASSOC          Displays or modifies file extension associations.
ATTRIB         Displays or changes file attributes.
BREAK          Sets or clears extended CTRL+C checking.
BCDEDIT        Sets properties in boot database to control boot loading.
CACLS          Displays or modifies access control lists (ACLs) of files.
CALL           Calls one batch program from another.
CD             Displays the name of or changes the current directory.
CHCP           Displays or sets the active code page number.
CHDIR          Displays the name of or changes the current directory.
CHKDSK         Checks a disk and displays a status report.
CHKNTFS        Displays or modifies the checking of disk at boot time.
CLS            Clears the screen.
CMD            Starts a new instance of the Windows command interpreter.
COLOR          Sets the default console foreground and background colors.
COMP           Compares the contents of two files or sets of files.
COMPACT        Displays or alters the compression of files on NTFS partitions.
CONVERT        Converts FAT volumes to NTFS.  You cannot convert the
               current drive.
COPY           Copies one or more files to another location.
DATE           Displays or sets the date.
DEL            Deletes one or more files.
OR you can do it the easy way and use redirection on the command line when you launch the file:

Code: [Select]batfile.bat > capture.txt

batfile.bat >> capture.txt

Using a single redirection symbol will create a new file or overwrite an existing file.
Using a double redirection symbol will create a new file if it does not exist or append to an existing file.

FYI: If the batch file contains prompt(s), they will be unseen by the user but there will still be a wait for input on the console. This may lead to laughable unpredictable results.

GOOD luck. Thank you sidewinder and victoria for both of your replies.

I used the single pipe batfile > capture.txt

However something strange is happening here. I am executing ftp commands in my bat file. the last but one is the SUPPOSED to download a file. Now when I run the bat file directly i see something like this

ftp> 20mb file transferred in 20.68 seconds 876.877kbytes/sec
ftp> quit

but when the output is written in to the text file i see

ftp> 20mb file transferred in  seconds kbytes/sec
ftp> 20.68876.877 quit

Both the seconds and kbps are written on the quit command line. Which i dont understand why. Any input is highly appreciated.
Not really sure, but the FTP command places you in another environment. I'm surprised you GOT any output from the FTP commands. In any case it seems like the carriage return/line feed characters are not being written properly which may have to do with the media (console vs. disk)

Try redirecting the FTP command output from within the batch file in addition to the redirection at the command line. Sometimes you just have to tweak the code until it works.

Good luck.  Quote from: dmog on August 11, 2010, 03:26:05 PM

I used the single redirect batfile > capture.txt

ftp> 20mb file transferred in  seconds kbytes/sec
ftp> 20.68876.877 quit

Both the seconds and kbps are written on the quit command line. Which i dont understand why. Any input is highly appreciated.


ftp> transfer   
ftp>echo.


ftp>echo  quit

Rem  Between the command that does the transfer and the command to quit

Rem Use echo.  echo. places  a blank line

( also a redirect > of each command MIGHT fix the problem. )

p.s. a pipe | and a redirect >>  are two different procedures. A pipe |  sends
the output to another program as the input.  Redirect >> goes to a text file.
228.

Solve : Need Help Debugging DOS Script?

Answer»

I have the batch file below.  Basically, if I login the batch file should do nothing, and if
someone else logs in it should log the date, time, and user ID.  We have some people who like
to play practical jokes when others go on vacation, and this is just a little thing I came up
with to help me figure out who messed with my machine.  It works, but with one annoyance that I
cannot seem to solve.  It will log my user ID *every* time.  What happens is that it skips
capturing the date and time, but it will always log my user ID to the output file.  How can I
change the script so that no action is taken when I login?


Echo Off

::Detect an anomalous LOGON.  If none detected file takes no action.
If %Username% neq Tom (

   ::Get the time and date
   FOR /F "tokens=5 delims=. " %%a IN ('ECHO ^| TIME ^| FIND "current"') do set Trun=%%a
   FOR /F "tokens=6" %%a IN ('ECHO ^| DATE ^| FIND "current"') do set Drun=%%a

   ::Build the log file--if necessary--then log the data
   if not exist "C:\Output\Logons.txt" (
      echo Date      Time      User Name >> "C:\Output\Logons.txt"
      echo ----      ----      --------- >> "C:\Output\Logons.txt"
   )

   ::Write the date, time, and user name to the output file.
   echo %Drun%   %Trun%   %username% >> "C:\Output\Logons.txt"

   ::Create the Anomalous Logon notification message.
   echo Anomalous logon detected.  CHECK C:\Output\Logons.txt for more information. >>
"C:\Documents and Settings\Tom\Start Menu\Programs\Startup\AnomalousLogons.txt"
)My inclination would be to fix the symptoms rather than spend time working out the issue, as this is not a major piece of development

Why not just bomb out if it is your name:
Code: [Select]If %Username% eq Tom GoTo :EOFInsert backslashes where needed

C:test>type  thom2.bat


Echo Off
rem set USERNAME=Joe
rem echo USERNAME=%USERNAME%
set USERNAME=You
echo USERNAME=%USERNAME%
echo Date              Time        User Name >> C:testLogons.txt
 Rem need quotes around %USERNAME% and You
if %USERNAME%==You (
echo %USERNAME%
goto :END
)

      echo ----              ----        --------- >> C:testLogons.txt


echo %DATE%   %TIME%  %USERNAME% >>  C:testLogons.txt


echo Anomalous logon detected.   >> C:testLogons.txt

echo type logons.txt
type logons.txt
goto :stop

:END
echo %USERNAME% is only user   >> C:testLogons.txt

echo type logons.txt
type logons.txt
:stop
C:test> Quote from: victoria on August 09, 2010, 01:26:09 PM

Insert backslashes where needed

C:test>type  thom2.bat


Echo Off
rem set USERNAME=Joe
rem echo USERNAME=%USERNAME%
set USERNAME=You
echo USERNAME=%USERNAME%
echo Date              Time        User Name >> C:testLogons.txt
 Rem need quotes around %USERNAME% and You
if %USERNAME%==You (
echo %USERNAME%
goto :END
)

      echo ----              ----        --------- >> C:testLogons.txt


echo %DATE%   %TIME%  %USERNAME% >>  C:testLogons.txt


echo Anomalous logon detected.   >> C:testLogons.txt

echo type logons.txt
type logons.txt
goto :stop

:END
echo %USERNAME% is only user   >> C:testLogons.txt

echo type logons.txt
type logons.txt
:stop
C:test>


But, will this work?


It seems to be complicated command line.

However, yours is clear and pretty.




Echo Off

::Detect an anomalous logon.  If none detected file takes no action.
If %Username% neq Tom (

   ::Get the time and date
   FOR /F "tokens=5 delims=. " %%a IN ('ECHO ^| TIME ^| FIND "current"') do set Trun=%%a
   FOR /F "tokens=6" %%a IN ('ECHO ^| DATE ^| FIND "current"') do set Drun=%%a

   ::Build the log file--if necessary--then log the data
   if not exist "C:\Output\Logons.txt" (
      echo Date      Time      User Name >> "C:\Output\Logons.txt"
      echo ----      ----      --------- >> "C:\Output\Logons.txt"
   )

   ::Write the date, time, and user name to the output file.
   echo %Drun%   %Trun%   %username% >> "C:\Output\Logons.txt"

   ::Create the Anomalous Logon notification message.
   echo Anomalous logon detected.  Check C:\Output\Logons.txt for more information. >>
"C:\Documents and Settings\Tom\Start Menu\Programs\Startup\AnomalousLogons.txt"
)vishuvishal,

We do not need a for loop to record  and save %DATE% and %TIME%   in a log file.


But I will test the for loop code and post back the results.

The editor here or with the Proxy Server is not working for me correctly. 

I might need to take a picture of the code while on my machine. It is pretty but we cannot copy and paste from the picture.

What happened when you tested the for loop code? 

Post your results.He he didn't work

Actually I was trying to figure out the procedure happened on this code.
But found myself dumb.
So, I think I am just beginner.
However, your code are awesome so simple. Quote from: vishuvishal on August 09, 2010, 02:49:44 PM

But, will this work?

It seems to be a complicated for loop.


Yes, the For loop by the Original Poster worked.

Quote from: vishuvishal on August 09, 2010, 04:46:43 PM

 I am a beginner.


The following code was mangled by my Poxy Editor.  Look at the above SCREEN shot for a clear picture of the code.


C:\\\\test>type  vis89.bat
Echo Off
set USERNAME=%1
echo USERNAME=%USERNAME%
SETLOCAL EnableDelayedExpansion
echo. > C:\\\\test\\\\Logons.log
If \\\"%USERNAME%\\\" EQU \\\"Tom\\\" goto :end
FOR /F \\\"tokens=5 delims=. \\\" %%a IN (\\\'ECHO ^| TIME ^| FIND \\\"current\\\"\\\') do (
set Trun=%%a )
FOR /F \\\"tokens=6\\\" %%a IN (\\\'ECHO ^| DATE ^| FIND \\\"current\\\"\\\') do set Drun=%%a
echo Date         Time        User Name >> C:\\\\test\\\\Logons.log
echo ----         ----        --------- >> C:\\\\test\\\\Logons.log
echo !Drun!   !Trun!   !USERNAME! >> C:\\\\test\\\\Logons.log
echo Anomalous logon detected.  >> C:\\\\test\\\\Logons.log
goto :secondend
:end
echo %1  was the only User
exit /b
:secondend
echo %1 was a Bogus User >> C:\\\\test\\\\Logons.log
echo Type logons.log
Type logons.log

Output:

C:\\\\test> vis89.bat  Tom
USERNAME=Tom
Tom  was the only User

C:\\\\test> vis89.bat  vis
USERNAME=vis
Type logons.log

Date         Time        User Name
----         ----        ---------
08/09/2010   18:23:30    vis
Anomalous logon detected.
vis was a Bogus User
C:\\\\test> 
I should say your bat is worth than this.
Cause ur's simple and good.

Thanks and regards
VishuVis,
The for loop is not necessary.

229.

Solve : need to when child batch file execution is over?

Answer»

Hi
I am calling one batch (child batch file) from from parent batch file.
Now i need to invoke another child batch file from parent once currently running child batch file EXECUTION is over.

any help in this regard will be highly appreciated.

Thanks
Amit CODE: [Select]Call Bat1.bat
Call BAT2.bat
Bat2 will not execute until Bat1 has finished
Graham Quote from: amitkumar.verma on August 17, 2010, 12:16:58 AM


I am calling one batch (child batch file) from from parent batch file.
Now i need to invoke another child batch file from parent once currently running child batch file execution is over.
Any help in this regard will be highly appreciated.

Thanks
Amit


C:test>type main.bat
echo off
echo main
call bat1.bat
echo RETURN from bat2
echo %TIME%
call bat2.bat
echo return from bat
echo %TIME%
echo Bye
C:test>type bat1.bat
echo off
echo bat1
sleep.exe  60
echo %TIME%
exit /b
C:test>type bat2.bat
echo off
echo bat2
sleep.exe  60
echo %TIME%
exit /b
C:test>

Output:

C:test>main.bat
main
bat1
 3:37:24.95
return from bat1
 3:37:24.95
bat2
 3:38:24.97
return from bat2
 3:38:24.97
Bye

C:test>
230.

Solve : Background Music?

Answer»

Hi Guys

I Am Making An "Command PROMPT" Project On Maruti Suzuki Cars

I Needed A Batch File to play a song silently without showing up any Music Player

can It be possible ??

My song is in B:\Project_MSC\redemptation.mp3Im not sure that you can do this -- exactly, see http://msdn.microsoft.com/en-us/library/dd562624(VS.85).aspx

One option might be to embed a media player component in an html page and open the page with the browser minimised


to play a song silently 
Well, you can run a music player minimized.

Start "" /min MPLAY32 /play /close "C:\Documents and Settings\user\My Documents\filename.mp3"

Just use that (change the path to SUIT your needs).I Appreciate helpmeh but any example of music player which can b ran silently during the show Quote from: The Italian Stallion on August 10, 2010, 10:25:59 AM

I Appreciate helpmeh but any example of music player which can b ran silently during the show

I think silence and playing music are sort of conflicting requirements here. Quote from: The Italian Stallion on August 10, 2010, 10:25:59 AM
I Appreciate helpmeh but any example of music player which can b ran silently during the show
Code: [Select]SET wshShell=wscript.CreateObject("WScript.Shell")
wshshell.run "MPLAY32 /play /close PATHTOMP3\file.mp3", 0i made this program that does that(with special thanks to helpmeh for the vbs script)

music.exe C:\test.mp3

[recovering DISK space - old attachment deleted by admin]First: Why do people insist on compiling batch files?


Original batch for "music.exe":
Code: [Select]echo off
echo Set wshShell=Wscript.CreateObject("WScript.Shell")>temp.vbs
echo wshshell.run "MPLAY32 /play /close "%1"",0>>temp.vbs
cscript //nologo temp.vbs
del temp.vbs

Second: MPLAY32 is the windows 95 media player. It can be found on Windows XP,Windows 2000, 98, 95, and ME.

Now, let's look at The_Mad_Joker's OS:

"Windows 7".

Now, allow me to tell you, that mplay32 is not present on Vista or 7. therefore that solution will not work.

third: it doesn't solve the problem anyway, since the windows is simply minimized.

Quote from: BC_Programmer on August 10, 2010, 05:43:40 PM
First: Why do people insist on compiling batch files?


Original batch for "music.exe":
Code: [Select]echo off
echo Set wshShell=Wscript.CreateObject("WScript.Shell")>temp.vbs
echo wshshell.run "MPLAY32 /play /close "%1"",0>>temp.vbs
cscript //nologo temp.vbs
del temp.vbs

Second: MPLAY32 is the windows 95 media player. It can be found on Windows XP,Windows 2000, 98, 95, and ME.

Now, let's look at The_Mad_Joker's OS:

"Windows 7".

Now, allow me to tell you, that mplay32 is not present on Vista or 7. therefore that solution will not work.

third: it doesn't solve the problem anyway, since the windows is simply minimized.



#1 Insecurities?
#2 Mplay2 then?
#2.5 Not again...why does he return?
#3 No...

Also, the quotes need to be escaped somehow, because Wscript is expecting an end of statement at L:2 C:37 (when run straight from VBS).i complied it so it would be hidden so there is less confusion IE no popupsOr use JUST a vbs file, that way there is no need to compile anything, nor are there any popups.Batch file too doesnt give any pop ups, and yes that music.exe is not workingIs there a preferred option? Quote from: The Italian Stallion on August 11, 2010, 12:36:05 AM
Batch file too doesnt give any pop ups, and yes that music.exe is not working
Ok, then just use the batch file. Quote
Ok, then just use the batch file.
Okies thank u all 4 your help
231.

Solve : Registry edit using Dos?

Answer»

I want to create a read error of a  registry key file using MS Dos

The key file and all its bionary , string , DWORD etc value will work perfect.
so give me a best solution with Dos Code.

thanks &AMP; regards
Sohomhttp://support.microsoft.com/kb/131352


MS-DOS doesn't have a "registry".
Sohom,


http://articles.techrepublic.com.com/5100-10878_11-1032874.html

Using REGEDIT in DOS
The utility we are going to use is REGEDIT.EXE—the same REGEDIT that we use in Windows also RUNS as a DOS PROGRAM. REGEDIT.EXE supports command line arguments that allow us to do a complete registry rebuild, while leaving the dirt and empty spaces behind. We  will eliminate the need to repetitively type commands by creating four batch files that you can carry with you and run from a floppy.
For the sake of simplicity, we will assume that SYSTEM.DAT, USER.DAT, and REGEDIT.EXE reside in the C:WINDOWS directory.
You mean "Win32 command line", not "DOS".

Regedit is an interactive utility.

You can use the reg command which can be used from the "Win32 Command Line" or from a batch file. If you prefer another language you can use the StdRegProv object.

Good luck.  There is a very simple way to edit/import/export the registry via the command line. It has always been there in Windows (maybe some earlier versions of Windows required the resource kit to be installed, but there has always been a possibility to do that)

The command is called REG.EXE and since Windows 7 and I think Windows 2003 it has always been there.
To explore the command, simply time REG /?, you will get something like this:
REG Operation [Parameter List]
  Operation  [ QUERY | ADD | DELETE | COPY | SAVE | LOAD | UNLOAD | RESTORE | COMPARE | EXPORT | IMPORT  | FLAGS ]
Return Code: (Except for REG COMPARE)
  0 - Successful
  1 - Failed
For help on a specific operation type:
  REG Operation /?
Examples

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?
  REG FLAGS /?

What EXACTLY are you trying to do?

232.

Solve : net use /delete in script - do not work?

Answer»

Hi All

can anybody help.

I have SCRIPT:
Code: [Select]echo Y|net use p: /delete

START /wait NET USE p: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive
call e:\batchfile.bat
echo Y|net use p: /delete

echo Y|net use p: /delete
START /wait NET USE p: \\server1\MDPRD\distributions\P31\BW__RACUGRP\Archive
call e:\batchfile.bat
echo Y|net use p: /delete

START /wait NET USE p: \\server1\MDPRD\distributions\Archive
call e:\batchfile.bat
echo Y|net use p: /delete
however after calling e:\batchfile.bat
echo Y|net use p: /delete
do not work

can anobydy advice how to solve that error?

Code: [Select]E:\>echo Y  | net use y: /delete
y: was deleted successfully.

E:\>START /wait NET USE y: \\server1\MDPRD\distributions\Inbound\70\70_Customer_flat\Archive


E:\>call e:\batchfile.bat
The device is being accessed by an active process. <---- here net use delete  is failing

More help is available by typing NET HELPMSG 2404.

Press any key to continue . .
Please advice

Thank you very much.

BR
Michal Quote

however after calling e:\batchfile.bat
echo Y|net use p: /delete
do not work

It would help if you posted the contents of batchfile.bat. It appears some process has an open handle to the P drive.

Any reason why you are using start with the net use command? There is no reason to run it in a separate window and running it inline produces the same result as the /wait switch would.

 hi Sidewinder

Thank you for replay, here is full batchfile.bat:


Code: [Select]echo off
CD /d p:\

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this ORDER will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A

REM tidy
del c:\evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,

set MM=
set DD=
set YYYY=

set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
net use p:|find "Remote name">> %LogFile%

REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach "%%A"

REM tidy up the log
>> %LogFile% Echo ========================================

goto :EOF

:ProcessEach

>> %LogFile% echo %~f1                       %~t1

goto :EOF



Thank you for help

BR
MichalThe second line in batchfile.bat LOGS you on to the P drive. There is no other CD instruction in the file (that I could find), so when batchfile.bat ends, you are still logged into the P drive.

Batchfile.bat needs to be changed to log off the P drive before the calling file attempts to delete the mapping (net use p: /delete)

 Michal
I knew it would be something easy !
Sorry I couldnt finish this off without Sidewinder's help (cheers SW)
Graham

Try this
Code: [Select]echo off
CD /d p:\

REM grab todays date into variables
set MM=%Date:~3,2%
set DD=%Date:~0,2%
set YYYY=%Date:~6,4%

REM Add the date variables to the log name
REM putting the date in this order will sort the files sensibly
Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log"

REM create the vb script
>c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0))

REM extract todays date less 7 days
set OldestDate=
for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A

REM tidy
del c:\evaluate.vbs

REM break up the date into constituent parts
REM Note - the date is parsing YYYY-MM-DD format dates,

set MM=
set DD=
set YYYY=

set MM=%OldestDate:~5,2%
set DD=%OldestDate:~8,2%
set YYYY=%OldestDate:~0,4%

REM reconstruct US format with '-' separators
set OldestDate=%MM%-%DD%-%YYYY%

REM add the new entry to the log
>> %LogFile% Echo %DATE% %TIME%
>> %LogFile% Echo Since : %OldestDate%
net use p:|find "Remote name">> %LogFile%

REM list the files that would be copied if we really were doing a copy
REM force it to believe that the target NonExistentDirectory is a directory
REM and echo the name & time for each

for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.*  NonExistentDirectory ' ) do call :ProcessEach "%%A"

REM tidy up the log
>> %LogFile% Echo ========================================

REM ----------------------------
REM Release mapped drive
REM ----------------------------

E:

goto :EOF

:ProcessEach

>> %LogFile% echo %~f1                       %~t1

goto :EOF
Hi

Now it looks to work with deleting p: drive when script is finished

It seems to be working as expected

Thank you very very very much

BR
MichalHi

I encouriage strange problem. Mentioned above script works fine on one computer, but on all others is failing.

I have that error message:

C:\MDM_Monitoring>echo Y  | net use p: /delete
p: was deleted successfully.


C:\MDM_Monitoring>START /wait NET USE p: \\server1\P_Customer\Inbound\70\70_Customer_flat\Archive

C:\MDM_Monitoring>call e:\bathfile.bat
The system cannot find the drive specified.
The device is being accessed by an active process.

More help is available by typing NET HELPMSG 2404.

Press any key to continue . . .


Can you please help, I have no clue why that error occour. Special that it works on once computer only. On all other computers I have mentioned above error.

Thank you in advance.

BR
Michal Quote
REM ----------------------------
REM Release mapped drive
REM ----------------------------

E:

I see remarks for deleting the mapped drive but no actual INSTRUCTIONS. It may be time to rethink your design. Batchfile should contain all the instructions it needs to run whether from the command line or as a called file. By this I mean batchfile should map the drive, access the drive and release the drive; it should not rely on some caller batch file to supply these instructions.

Be aware that in a caller/calling sequence, that if any module fails to complete properly, your session status may be corrupt.

Why are you using start /wait with the net use command? Why are you piping Y to the net use command?

Quote
Special that it works on once computer only. On all other computers I have mentioned above error.

Let us know. 

Are all the computers running the same OS. Are they on the same network?

Hi All

Sorry I messed up, all works fine.

note. Always connect to disks mapped to your computer

BR
Silberzin
233.

Solve : how to get the Count of string in file?

Answer» HI,

Am having a FILE with 1 line having a file size of 35MB.


Eg:-
arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~

I need to get a count of INS* in the above file. Am new to DOS Commands.

Please help me.

Thanks in Advance.

Regards,
Arun S. Quote from: arunavlp on August 03, 2010, 04:43:17 AM
hi,

Am having a file with 1 line having a file size of 35MB.


Eg:-
arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~

I need to get a count of INS* in the above file. Am new to DOS Commands.

Please help me.

Thanks in Advance.

Regards,
Arun S.

download  gawk for windows,
then
Code: [Select]c:\test> gawk "{m=gsub("INS",""); total+=m}END{print "total:" total}" file
hi ,

Thanks for suggestion. but i got an error message like this

30.834
gawk: {m=gsub(INS,");
gawk:             ^ unterminated string

i dont know wht this error means. Please help me on this.


Regards,
Arun S.Escape your double quotes

Code: [Select]c:\test> gawk "{m=gsub(\"INS\",\"\"); total+=m}END{print \"total:\" total}" file
hi,

Thanks It works..  but please let me know if we can do it in Find Command....

Regards,
Arun S. Quote from: arunavlp on August 05, 2010, 12:34:57 AM
hi,

Thanks It works..  but please let me know if we can do it in Find Command....

Regards,
Arun S.
i personally wouldn't bother. find (or findstr) just find the string on a line for you. It won't count how many there are. More involved PROGRAMMING is needed. ( that i will leave it someone else who has the expertise and time to show you, )
When parsing files and doing string manipulation, use a good tool for the job.The find command will count the lines with the search argument. If a line has more than one occurrence of the search argument, it still counts for one. Findstr does not do counting but allows for multiple search arguments and a limited form of regular expressions.

You can use VBScript which came with your Windows machine. The little demo script will prompt the user for the file name and the search argument. It can be tweaked to remove the prompts (which will probably gut the majority of the script).

Code: [Select]Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")

Do
  WScript.StdOut.Write "Please enter file name: "
  strFile = WScript.StdIn.ReadLine
  If fso.FileExists(strFile) Then
  Set objFile = fso.OpenTextFile(strFile, ForReading)
strCharacters = objFile.ReadAll
  Exit Do
  Else
    WScript.StdOut.Write "Invalid file name ... Try Again" & vbCrLf
  End If
Loop

Do
  WScript.StdOut.Write "Please enter character string: "
  strToCount = WScript.StdIn.ReadLine
  If strToCount <> "" Then Exit Do
Loop

strTemp = Replace(LCase(strCharacters), LCase(strToCount), "")
WScript.Echo "Occurences of:", strToCount, "=", (Len(strCharacters) - Len(strTemp)) / Len(strToCount)

objFile.Close

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

Good luck. 
I can give you Idea what it should like to be:

set /p pass= echo %pass%
call set new=%%pass:~%a%,1%%
set /a a=%a% + 1
  set key=%key%%new%
echo %new%

This new will give you the number of string.
However, I am going will give you further details tommorrow

Thanks and regard
vishu Code: [Select]set /p pass=<string.txt
echo %pass%
:st
call set new=%%pass:~%a%,1%%
echo a=%a% + 1
echo %a%
set key=%key%%new%
echo %new%
echo %key%
pause
::if %new% ==; goto :EOF

pause
goto :st


All we need to fix is loop.
Change the string.txt to your file drive:path\file name
Gave you a best option

echo  off

sed s/the/the\\n/g yz.txt | egrep -c the



counthe.bat
10
type yz.txt
the
the
the
the
the the the
the the the
Two \\ should be one

C:\\test>type   cntstr.bat
REM echo  off
sed s/%1/%1\\n/g %2 | egrep -c %1

C:\\test>cntstr.bat  the yz.txt

C:\\test>rem echo  off

C:\\test>sed s/the/the\\n/g yz.txt   | egrep -c the
10

C:\\test>type yz.txt
the
the
the
the
the the the
the the the
Only one \\ backslash each time

type cntstr.bat
rem echo  off
sed s/%1/%1\\n/g %2 | egrep -c %1

cntstr.bat   22  yr2010.doc

rem echo  off

sed s/22/22\\n/g yr2010.doc   | egrep -c 22
12

Output for REPLY #6 by sidewinder


cscript   swcnt.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Please enter file name: yr2010.doc
Please enter character string: 22
Occurences of: 22 = 12

Victoria, I really understand wht these commands will do.

Seems like not a proper bat file
234.

Solve : Help creating files?

Answer»

I'm writing a messenger for me and my brother to use at our house. I'm Just having a little trouble with it.

Here's what I have so far,

Code: [Select]ECHO OFF

IF EXIST Writer.bat (
IF EXIST READER.bat (GOTO DONE
) ELSE (
GOTO Reader
)
) ELSE (
GOTO Writer
)

:Reader

ECHO ECHO OFF>Reader.bat
ECHO.>>Reader.bat
ECHO :Loop>>Reader.bat
ECHO.>>Reader.bat
ECHO CLS>>Reader.bat
ECHO TYPE Messages.txt>>Reader.bat
>>Reader.bat ECHO TIMEOUT /t 2
ECHO GOTO Loop>>Reader.bat

ATTRIB +H Reader.bat

ECHO Reader Successfully Created.

IF EXIST Writer.bat (GOTO Done
) ELSE (
GOTO Writer
)

:Writer

ECHO ECHO OFF>Writer.bat
ECHO.>>Writer.bat
ECHO ECHO Enter your name:>>Writer.bat
ECHO SET /p User="">>Writer.bat
ECHO.>>Writer.bat
ECHO :Loop>>Writer.bat
ECHO.>>Writer.bat
ECHO CLS>>Writer.bat
ECHO ECHO Enter your message:>>Writer.bat
ECHO SET /p Message="">>Writer.bat
>>Messages.txt ECHO ECHO %%User%% - %%Message%%>>Writer.bat
>>Messages.txt ECHO ECHO.>>Writer.bat
ECHO GOTO Loop>>Writer.bat

ATTRIB +H Writer.bat

ECHO Writer Successfully Created.

IF EXIST Reader.bat (GOTO Done
) ELSE (
GOTO Reader
)

:Done

PAUSE
START Reader.bat
START Writer.bat
EXIT
The parts I'm having troubles with  is:

Code: [Select]>>Writer.bat ECHo ECHO %%User%% - %%Message%%>>Messages.txt
>>Writer.bat ECHO.>>Messages.txt
And:

Code: [Select]>>Reader.bat ECHO TIMEOUT /t 2
The first one I really wasn't expecting to work, does anybody know a way around it?

And the second, I really don't know why it's not working. Any Ideas?>>Reader.bat ECHO TIMEOUT /t 2 No problems with this line, it appears it will be written to Reader.bat but does Timeout have a /t switch?

Code: [Select]>>Writer.bat ECHO ECHO %%User%% - %%Message%%>>Messages.txt
>>Writer.bat ECHO.>>Messages.txt
Escape the second >> using the caret like
Code: [Select]>>Writer.bat ECHO ECHO %%User%% - %%Message%%^>^>Messages.txt
>>Writer.bat ECHO ECHO.^>^>Messages.txt
This doesn't mean your script will run, I think there are other problems for you to sort out..

FYI to save a lot of repetitive typing you could use

(
ECHO ECHO OFF
ECHO ECHO.
ECHO SET /p User=Enter your name:
ECHO ECHO.
etc...
.
.
etc...
)>writer.bat

Good luck.Ahh, thank you very much!

I am aware of the bugs, and am still working on them. These two were the ones stumping me.

And by the way:

Code: [Select]C:\>timeout /?

TIMEOUT [/T] timeout [/NOBREAK]

Description:
    This utility accepts a timeout parameter to wait for the specified
    time period (in seconds) or until any key is pressed. It also
    accepts a parameter to ignore the key press.

Parameter List:
    /T        timeout       Specifies the number of seconds to wait.
                            Valid range is -1 to 99999 seconds.

    /NOBREAK                Ignore key presses and wait specified time.

    /?                      Displays this help message.

NOTE: A timeout value of -1 means to wait indefinitely for a key press.

Examples:
    TIMEOUT /?
    TIMEOUT /T 10
    TIMEOUT /T 300 /NOBREAK
    TIMEOUT /T -1

C:\>
Thanks for the suggestions!Timeout /t  SORRY about that, it's your Win 7 vs my Win XP.  LOL Haha yeah, not a problem! Thanks again. Quote from: Dusty on AUGUST 17, 2010, 09:28:32 PM

FYI to save a lot of repetitive typing you could use

(
ECHO ECHO OFF
ECHO ECHO.
ECHO SET /p User=Enter your name:
ECHO ECHO.
etc...
.
.
etc...
)>writer.bat

Good luck.
WOW! You can actually do that? Dang...that could have saved tonnes of time! Quote from: helpmeh
WOW! You can actually do that?

Yep, try it out.

235.

Solve : Help with script involving dates and days of week?

Answer»

Hi,

I use a batch program to download files from a server.  The files are named [name]_[date in yyymmdd format].
I wrote the program to download files for the last 7 days starting with today.  I have two problems:
1.  When the program counts backwards I loose the leading zero so 20100804 becomes 201084 which doesn't work.
2.  When I back up against another month it fails also.

Can this be fixed.  Also can the day of the week that corresponds to the date be RETURNED as a variable?

Here is the code:

SET dwMONTH=%DATE:~4,2%
SET dwDAY=%DATE:~7,2%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

:gs01
set localroot=[server]
set localdrv=d:
copy %localroot%\FL_%plantid%_*%datenow%.txt %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy %localroot%\D1_%plantid%_*%datenow%.txt %localdrv%\rs_input\D1_%plantid%_%datenow%.txt


SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2%-1
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

copy %localroot%\FL_%plantid%_*%datenow%.txt %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy %localroot%\D1_%plantid%_*%datenow%.txt %localdrv%\rs_input\D1_%plantid%_%datenow%.txt

An help is appreciatedHere is the solution. There was small defect.


Code: [Select]SET dwMONTH=%DATE:~4,2%
SET dwDAY=%DATE:~7,2%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

:gs01
set localroot=[server]
set localdrv=d:
copy "%localroot%\FL_%plantid%_*%datenow%.txt" %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy "%localroot%\D1_%plantid%_*%datenow%.txt" %localdrv%\rs_input\D1_%plantid%_%datenow%.txt


SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

copy "%localroot%\FL_%plantid%_*%datenow%.txt" %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy "%localroot%\D1_%plantid%_*%datenow%.txt" %localdrv%\rs_input\D1_%plantid%_%datenow%.txt



Checked and VERIFIED. This will work

Please let me know if it all set.

Thanks will do it.


Thanks and regards
vishuHi Vishu,

I apologize for my lack of clarity the line: SET /A dwDAY=%DATE:~7,2%-1 is not really a defect.  It subtracts 1 day from the date.  the program counts BACKWARD for 6 days to copy files dated as I stated in the original post.  The subsequent groups of code have: SET /A dwDAY=%DATE:~7,2%-2, SET /A dwDAY=%DATE:~7,2%-1-3, etc. to SET /A dwDAY=%DATE:~7,2%-6.

In the end I want 7 sets of files including the current day. Quote from: vishuvishal on August 15, 2010, 06:10:44 PM

Here is the solution. There was small defect.


Code: [Select]SET dwMONTH=%DATE:~4,2%
SET dwDAY=%DATE:~7,2%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

:gs01
set localroot=[server]
set localdrv=d:
copy "%localroot%\FL_%plantid%_*%datenow%.txt" %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy "%localroot%\D1_%plantid%_*%datenow%.txt" %localdrv%\rs_input\D1_%plantid%_%datenow%.txt


SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2%-1
IF /i %dwDAY% LSS 10 set dwday=0%dwDAY%
SET dwday=%0%%dwday%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%

copy "%localroot%\FL_%plantid%_*%datenow%.txt" %localdrv%\rs_input\FL_%plantid%_%datenow%.txt
copy "%localroot%\D1_%plantid%_*%datenow%.txt" %localdrv%\rs_input\D1_%plantid%_%datenow%.txt



Checked and verified. This will work

Please let me know if it all set.

Thanks will do it.


Thanks and regards
vishu
Batch scripting is all but useless in manipulating dates.

What happens if the day is 01?  The result of SET /A dwDAY=%DATE:~7,2%-1 is that dwDAY will return zero , and if the day is 02 and you "count backwards" for six days, dwDay will return -4.

Also, if the day is 08 or 09 Set /a will treat the values as Octal and throw up the usual error message because 08 and 09 are invalid in octal.

If the script is run near the beginning of the month, month and day must be decremented.  If you run the script in early January the day, month and year must be decremented.

Best have a look at date manipulation using VB scripting.

Good luck.C:test>type griff816.bat
echo off
set /a c=0
:start
SET dwMONTH=%DATE:~4,2%
echo dwMONTH=%dwMONTH%
SET /A dwDAY=%DATE:~7,2% -%c%
echo dwDAY=%dwDAY%
SET dwDAY=%DATE:~7,2%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%


set localroot=c:test
set localdrv=c:tmp
copy  %localroot%\\%datenow%.txt %localdrv%\\%datenow%.txt
copy  %localroot%\\%datenow%.txt %localdrv%\\%datenow%.txt


SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2% -%c%
echo dwDAY=%dwDAY%
if %dwDAY% LEQ 0 (
SET /a dwDAY=31
SET /a dwMONTH=%DATE:~5,1% -1
echo dwMONTH=%dwMONTH%
if %dwMONTH% EQU 7 set /a dwDAY=31
if %dwMONTH% EQU 8 set /a dwDAY=31
if %dwMONTH% EQU 6 set /a dwDAY=30
if %dwMONTH% EQU 2 set /a dwDAY=28
echo dwDAY=%dwDAY%
)
if %dwMONTH% LEQ 9 set dwMONTH=0%dwMONTH%
echo dwMONTH=%dwMONTH%
SET dwYEAR=%DATE:~10,4%
SET Datenow=%dwYEAR%%dwMONTH%%dwDAy%
echo Datenow=%Datenow%
if %dwDAY% LEQ 9 set dwDAY=0%dwDAY%

copy %localroot%\\FL_%plantid%_*%datenow%.txt %localdrv%\\rs_input\\FL_%plantid%_%datenow%.txt
copy %localroot%\\\\D1_%plantid%_*%datenow%.txt %localdrv%\\\\rs_input\\\\D1_%plantid%_%datenow%.txt
set /a c=%c% + 1
if %c% LEQ 7 goto :start


C:test>Hi Roy,

I tried your code but it placed a zero in front all dates even if there were ALREADY 2 digits.  But I like your logic here.  I'm trying this but it isn't working quite right either. Any thoughts?

set /a addzero=0
SET dwMONTH=%DATE:~4,2%
SET /A dwDAY=%DATE:~7,2%-14
SET dwYEAR=%DATE:~10,4%
if (%dwday%) GEQ (10) (
set /a datenow=%dwYEAR%%dwMONTH%%dwDAy%
) else (
SET /a Datenow=%dwyear%%dwmonth%%addzero%%dwday%
)

echo %datenow%here comes the expert Roy. Don't worry mcgriff1969, Roy will solve your problem using batch. As for my recommendation, i would suggest you use some other tools able to MANIPULATE dates better, eg vbscript. you can search the forum as there are many such vbscripts lying around. Quote from: ghostdog74 on August 23, 2010, 07:10:28 PM
here comes the expert Roy. Don't worry mcgriff1969, Roy will solve your problem using batch. As for my recommendation, i would suggest you use some other tools able to manipulate dates better, eg vbscript. you can search the forum as there are many such vbscripts lying around.

Wow!  No love for Roy? 

 I understand that VB Script is better for this but I have zero knowledge of it. Quote from: mcgriff1969 on August 25, 2010, 08:31:58 AM
Wow!  No love for Roy? 
No patience for Roy, or any of his other accounts. Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM

I tried your code but it placed a zero in front all dates even if there were already 2 digits.  But I like your logic here.  I\'m trying this but it isnt working quite right either. Any thoughts?

echo %datenow%

Many suggestions from the Ghost and Helpless about what does not work.

But no suggestions or examples from the Ghost and Helpless of what can be done.

The Cat Bell? Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM

I tried your code but it placed a zero in front all dates even if there were already 2 digits.  But I like your logic here.  Im trying this but it isnt working quite right either.

Any thoughts?


C:test>Display  mc.bat

echo off
SET dwMONTH=%DATE:~4,2%
echo dwMONTH=%dwMONTH%
SET /A dwDAY=%DATE:~7,2%-16
echo dwDAY=%dwDAY%
SET dwYEAR=%DATE:~10,4%
echo dwYEAR=%dwYEAR%
if %dwday% LEQ 9 set dwday=0%dwday%
SET  Datenow=%dwyear%%dwmonth%%dwday%

echo Datenow=%Datenow%

Output:

C:test> mc.bat
dwMONTH=08
dwDAY=9
dwYEAR=2010
Datenow=20100809

C:test>

When dwDAY is not less than or equal to 9, no zero is added. ( We subtracted -14 not -16 )

Output:

C:test> mc.bat
dwMONTH=08
dwDAY=11
dwYEAR=2010
Datenow=20100811

C:test>

Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM


I tried your code but it placed a zero in front all dates even if there were already 2 digits.  But I like your logic here.  Im trying this but it isnt working quite right either. Any thoughts?


set /?
« Sent to: mcgriff1969 on: Today at 12:14:03 PM »     

--------------------------------------------------------------------------------

 set dwday=0%dwday%

 set /a dwday=0%dwday%

set /a  will not  work 09 is octal not an integer Quote from: Fields on August 25, 2010, 12:17:56 PM
09 is octal not an integer

09 is not octal, and it is an integer.
Quote from: Fields on August 25, 2010, 11:26:00 AM
C:test>Display  mc.bat

echo off
SET dwMONTH=%DATE:~4,2%
echo dwMONTH=%dwMONTH%
SET /A dwDAY=%DATE:~7,2%-16
echo dwDAY=%dwDAY%
SET dwYEAR=%DATE:~10,4%
echo dwYEAR=%dwYEAR%
if %dwday% LEQ 9 set dwday=0%dwday%
SET  Datenow=%dwyear%%dwmonth%%dwday%



I think you've got it!
236.

Solve : NET USE or Other Cmd to change Drive Mapping's "Label"?

Answer»

Is there a way to use the NET USE or some other command to CHANGE the "Comment" or "Label" for a DRIVE mapping?

For example for one of my SERVER shares ...
NET USE Q: \\srv-m2ne\Video_04 /p:n
... results in a "description in My Computer" of:

Video_04 on 'srv-m2ne'(Q:)

But instead of the "Video_04 on 'srv-m2ne'" I want to "use F2" (but WITHIN the bat file that does all of our mapping) and change the "Label" to something like:

Video04 MOVIES (Q:)

237.

Solve : Chat tool using dos?

Answer»

HI Techs,

Can we create a chat tool using dos. That can chat over internet like MSN or Yahoo.

Thanks and regards
vishuProbably. Why don't you RESEARCH it and show us your code?

Here, I'll start you off

http://www.google.com/search?source=ig&hl=en&rlz=&=&q=command+line+chat+tool&btnG=Google+Search


Sorry to DISAPPOINT you but I could find it. Could you be specific?Did you mean you want somebody to write a chat program for you?
Even if you look AROUND on this forum you will find something.

Quote from: Frejoh466 on August 15, 2010, 03:51:30 AM
Code: [Select]echo off
:A
Cls
set /P n=User:  IP address
set /p m=Message: message
net send %n% %m%
Pause
Goto A
238.

Solve : MS Dos 3.1????

Answer»

I am trying to get a very, very, very old computer, which runs a very expensive piece of equipment, up and running.  I believe that this computer is a 1986 AT&T PC3600 running MS DOS 3.1.  When the computer boots it runs a memory test and then comes to the following screen and sits:

T U R B O - XT 1986
Speed 4.77/8.00MHz Version 3.10


Then it just sits for a while with no prompt or anything and then it eventually goes away and does nothing else.

Any clue how to help this old DINOSAUR back to life???Has the system been working recently ? It does sound like the hard drive has gone west – or is it all run off floppies ?

You may be able to resurrect the drive by taking it out and putting it in a different pc.

Is the equipment controlled by either the serial or parallel port ? If so there is a chance that a newer pc (with the appropriate port) could do the job. You may have to get a 5-1/4 inch floppy drive to enable the software to be loaded (you do have the original disks ?) – or POSSIBLY copying it off the hard drive if it isn’t too broken.
If the floppy drive is working, you might be able to use that on the new pc.

Good luck -- let us know how you get on
No, I don't believe the system has been working recently.  I believe the system is run off the HD.

The equipment is run by custom cards (ribbon cables come right out of the back of the PC).

The equipment didn't come with any disks.

Would the best BET be to install the HD in a working PC, copy any software over, get a working HD installed in dead PC and transfer the data back?

This is going to be tricky
If your hard drive is dead, and you do not have any backups, then that is the end of the story.

If it isnt completely dead, then you might be able to recover most of the data on the disk.

BUT
The original pc is so old, you may not be able to find a disk that is compatible with it.

You say the ribbon cable comes out of the back of it - are you sure that this isnt the parallel printer port ?

What is the equipment it controls ? if it is so important to you, you may be able to get the necessary drivers and software installed on a modern pc, without having to resurrect the dead box.

Ah, one thought comes to mind -- the BIOS holds the setup INFO in cmos ram, this needs a battery to help it remember, it may be that it does not know where to boot from. Open the case, locate and replace the battery.

I have no idea how to reset the memory, as far as I can remember from those days, I had an external program to change the settings. Try hitting keys while the thing starts up F2 or F8 -- or DEL (backspace, not Dell!!) to see if it takes you into a config menu?

Good luck again
Graham Quote from: gpl on September 01, 2010, 10:09:05 AM

You say the ribbon cable comes out of the back of it - are you sure that this isnt the parallel printer port ?
Parallel Printer cables aren't a ribbon... they're just a cable.

Quote
Ah, one thought comes to mind -- the BIOS holds the setup info in cmos ram, this needs a battery to help it remember, it may be that it does not know where to boot from. Open the case, locate and replace the battery.

no computers before the 286/AT had a CMOS battery. All configuration was done VIA DIP switches and jumpers on the motherboard, so this is not the problem.

Sounds more like, as you said, the hard drive has gone south. I'd of course first check that by making sure everything was snugly connected inside. The hard drive is highly unlikely to be a IDE drive- it is more then likely a ESDI or another older interface, which you won't be able to install in a new computer. Replacements will be equally hard to find, if they are even sold anywhere.

Best idea would be to update the hardware/software solution in place to use more modern components with more readily available replacements when parts go BAD.
239.

Solve : DOS batch job to delete files?

Answer»

Need a DOS BATCH job to delete files older than 30 days Quote from: Sidewinder on August 06, 2008, 09:02:02 AM

This little snippet is written in VBScript:

Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
Set F = fso.GetFolder("c:\scripts")            'point to your directory
Set fc = f.Files

For Each objFile In fc
If fso.GetExtensionName(objFile) = "avi" then
If objFile.DateCreated < date - 5 Then
WScript.Echo objFile & " " & objFile.DateCreated
'fso.DeleteFile(objFile)  'commented out
End If
End If
Next

Save with a vbs extension and run from the command line as: cscript scriptname.vbs

The delete function is currently commented out. Script will currently LIST files to be deleted. When you're ready, uncomment the delete function and comment the wscript.echo line.

Good luck 



Just change the 5 in the code to 30 and the folder to your own folder. Quote from: darther on August 19, 2010, 12:46:57 PM
Need a DOS BATCH job to delete files older than 30 days

Quote from: darther on August 19, 2010, 12:46:57 PM
Need a DOS BATCH job to delete files older than 30 days

( copy and PASTE from this post.  See above copy for no extra backslashes. )

ref:
http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

C:\\test>display   de30.bat
echo off
rem change \"cmd /c echo path\"  to  \"cmd /c del  path\"

forfiles -p \"C:\\test\"  /s /m *.bat -d -30 -c \"cmd  /c echo path\"  >  30day.txt

rem type  30day.txt

type  30day.txt  | wc -l

echo. >  out829.txt
for /f \"delims=\" %%i in (30day.txt) do (
dir  /s /TC /OD  %%i  |  FINDSTR  \"2010\"  >>  out829.txt
)

echo Display batch files older than 30 days
sort  out829.txt

Output:

C:\\test> de30.bat
     130 files
Display batch files older than 30 days

.

05/30/2010  07:06 PM             1,869 parse2.bat
05/30/2010  10:35 AM                87 zoe.bat
06/01/2010  05:44 PM               368 matt524.bat
06/11/2010  01:28 PM             1,624 redirect.bat
06/11/2010  06:09 PM               413 sib611.bat
06/11/2010  06:22 PM               509 yesterdayfiles.bat
06/11/2010  06:26 PM               722 dayfiles.bat
06/11/2010  09:02 PM               285 trail.bat
06/14/2010  01:04 PM               455 fday.bat
06/14/2010  05:17 PM               253 date.bat
06/14/2010  06:51 PM                81 schedule.bat
06/15/2010  04:01 PM               514 nightrider.bat
06/15/2010  08:45 PM             3,386 vis.bat
06/16/2010  03:30 PM               768 tri.bat
06/16/2010  07:26 AM               456 nrider.bat
06/16/2010  08:23 AM               493 nnrider.bat
06/16/2010  12:42 PM               866 pascal.bat
06/17/2010  02:45 AM               143 aaron.bat
06/17/2010  09:58 PM                90 slept.bat
06/20/2010  06:25 PM                 0 fibbie.bat
06/20/2010  06:33 PM                65 try.bat
06/21/2010  05:36 PM               442 swxfer.bat
06/25/2010  06:36 AM                70 ab.bat
06/26/2010  08:18 PM               252 sepstr.bat
06/26/2010  08:43 PM               434 spacechar.bat
06/28/2010  07:42 PM               146 tend.bat
06/30/2010  08:34 PM               703 bang.bat
07/02/2010  09:10 PM               178 nib.bat
07/02/2010  11:05 AM               744 scrpt.bat
07/03/2010  06:06 PM               517 sw070410.bat
07/03/2010  10:43 AM               189 st070310.bat
07/04/2010  12:04 PM                61 ravi.bat
07/05/2010  06:05 PM               213 project0705.bat
07/05/2010  08:16 PM                91 ravi2.bat
07/06/2010  06:18 AM               120 old.bat
07/06/2010  08:30 PM             1,619 ski.bat
07/06/2010  09:43 PM                10 test.bat
07/06/2010  11:18 AM             1,604 shshi.bat
07/07/2010  01:33 PM               184 numdown.bat
07/07/2010  02:43 AM               210 gok.bat
07/07/2010  06:27 PM               498 matt0705.bat
07/09/2010  05:25 PM               538 dis1.bat
07/09/2010  09:57 AM               559 dis.bat
07/09/2010  11:26 PM               320 dis2.bat
07/09/2010  11:54 PM               250 hope.bat
07/11/2010  07:56 PM               263 only.bat
07/11/2010  08:26 PM               300 xfilefor.bat
07/11/2010  08:27 PM               192 xfilefromstr.bat
07/11/2010  08:28 PM               164 xfiletime.bat
07/11/2010  08:29 PM                58 xfiletime2.bat
07/13/2010  08:46 PM                38 doni.bat
07/17/2010  01:07 PM               201 blank2.bat
07/17/2010  07:26 PM                88 cp.bat
07/17/2010  11:44 AM               751 blank.bat
07/17/2010  11:59 AM               160 clean.bat
07/20/2010  07:01 PM               152 ol720.bat
07/20/2010  07:10 PM               300 filefor.bat
07/24/2010  11:01 AM                77 lp.bat
07/25/2010  01:52 PM               702 lon.bat
07/25/2010  04:39 PM               384 paw.bat
07/25/2010  07:15 PM               479 paw2.bat
07/26/2010  07:33 PM               449 blog.bat
07/26/2010  12:45 PM               140 ol726.bat
07/28/2010  06:00 PM               287 id2.bat

C:\\test>
240.

Solve : DOS Batch command to open file with certain program, depending on file size?

Answer»

Hello all,

I want to open TXT and LOG files with different programs, depending on the file size.

For instance, if it's just a small file, I'm happy to open it up in WIN32PAD, which is small and opens fast. But if it's a larger file, then I want to open it in PSPad, my preferred text editor. But PSPad is a LOT bigger (> 4Mb), so I don't want to use it for any small file.

So I wrote the following batch script:

Code: [Select]REM OPENTXT.BAT
ECHO is %~z1 greater than 20000?
if %~z1 GTR 20000 (ECHO YES) ELSE (ECHO NO)
IF %~z1 GTR 20000 (start "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1) else (start "C:\Arquivos de programas\win32pad\win32pad.exe" %1)
exit

And then I run OPENTXT.BAT MYFILE.TXT

The first three lines I put just for me to CHECK if the file size is being got correctly.

Anyway, no matter what the size of the MYFILE.TXT is, it ALWAYS opens it with PSPAD. The first lines echo the result (true or false) for the GTR operator, which confirms that the logical operator is returning the expected result.

I tried changing things round and using LEQ instead of GTR, but it still opens all files with PSPAD, no matter what the result of GTR (or LEQ) is.

If I type on the command line WIN32PAD.EXE MYFILE.TXT, it opens fine.

Any ideas?

OK, I seemed to have solved it myself:

Code: [Select]IF %~z1 gtr 3500 (goto 1) else (goto 2)
exit

:1
start "1" "C:\LiberKey\Apps\PSPad\PSPadLKL.exe" %1
GOTO:EOF

:2
start "2" "C:\Arquivos de programas\win32pad\win32pad.exe" %1
GOTO:EOF

I associated TXT files with this batch file, and it's working.

I think it had something to do with me ADDING the "Window TITLE" in the START option.

241.

Solve : .Bat File For Renaming Files That Are Allways Changing?

Answer» HI There

I Wanting To Undergo A Tricky Operation How To Rename Files Without Specifying

There Names   Example File 1 To 01.MP3 File 2 to 02.mp3

Using This .Bat  File For My Sonic 2 Mp3 tool


Any Help Will Be Greatly Appreciated Code: [Select]echo off
SET ext=mp3
setlocal ENABLEDELAYEDEXPANSION
set path2=C:\test
set a=1
dir /s %path2%.\*.%ext% /b >%path2%.\%ext%.dir
for /f "delims=" %%a in (%path2%.\%ext%.dir) do (
set b=!a!
if !a! lss 10 set b=0!b!
ren "%%a" !b!.%ext%
set /a a=!a!+1
)
del %path2%.\%ext%.dirC:\test is the folder of the mp3 files  That Has WORKED Thanks So Much
242.

Solve : trim first 5 characters off of file names?

Answer»

Looking for a way to trim first 5 character places off of a bunch of file names named
01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.

I saw a program for sale called better file rename for $20, but was WONDERING if anyone knew of a way to do it for free through batch using a read in file name and then trim and rename as filename without the first 5 characters leading into the file name? I dont see why batch wouldnt be able to do it, but this exceeds my batching abilities, so a solution would be a learning experience if you could also describe what does what in the batch.

I have about 3000 SONGS that I want to trim this off of, so I am not sure if there is a way to read in with wildcard *.mp3 for all files in that directory and have it CHUG through them until they are all renamed without first 5 characters that always start with 01(space)-(space), 02(space)-(space) ect where the leading 2 digits is the track number so maybe ??(space)-(space) can be used as a wildcard type match for the files to test against them, or if the test would be to look for a dash ( - ) at the 4th character place of each file name and if there is a dash at the 4th character place, then trim first 5 character places off of the filename with a read in of that files name, trim, and rename?

Thanks.Try this.  It's not fully tested so instead of renaming the files it will copy them to your %temp% folder from which they can be deleted at will.  When you have tested and proved the script, change the copy line to
ren "!filename!" "!newfilename!"

Code: [Select]echo off
cls
setlocal enabledelayedexpansion

:: Set default directory to the directory containing .mp3 files
pushd path\to\files\|| echo PUSHD FAILED - job terminated&exit /b

:: Loop thru' a bare directory listing of mp3 files, reading each filename
:: into the environment variable %filename%, creating a new environment
:: variable %newfilename% containing %filename% less the first 5 chars
:: then renaming..

for /f "tokens=*" %%1 in ('dir /b *.mp3') do (
    set filename=%%1
    set newfilename=!filename:~5!
    copy "!filename!" "%temp%\!newfilename!"
    )

popd

Quote from: DaveLembke on August 22, 2010, 11:45:34 AM

Looking for a way to trim first 5 character places off of a bunch of file names named
01 - filename.mp3 so that the file is trimmed to a name of filename.mp3 without the 01(space)-(space) before the song title.

I saw a program for sale called better file rename for $20, but was wondering if anyone knew of a way to do it for free through batch using a read in file name and then trim and rename as filename without the first 5 characters leading into the file name? I dont see why batch wouldnt be able to do it, but this exceeds my batching abilities, so a solution would be a learning experience if you could also describe what does what in the batch.

I have about 3000 songs that I want to trim this off of, so I am not sure if there is a way to read in with wildcard *.mp3 for all files in that directory and have it chug through them until they are all renamed without first 5 characters that always start with 01(space)-(space), 02(space)-(space) ect where the leading 2 digits is the track number so maybe ??(space)-(space) can be used as a wildcard type match for the files to test against them, or if the test would be to look for a dash ( - ) at the 4th character place of each file name and if there is a dash at the 4th character place, then trim first 5 character places off of the filename with a read in of that files name, trim, and rename?

Thanks.

what you need is a string manipulation tool that is free and versatile to use. 
you can download sed for windows and then do this

Code: [Select]C:\test>dir /b /a-d *mp3
01 - song1.mp3
02   -   song2.mp3

C:\test>dir /b /a-d *mp3|sed "s/^.[0-9]*[ \t]*-[ \t]*//"
song1.mp3
song2.mp3

Use a for loop to iterate and rename your files. Note it takes care of variable number of spaces between your numbers, not just 5. COOL!  ... I am going to use this right now to trim up the file names. Thanks!!!For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.

The version I have does not work on vista but is fine on XP (its not been updated on download.com since 2006, so I doubt there will be a new version)

Graham Quote from: gpl on August 23, 2010, 12:33:03 AM
For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.
there are alot of such kind of software for renaming files. One can create such a UTILITY with just simple scripting. Quote from: DaveLembke on August 22, 2010, 11:45:34 AM
Looking for a way to trim first 5 character places off of a bunch of file names.

This solution is nearly the same as TCs in reply 1.  TCs is better. Except We show the output.

Reference: 

http://www.dostips.com/DtTipsStringManipulation.php

C:test>Display  trim5.bat

echo off
echo.  >  newmp3.txt
dir /b *.mp3  > mp3.txt
type mp3.txt
echo.

setlocal enabledelayedexpansion
for /f  delims= %%i in (mp3.txt)  do (
set mp=%%i
echo mp=!mp!
set mp=!mp:~5!
echo mp=!mp!
echo !mp! >>  newmp3.txt
copy %%i  !mp!
rem ren %%i  !mp!
rem  del  %%i
)
echo Display Trim5
type newmp3.txt
rem ( will need double quotes for source and destination for the copy command. )

Output:

C:test>trim5.bat
Kalimba.mp3
Maid with the Flaxen Hair.mp3
SleepAway.mp3

mp=Kalimba.mp3
mp=ba.mp3
        1 file(s) copied.
mp=Maid with the Flaxen Hair.mp3
mp=with the Flaxen Hair.mp3
        1 file(s) copied.
mp=SleepAway.mp3
mp=Away.mp3
        1 file(s) copied.
Display Trim5
ba.mp3
with the Flaxen Hair.mp3
Away.mp3
C:test>
243.

Solve : Adding or subtracting days from current date in batch script?

Answer»

Hi,

I'm writing an batch file to create report

In the batch file iam PASSING two arguments:startdate and finishdate

Ex: startdate=07-sep-2009 finishdate=07-sep-2011

I NEED to have script that takes command line argument as input and gives me out currentdate last YEAR and current date next year as mention above example.

currentdate-1 year &AMP; currentdate+ 1year

For example if I pass argument as 07-sep-2010 to batch script I should get ouput as startdate=07-sep-2009 finishdate=07-sep-2011.

Could any one please help?.

Regards,
Anand
you can download coreutils for windows, then use the date command
Code: [Select]c:\test&GT; gnu_date.exe -d "1 year ago"
c:\test> gnu_date.exe -d "1 year"

244.

Solve : MS-DOS training classes?

Answer»

I'm interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, MALICIOUS programing, etc., or is this not true.
Also, more to my subject there was a listing for Wolverton's training in DOS with a coulple of CD's.  Is anyone aware of that or where to go to get classes? Quote from: debo0648 on August 28, 2010, 11:05:22 PM

Im interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, malicious programing, etc., or is this not true.
Also, more to my subject there was a listing for Wolvertons training in DOS with a coulple of CDs.  Is anyone aware of that or where to go to get classes?

http://www.microsoft.com/mspress/books/sampchap/6321.aspx

The book was written in 2002. 

Get a few more comments before you do anything. Quote
I hope to find a way to run my OS/applications under DOS

MS-DOS is an "OS". Quote from: debo0648 on August 28, 2010, 11:05:22 PM
I'm interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, malicious programing, etc., or is this not true.
Also, more to my subject there was a listing for Wolverton's training in DOS with a coulple of CD's.  Is anyone aware of that or where to go to get classes?

DOS doesn't protect you from anything. At all. Not even yourself, in most cases. DOS viruses are probably not as common these days but they are a lot more dangerous then todays viruses, since in those days creating a virus usually meant learning about ASSEMBLY and actually being good with computers, as OPPOSED to just banging out a script as most kiddies do today. So in a sense, you'll be "protected" from modern worms/viruses, but you'll also be "protected" from using new applications. This is like protecting yourself from viruses entirely by shutting the computer off. you're safe but you can't do anything with it.

Additionally, you'll be hard pressed to find a lot of modern software for it. And as to running your "OS" under DOS, (I assume you mean Windows 7) then your not understanding what DOS is. As ST says, DOS is an operating system. Therefore you cannot run another OS "under" it. You can run Shells (like windows 3.1) but you are never going to be able to have a Pure DOS environment beneath Windows 7, or any NT OS, for that matter.Not to be off topic, but if one was to want to use a computer that is immune to infection, one might want to check into a Live Linux Distro like Knoppix which is a Read-Only OS. Not only is Linux the least viral prone, but the Read-Only OS is immune from tampering once burned to CD or DVDi am interest to learnI suggest using a VIRTUAL machine for messing around with shady things. Antivirus will never compare.

http://www.virtualbox.org/
245.

Solve : How to determine the name of batch script while running?

Answer»

Hi all,

Within my BATCH script, I need to find out what is the name of the script that is currently running. Reason... I have multiple different batch files that on completion I want to send an email to a different set of recipients. Am using blat with -tf option. The PLAN is to make the -tf file name parameter dynamic based on the name current of the currently running script.
eg. Assume I have batch files, JOB_A.BAT,  JOB_B.bat etc
In each script, I want to execute blat - tf C:\Mail_Recipients\%%.txt  .....

Question: How do I find out the name of the currently running batch script while it is executing.Parameter %0 gives you the name of the bat (if you have not used SHIFT)%0 gives the command effectively used to invoke the script. This can vary. The actual script name and extension MAY be ISOLATED in every case as %~nx0 or %~dpnx0 for the full drive, path, name and extension.

246.

Solve : %date% - issue on chinese computer?

Answer» HI All

I have few scripts where each of them every time is running is creating log. The log contain current date.
It looks like:
>> %Date%_files
Question is: can be handled on chinese computer CORRECTLY?
Scripts WORKS perfectly fine on computers in Europe but fail on computers in China.
can you help?

example:
echo.
echo.---------------------------------------- >> %Date%_files_from_exceptions_and_ready_folders.Log
echo.the script has been run %date% at %time% >> %Date%_files_from_exceptions_and_ready_folders.Log
echo.---------------------------------------- >> %Date%_files_from_exceptions_and_ready_folders.Log
echo.


this casue script to fail on chinese computer, but is Ok on my comptuer with "european date format".
Do you know how to solve it?
It looks like date format on chinese computers can't be changed due to other issues.

Please advice.

BR
Michalwhat does the Chinese date format LOOK like? Please give an example.
Hi

Something like:
中國人

that generate problem.

BR
Michal
247.

Solve : learn dos without damage?

Answer»

Does exist a PROGRAM to learn dos without damage your computer (with a stupid error)Yes. It's here: http://www.virtualbox.org/
It's called VirtualBox.
Install Windows XP on it.
Then run DOS from there.
Quote from: Big on September 04, 2010, 08:43:50 PM

Yes. It's here: http://www.virtualbox.org/
It's called VirtualBox.
Install Windows XP on it.
Then run DOS from there.

You can't run DOS from Windows XP.BC, you should KNOW by now that I'm referring to the Windows commandline, which he implicitly was referring to, too, as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system.
You might also want to read my degrees list. Quote from: Big on September 04, 2010, 09:12:24 PM
BC, you should know by now that I'm referring to the Windows commandline,
I know what you are referring to.


Quote
which he implicitly was referring to
Maybe, but You cannot know this. But since you seem to think so, what the heck did me mean by "without stupid error?"


Quote
as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system.
And people who are actually talking about DOS happen to use the same term.


Quote
You might also want to read my degrees list.

Don't care.




Big, if you install VirtualBox you can install FreeDOS which is functionally a very close equivalent to MS-DOS. Why do you assert that HP2 was "implicitly referring to" the windows command line?

Quote from: Big
You might also want to read my degrees list.

You are in danger of getting tedious.


Quote from: Big on September 04, 2010, 09:12:24 PM
You might also want to read my degrees list.

I don't see "Physic" in your DEGREE list. Quote from: mroilfield on September 05, 2010, 12:41:20 AM
I don't see "Physic" in your degree list.

He comes from a linguistic family, and did Latin in high school, didn't you know?
What's Virtual Box... More details please Quote from: Big on September 04, 2010, 09:12:24 PM
BC, you should know by now that I'm referring to the Windows commandline, which he implicitly was referring to, too, as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system.
You might also want to read my degrees list.
Linguistic? Hardly. Quote from: HP2 on September 05, 2010, 02:38:23 PM
What's Virtual Box... More details please

http://www.google.com/webhp?rls=ig#rls=ig&hl=en&source=hp&q=virtualbox

What is it

Virtual Box is a program that emulates (immitates) a computer environment by letting you install Windows on that program and letting it launch Windows from within that program (much like when you start your PC).
So this program is basically a virtual computer. It immitates a computer. Runs the Operating Systems (such as Windows XP) that you give to it. You then see your Windows XP inside a window, much like you see a notepad window, or any other window on your desktop. In this case it's the Virtual Box window.

History

This concept is called 'virtualization' and it was needed because it is a lot cheaper and you need less resources.
For example, if the Windows installation that is on that virtual box is corrupt or messy, you can simply delete it and make a new one, like nothing happened.
This is of course less time consuming than having to format your system (yes, even quicker than quick format).

You can do this, because when you tell Virtual Box to make a new 'virtual disk' it will make a fictional harddisk for you, with some GB on it (15 GB for example). It then represents your harddisk that is needed for let's say Windows XP. You then have a 15 GB .iso image on your real hard drive.
You can delete this .iso, containing your Windows XP, when you want.

Purpose

So, finally, my point is that you can test software inside the operating system that is given to Virtual Box.
'Box' is a slang (dialect) for 'computer' (much like the PC tower you have; i.e. analogy 'box').
Thus it means 'Virtual Computer'.


I hope that this was somewhat a good explanation for you, HP 2.
If any further questions, you may ask.
Now I am certain Big is Billrich.
Quote from: Salmon Trout on September 05, 2010, 11:46:27 PM
Now I am certain Big is Billrich.

what are the signs? Quote from: ghostdog74 on September 06, 2010, 12:44:06 AM
what are the signs?

The writing style, certainly, the attitude, and his strategy of creating multiple accounts so that he can first pose as a (usually comically ignorant) questioner with some very simple query and then he can log in as an ENORMOUSLY knowledgeable "expert" who proceeds to answer the question. This thread is an example. He cannot resist the temptation to boastful prolixity. The "members" he creates have a certain feel, a smell ALMOST. A psychiatrist would have a field day with him - note he is calling himself "Big".


248.

Solve : Shortcut?

Answer»

Can we make shortcut with dos???Code: [Select]START "" "C:/path/to/file.exe"
Like that?Like when you make shortcut with right click (...) but with dosDOS (Disk Operating SYSTEM) does not support shortcuts. They are Windows files (.lnk extension). On your XP machine you have a NT command line.

There is a program called shortcut in the NT Resource Kit that can be run from the command line. It is a 6.9 MB download which may be overkill for a single program although there are other useful utilities included.

An alternative is VBScript which came with your XP system. If you decide to go with VBScript post back, we may be able to scrape up an example. Note: VBScripts can be run from the command line for console scripts or from the run BOX for window scripts.

 see here for vbscript example , and IGNORE posts by BillRich

249.

Solve : .bat or .vbs Find within text and Rename File?

Answer»

I have outputted some text files all in the same directory. Each .txt FILE has within a group number, this number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXX i need the script to find this RXC number and rename the file to its corresponding group number, then do the same for all files in the same directory.

would really like this to be a .bat but a .vbs will also work.

Thanks in advance,
Joe Quote from: jmituzas on August 31, 2010, 12:56:20 PM

number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXXi

C:test>type  rxc.bat
echo  off

REM dir /b rxc*  >>  rxc.txt
echo. >> rxc.txt
type rxc.txt

setlocal enabledelayedexpansion
for /f  delims= %%i in (rxc.txt) do (
set x=%%i
set  x=!x:~3!
echo !x!
rem copy %%i  !x!
rem ren %%i  !x!
)
Output:

C:test>rxc.bat
rcx12345
rcx23456
rcx34567

12345
23456
34567


C:test>Hmmmm!

Quote from: OP
I have outputted some text files all in the same directory. Each .txt file has within a group number

I think this means that the group number (RCXnnnnn) is part of the contents of the text file, in other words is part of the text not of the filename which could be anything.. Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "txt" Then    
strFileName = strFile.Name
Set objFile = objFS.OpenTextFile(strFileName)
Do Until objFile.AtEndOfStream
strLine=objFile.ReadLine
If InStr(strLine,"RXC" ) > 0 Then
number=Mid(strLine,4,5) 'Get 5 characters afterwards
objFile.Close
strFile.Name = Trim(number)&".txt"
Exit Do
End If
Loop     
End If
Next
Quote from: T.C. on August 31, 2010, 04:10:48 PM

I think this means that the group number (RCXnnnnn) is part of the contents of the text file, in other words is part of the text not of the filename which could be anything.


C:test>Display    rxc2.bat

echo  off
echo rxc12345 > rxc1.txt
echo rxc23456 > rxc2.txt
echo rxc34567 > rxc3.txt

echo. >  run.txt

findstr rxc  *.txt >> run.txt

echo Display  run.txt
type  run.txt
echo.

setlocal enabledelayedexpansion
rem Will need double quote before skip and after delims=:

for /f  skip=1 tokens=1,2 delims=: %%i in (run.txt) do (
set filename=%%i
set newname=%%j
echo filename=!filename!
echo newname=!newname!.txt
rem copy !filename! !newname!
rem ren !filename! !newname!
)
rem will need double quote around filename and newname for copy or ren

Output:

C:test>rxc2.bat
Display  run.txt

rxc1.txt:rxc12345
rxc2.txt:rxc23456
rxc3.txt:rxc34567

filename=rxc1.txt
newname=rxc12345.txt
filename=rxc2.txt
newname=rxc23456.txt
filename=rxc3.txt
newname=rxc34567.txt
C:test> Quote from: Fields on August 31, 2010, 06:13:31 PM
Code: [Select]C:test>Display    rxc2.bat

echo  off
echo rxc12345 > rxc1.txt
echo rxc23456 > rxc2.txt
echo rxc34567 > rxc3.txt
echo. >  run.txt
findstr rxc  *.txt >> run.txt


how do you know OP has only RXCXXXXX on a line by itself? He MAY have a line like this "troll RXC12345 is here".
and then your script breaks.
Quote from: ghostdog74 on August 31, 2010, 06:38:29 PM

How do you know OP has only RXCXXXXX on a line by itself? He may have a line like this nooutput  RXC12345 is here.
and then your script breaks.


The tokens and delims can be adjusted to account for  as many tokens as needed,
We can also use more than one delims.

for /f  skip=1 tokens=1,2 delims=: %%i in (run.txt) do (



Quote from: Fields on August 31, 2010, 06:52:19 PM
The tokens and delims can be adjusted to account for  as many tokens as needed,
We can also use more than one delims.

for /f  skip=1 tokens=1,2 delims=: %%i in (run.txt) do (





but do you know where RXC12345 will occur in the text? beginning of line? end of line? If it can occur anywhere in the text,  then how do you go about setting your delims and tokens? Quote from: ghostdog74 on August 31, 2010, 06:58:32 PM
But do you know where RXC12345 will occur in the text? beginning of line? end of line? If it can occur anywhere in the text,  then how do you go about setting your delims and tokens?

The original code did not fail. There is a longer name for the new file. The adjustments I MENTIONED will
work but not needed now. If OP request the adjustments we will do it.




Quote from: Fields on August 31, 2010, 07:39:01 PM
The original code did not fail. There is a longer name for the new file.
yes it does. Like your example rxc4.txt,  you now have "nooutput rxc45678 is here" as the new file name. It should be "45678.txt" as the new file name.  Here's a suggestion :

Code: [Select]for .... ( txtfile ) do (
    rem set delim to whitspaces.
    rem go through all the tokens, look for "RXC",
    rem once found, get the substring from 4th character onwards.
    rem create the new file.
)
Quote from: ghostdog74 on August 31, 2010, 08:03:00 PM
yes it does. Like your example rxc4.txt,  you now have \"nooutput rxc45678 is here\" as the new file name. It should be \"45678.txt\" as the new file name.  Here\'s a suggestion :

Code: [Select]for .... ( txtfile ) do (
    rem set delim to whitspaces.
    rem go through all the tokens, look for \"RXC\",
    rem once found, get the substring from 4th character onwards.
    rem create the new file.
)

Yes that will work but I will not look at all the tokens until the OP asks for it.

The long file name is ok with me.
 
Many OPS ask a question and never return.

By the way,  I dont know enough VBS to get your VBS code to run. I have not spent much time with your VBS.  Wll try later. Quote from: Fields on August 31, 2010, 08:52:57 PM
The long file name is ok with me.
its not ok as OP's required specs. He wants to find the RXC number following RXC. (without other alphabets/words)
 
Quote
By the way,  I dont know enough VBS to get your VBS code to run. I have not spent much time with your VBS.  Wll try later.
you don't have to know much to learn how to run a vbscript.
Code: [Select]cscript //nologo myscript.vbs
Quote from: ghostdog74 on August 31, 2010, 05:57:20 PM
Code: [Select]Set objFS = CreateObject(\"Scripting.FileSystemObject\")


I was able to run your vbs file.  The output did not come to the screen  but the vbs did change the names of the original file names.
The original file rxc4.txt with text [ nooutput  rxc45678 is here]
was changed  to utput.txt  and not to 45678.txt.  This is clearly a flaw with the vbs solution
The ops specs were not followed. Please correct


C:\\test>type  ghost831.vbs
Set objFS = CreateObject(\"Scripting.FileSystemObject\")
strFolder=\"c:\\test\"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
        If objFS.GetExtensionName(strFile) = \"txt\" Then
                strFileName = strFile.Name
                Set objFile = objFS.OpenTextFile(strFileName)
                Do Until objFile.AtEndOfStream
                        strLine=objFile.ReadLine
                        If InStr(strLine,\"rxc\" ) > 0 Then
                                number=Mid(strLine,4,5) \'Get 5 characters afterwards
                                objFile.Close
                                strFile.Name = Trim(number)&\".txt\"
                                Exit Do
                        End If
                Loop
        End If
Next

Input:

C:test>findstr  rxc  *.txt

rxc1.txt:rxc12345
rxc2.txt:rxc23456
rxc3.txt:rxc34567
rxc4.txt:nooutput  rxc45678 is here

Output:

C:\\test>dir  *  |  sort

09/01/2010  04:55 AM                11 12345.txt
09/01/2010  04:55 AM                11 23456.txt
09/01/2010  04:55 AM                11 34567.txt
09/01/2010  04:55 AM                29 utput.txt
09/01/2010  04:55 AM               101 1.txt.txt

C:test>type  12345.txt
rxc12345

C:test>type  utput.txt
nooutput  rxc45678 is here

C:test>type  1.txt.txt

rxc1.txt:rxc12345
rxc2.txt:rxc23456
rxc3.txt:rxc34567
rxc4.txt:nooutput  rxc45678 is here
that's easy to change. So now, are you going to change your batch script to do the same?
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder="c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) = "txt" Then    
strFileName = strFile.Name
Set objFile = objFS.OpenTextFile(strFileName)
Do Until objFile.AtEndOfStream
strLine=objFile.ReadLine
m=InStr(strLine,"RXC" )
If m > 0 Then
number=Mid(strLine,m+3,5)
WScript.Echo number
objFile.Close
strFile.Name = Trim(number)&".txt"
Exit Do
End If
Loop     
End If
Next
Quote from: ghostdog74 on September 01, 2010, 04:59:10 AM
Thats easy to change.

Same error as before:  45678.txt is  not created.  utput.txt is created  from the input file rxc4.txt with the
line [ nooutput  rxc45678 is here ] inside of the rxc4.txt file.

The fix for the ghost.vbs did not work.

C:test>Display    ghost901.vbs
Set objFS = CreateObject(Scripting.FileSystemObject)
strFolder=c:test
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
        If objFS.GetExtensionName(strFile) = txt Then
                strFileName = strFile.Name
                Set objFile = objFS.OpenTextFile(strFileName)
                Do Until objFile.AtEndOfStream
                        strLine=objFile.ReadLine
                        If InStr(strLine,rxc ) > 0 Then
                                number=Mid(strLine,4,5) Get 5 characters afterwards
                                objFile.Close
                                strFile.Name = Trim(number)&.txt
                                Exit Do
                        End If
                Loop
        End If
Next


C:test>cscript //nologo  ghost901.vbs

Output:

09/01/2010  08:15 AM                11 12345.txt
09/01/2010  08:15 AM                11 23456.txt
09/01/2010  08:15 AM                11 34567.txt
09/01/2010  08:15 AM                29 utput.txt
09/01/2010  08:15 AM               101 1.txt.txt

C:test>type 12345.txt
rxc12345

C:test>type  utput.txt
nooutput  rxc45678 is here


C:test>type 1.txt.txt

rxc1.txt:rxc12345
rxc2.txt:rxc23456
rxc3.txt:rxc34567
rxc4.txt:nooutput  rxc45678 is here
250.

Solve : Bug...?

Answer»

In some batch files, when I click on them, it open and close automatically and I don't have time to do anything...
WHY?create this batch file

Code: [SELECT]cmd /k %1
then drag the non working batch file it will tell you the errorThis is not a "bug". It is normal. If you start a batch script by double clicking its icon in Windows Explorer it will start in a command window which will vanish when the script terminates. It might be a natural ending or a premature one if there is an ERROR in the code. To see error messages etc you NEED to start the batch file from the prompt by typing its name.
But how to run the batch file WITHOUT this "bug" (call 'd the way you want) Quote from: HP2 on September 06, 2010, 12:32:16 PM

But how to run the batch file without this "bug" (call 'd the way you want)

It isn't a bug, Bill, as you well know. Furthermore, the answer is in my post above, which you should read more attentively. You probably know this too. Did Big get banned?