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.

601.

Solve : copy from within batch file to a text file ERROR!?

Answer»

i am trying to copy the line below to a new text file using batch file. The line is given below

objIEA.Navigate "http://"&WScript.Arguments(0)&"/VIDEO?session=3&alphabet=83&channel="&WScript.Arguments(1)&"&profile="& WScript.Arguments(2)

This is the line. what i did is something LIKE this and i am getting error while executing batch file.

ECHO objIEA.Navigate "http://"&WScript.Arguments(0)&"/video?session=3&alphabet=83&channel="&WScript.Arguments(1)&"&profile="& WScript.Arguments(2) > test.txt

THe above command is giving me error. I want to copy the exact line shown above to a new file and in reality the new file will have .vbs extension. i mean the new file in reality should be test.vbs but it is not working for even test.txt

please helpThe AMPERSAND (&) character is a control character in batch, it is the command separator, and if you want to use it in an ECHO statement you have to "escape" it with a caret (^), unless it is within quotes.

Code: [Select]ECHO objIEA.Navigate "http://"^&WScript.Arguments(0)^&"/video?session=3&alphabet=83&channel="^&WScript.Arguments(1)^&"&profile="^& WScript.Arguments(2) > test.vbs
Code: [Select]C:\>echo hello & goodbye
hello
'goodbye' is not recognized as an internal or external command,
operable PROGRAM or batch file.

C:\>echo hello ^& goodbye
hello & goodbye

C:\>echo "hello & goodbye"
"hello & goodbye"
thank you very much. very much appreciated

602.

Solve : Updateing quicken 4?

Answer»

HI,
I tried to find an answer in your forum but no LUCK.   I need to update my quicken 4 files and when I got the update files it states that I MUST install in dos not dos prompt.  I must be totally out of windows for it to work.  It has been years since I have worked in dos and I can not remember how to get to it with out the prompt.  I also need a dos zip to open these updates.  Does anyone know how to go about doing this.  Any and all help would be greatfully accepted.   I need to do this as I have v2 and I need to update to V7.    I can not afford a new quicken and I do not LIKE money.   Please help if you can.
Thank you,  
RobynIt does not appear that Quicken 4 is suported in any version of Windows without DOS.  So...no WinME, no Win2k, no WinXP.
If you have WIN95 or Win98, it will work.  Hit F8 key while Windows is trying to load, then select Command Prompt.
http://www.intuit.com/support/quicken/updates/qkn_updates_win4.html

603.

Solve : Launch a new script within a .cmd file??

Answer»

Hopefully a easy question for you guys,
I WANT to launch a JAVA script within a .cmd file so I can add a printer on a remote workstation.
Basically I have no IDEA on how to do this. I have found a script that I saved as a .VBS to add a printer on a local workstation but would like to amplify this so it works on a remote workstation.
The code I have come up with is this but it doesn't work:-
*********************************************
echo off
cls
echo Add Printer %2 on %1
echo.

if {%1}=={} goto Syntax
if {%2}=={} goto Syntax

psexec \\%1 -i -d -s notepad

Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "%2"


:Syntax
echo Adds a printer on the target workstation
echo.
echo USAGE: Printer [Computername] [\\Server\Printer]
echo.

:End
pause
*********************************************
This works up until psexec launches notepad on the remote workstation.

What I would like to know is how to add the the Bold code to the notepad window that launched and then to save it on the workstation as a .vbs file. I think then I will be able to figure out the rest.

Is this possible?
Any replies would be very helpfull...

604.

Solve : Reading from a txt file - spaces?

Answer»

Hi,

I have the following code and simply need one thing fixed - the Schemes.txt file contains a list of schemes and some schemes have spaces, how do I get the code to read in the schemes including the spaces?

FOR /F %1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\"%1

Many thanks. Quote from: jgkwork on October 25, 2011, 08:20:44 AM

FOR /F %1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\"%1

You just need to specify delimiters as carraige returns.

FOR /F "delims=" %1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\"%1


Check out this post for a more detailed explaination. Quote from: Raven19528 on October 25, 2011, 09:48:34 AM
You just need to specify delimiters as carraige returns.

FOR /F "delims=" %1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\"%1


Check out this post for a more detailed explaination.

Hi - thanks for that, I tried this code but it did exactly the same thing i.e. as soon as it encountered a space it went to the next line - any thoughts?Sorry should give some more info - I get the following error when running your code but the error says these folders already exist but the folder is empty before running the code. I have blanked out some of the code as it has my name:



[regaining space - attachment deleted by admin]If you are using these commands from a batch script you need to double up on the % e.g. %%1

The directories being created MAY have spaces in the name so you must include the trailing %%1 inside the " like so:

Code: [Select]FOR /F "delims=" %%1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\%%1"
Quote from: Dusty on October 26, 2011, 03:00:44 AM
If you are using these commands from a batch script you need to double up on the % e.g. %%1

The directories being created may have spaces in the name so you must include the trailing %%1 inside the " like so:

Code: [Select]FOR /F "delims=" %%1 IN (\\vfile1\cfp\ICT_Only_Templates\All_Scripts\Schemes.txt) do MD "\\vfile1\cfp\Housing Management\Housing Schemes\%%1"

Thanks - I'm just running this directly from a command prompt. When I run the above code I get the attached message??

[regaining space - attachment deleted by admin]OK, thanks for the clarification, now REVERT to single %
Quote from: Dusty on October 26, 2011, 03:17:06 AM
OK, thanks for the clarification, now revert to single %

Whoohoo - that works great, big thanks for that and to everyone who HELPED me get there.Thanks for coming back to REPORT your success.

Good luck.
605.

Solve : Help with cd and mkdir (I think)?

Answer»

My computer is a gateway using win7 with AMD Dual Core II X2 240 ~2.8 ghz, 4 gigs of ram, DX11, 500 gig hdd (can't find the manufacturer).  The whole computer is a touch screen bought from bestbuy.  I use the computer for home and work.  My question is about installing python (from learnpythonthehardway.org).

The question is specifically how to run python from the cmd prompt (installed in c:\python27), how to make a directory (mkdir?), change a directory (cd...doesn't work for me, I know I'm doing it wrong somehow) and how to create a file in it.  Here are the directions (sorry for the block of TEXT):

Find your "Terminal" program. It's called Command Prompt. Alternatively just run cmd.
Make a shortcut to it on your desktop and/or Quick Launch for your convenience.
Run your Terminal program. It won't look like much.
In your Terminal program, run python. You run things in Terminal by just typing their name and hitting RETURN.
If you run python and it's not there (python is not recognized..). Install it from http://python.org/download
Make sure you install Python 2 not Python 3.
You may be better off with ActiveState Python especially when you miss Administrative rights
Hit CTRL-Z (^Z), Enter and get out of python.
You should be back at a prompt SIMILAR to what you had before you typed python. If not find out why.
Learn how to make a directory in the Terminal. Search online for help.
Learn how to change into a directory in the Terminal. Again search online.
Use your editor to create a file in this directory. Make the file, "Save" or "Save As...", and pick this directory.
Go back to Terminal using just the keyboard to switch WINDOWS. Look it up if you can't FIGURE it out.
Back in Terminal, see if you can list the directory to see your newly created file. Search online for how to list a directory.

I have python 2 installed in the afore mentioned directory.  That is as far as I got.  I am sure there are some shortcuts I could take to just start coding, but this is my first time, and I want to be as thorough as possible.  When I run cmd, I am lead to c:\users\blahblahmycomputername>

I try to change directory to c:\Python27, and "the system can not find the path specified" appears.  DIR works, and I can fish around in favorites etc all the things in normal \users, but nothing more.  I'm sorry for these probably simple and easy to figure out questions, but I've spend over 2 hours trying to figure it out on this site, and I'm nearing a wits end.  Any assistance is appreciated

shairgjI figured it out.  Thank you for having this forum/site, I found the solution finally.  Capitalization matters?  Oh my stars.In some cases it does...

Sorry that's the best Pun i could come up with at the time... Quote from: shairgj on October 25, 2011, 03:45:08 PM

Capitalization matters?

Not where Windows filenames and paths are concerned. Please explain more.
606.

Solve : A program to...?

Answer»

So I'm designing a program to take over the world... Anyone want to help?  (I'm bored today and thought I would entertain myself)

Here's what I have so far:
Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "delims=" %%G in ('dir "World" /s /b') do (
  set location=%%~dpG
  echo %%G | find "King"
  if not errorlevel 1 (ren %%A !location!ME)
)
echo You are now king of the world!
echo Have a good day, SIRE!
start evillaugh.mp3
pause
QUOTE

So I'm designing a program to take over the world... Anyone want to help?

That sounds like a GENIUS plan brain. . . Reminds me of watching that show when I was a kid.POIT ! ! Quote from: patio on October 26, 2011, 02:39:33 PM
POIT ! !
Quote
   Poit    128 up, 15 down
A nonsensical exclamitory used in many CARTOONS, in many situations. Dextor's Lab shows "->poit<-" when Dextor teleports. Another randon cartoon showed ->poit<- when someone got slapped.
Brain: "Poit... What is poit? Do you mind telling me that?"
Pinky: "Well... it's a lot like 'Narf or Zort..."
Urban Dictionary. Quote from: Geek-9pm on October 26, 2011, 04:20:28 PM
Dextor's Lab shows "->poit<-" when Dextor teleports.

I loved that show too!

So ideas...Dextor vs. Brain...who wins?

I vote Dextor, he was able to keep a 3,000 acre labratory (not sure exact size, but it was big) hidden from his parents through the entire length of the show and Brain was never actually able to take over the world. So Dextor definetly gets a POINT for achieving goals. Quote from: Raven19528 on October 26, 2011, 04:44:42 PM
So ideas...Dextor vs. Brain...who wins?
Twilight Sparkle.
607.

Solve : Checking File Size?

Answer»

I need to write a batch file that goes out, checks the size of a file (ie asjob.txt) and DETERMINES whether or not this is a 0k file or not, If the file is 0k it should goto the next check, if it is 1k or more it should execute a psservice/stop COMMAND.

I would appreciate if someone can give me a HAND in checking the filesize and USING it in either an if then goto command?

608.

Solve : PRIMARY AND LOGICAL DRIVES?

Answer»

:'(I KEEP TRYING TO REINSTALL WIN98 AFTER FOLLOWING INSTRUCTIONS ON CH000569 AND GET THE MESSAGE WINDOWS SET UP REQUIRER 7340032 BYTES AVAILAIBLE AND THEN JUST STOPSAll Caps is SHOUTING.  No need to shout, we HEAR you.  Message you are getting means:  "hard drive is full".

Is this new install, reinstall, upgrade?  Maybe you want to format hard drive 1st.I FORMATED THE HARD DRIVE FIRST BUT THE PROBLEM SEAMS TO BE IN THE PRI DOS AND EXTEND DOS IN THE FDISK I THINK ! I TRYED TO DO THE PARTITION STATUS ECT AND F***** UP (FORGOT TO WRIGHT DOWN THE SETTINGS FIRST SHOOT ME LATER) ALL HELP WOULD BE THANKFULLY RECIEVED     BIG THANKS TO ALL I MANAGE TO REINSTALL WIN 98  AND MY FARTHER_IN_LAW IS PLEASED AS HE JUST TOOK IT HOME IF HE LIKES HE BUYS HE SAID SO AGAIN THANKS

609.

Solve : Print and save log of activity of computer.?

Answer»

Hi,
How can I PRINT or SAVE  a file for  logs of COMPUTER activity.


Many thanks


Bill2004Hi,
I recalled we had option to use Dos command to print logs of computer activity 10 YEARS ago.
Is any one know NEW MS-Dos command ?

Many thanks


Bill2004where are your logs bill....just click on them...file print..

610.

Solve : Spinning / when running a file in a batch?

Answer»

when I START a XP Hotfix in a batch, how do I GET a line to SPIN showing that the machine is WORKING?

611.

Solve : Batch file to copy from local drive to net share.?

Answer»

I have the following batch file that I would like to MODIFY too copy the FILES that it lists in the Allfiles.txt file to the U:\. Can anyone assist with the proper syntax.

C:
dir c:\*.doc, *.xls, *.ppt, *.PAB, *.pst, *.mab, *.rtf, *.pdf, *.mdb /s /b>c:\Cdrive.txt
d:
dir d:\*.doc, *.xls, *.ppt, *.pab, *.pst, *.mab, *.rtf, *.pdf, *.mdb /s /b>c:\Ddrive.txt
e:
dir e:\*.doc, *.xls, *.ppt, *.pab, *.pst, *.mab, *.rtf, *.pdf, *.mdb /s /b>c:\Edrive.txt

c:
type cdrive.txt>allfiles.txt
type ddrive.txt>>allfiles.txt
type edrive.txt>>allfiles.txt

u:
md MyDocs_oldPC

cd MyDocs_oldPC

md %username%

cd %username%

md favorites
md personal
md desktop


c:

cd\

cd winnt\profiles\%username%

xcopy /s favorites u:\mydocs_oldpc\%username%\favorites
del /Q /s favoritesits been awhile SINCE i used the "FOR IN DO"  but i think you can copy using it ex.

FOR c:\*.pdf DO copy d:\*.*

I've never worked with the IN set so I'm not sure how the set must be structured.

612.

Solve : Clear a file??

Answer»

Okay, this is a very nooby question, but I'm no expert.
How do I simply clear a text FILE of all its contents?
I was THINKING something like:
CODE: [SELECT]echo  >file.txtbut that would ADD in a space.This may help:

Code: [Select]type nul > file.txt

Good luck.  Thanks!

613.

Solve : Batch file Var output help needed?

Answer»

I need a few things

1) need to pass a var to a subroutine to be use in subroutine
Code: [Select]echo. this is a test
call :test (need to pass var (test1)
call :test (need to pass var (test2)
call :test (need to pass var (test3)
:end

:test1
echo. This is (insert variable passed)
goto :eof


Result output should be
Code: [Select]This is test1
This is test2
This is test3


2) I need to be able to create a config file to read and write to with ability to modify a particular line within the config file.

Example:
I want to give the user the ability to select a particular directory or create a new directory or delete a created directory listing.

I would want a subroutine menu created from the config file and what ever lines are in the config file to create that many options.
Config file:
Code: [Select]"C$\testfolder0\"
"C$\testfolder1\"
"C$\testfolder2\"
"C$\testfolder3\"
"C$\testfolder4\"

Menu output:
Code: [Select]Directory select menu:

1) C$\testfolder0
2) C$\testfolder1
3) C$\testfolder2
4) C$\testfolder3
5) C$\testfolder4
6) Create New Directory Entry
7) Delete a Directory Entry

Select Directory:



I would then need the result set to a variable to be RETURNED from the subroutine and sent to another subroutine and used in connecting to that directory on a computer (we are copying files to 10 backup servers often but different files and to different folders)
Code: [Select]XCOPY  *.* "\\192.168.1.110 (Variable)"
XCOPY  *.* "\\192.168.1.120 (Variable)"
XCOPY  *.* "\\192.168.1.130 (Variable)"
Quote

echo. this is a test
call :test (need to pass var (test1)
call :test (need to pass var (test2)
call :test (need to pass var (test3)
:end

:test1
echo. This is (insert variable passed)
goto :eof

1. pass literal strings

Code: [Select]echo. this is a test
call :test test1
call :test test2
call :test test3
:end

2. pass variables

Code: [Select]echo. this is a test
call :test %test1%
call :test %test2%
call :test %test3%
:end


Either case, subroutine shows what is passed:

Code: [Select]:test1
echo. This is %1
goto :eofThanks for your help. That work like i needed.

now another question about var's

im doing the following subroutine:
Code: [Select]
call :s1ofc "Server 1"
PING 192.168.1.110 -n 1| FIND "bytes=" > NUL
call :s2ofc "Server 1"
XCOPY  *.* "\\192.168.1.110\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k
call :s3ofc "Server 1"
GOTO :EOF



::===========================::
:: Screen1 ouput for copying ::
::===========================::
:s1ofc
echo.
echo. -----------------------------------------------
echo.
echo. Copying files to %1
echo.
echo. Connecting to %1...
GOTO :EOF

::===========================::
:: Screen2 ouput for copying ::
::===========================::
:s2ofc
IF ERRORLEVEL 1 ECHO.   Connection failed... && ECHO.     Skipping %1...&& echo %date% %time% Connecting to %1 failed>> .\LOG.TXT && ECHO. && GOTO :EOF
echo.   Connection established...
echo.
echo.     Copying STARTED...
echo.
pause
GOTO :EOF


::===========================::
:: Screen3 ouput for copying ::
::===========================::
:s3ofc
echo.
if errorlevel 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time% Insufficient disk access, space, on %1>> .\LOG.TXT
if errorlevel 5 echo echo %date% %time% Disk write error occur99red on %1>> .\LOG.TXT
echo.
echo. Copying files to %1 Complete...
PING 1.0.0.0 -n 1 -w 2000 >NUL
GOTO :EOF

I need help with my if errorlevel's
I want that If the errorlevel is true that on that line i can enter in a var and pass it back to the original routine to run an if STATEMENT.

Code: [Select]call :s1ofc "Server 1"
PING 192.168.1.110 -n 1| FIND "bytes=" > NUL
IF erq1=1 goto: eof
call :s2ofc "Server 1"
XCOPY  *.* "\\192.168.1.110\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k
call :s3ofc "Server 1"
GOTO :EOF

::===========================::
:: Screen2 ouput for copying ::
::===========================::
:s2ofc
set erq1=0
IF ERRORLEVEL 1 ECHO.  Connection failed... && ECHO.     Skipping %1...&& echo %date% %time% Connecting to %1 failed>> .\LOG.TXT && ECHO. && erq1=1 && GOTO :EOF
echo.   Connection established...
echo.
echo.     Copying started...
echo.
pause
GOTO :EOF

but for some reason erq1 always equals 0

Thoughts?if you use the archaic obsolete MS-DOS method in this format:

(N is a number)

IF ERRORLEVEL N action

You need to understand that the test is passed if the errorlevel is N or greater. Thus if you are testing for different errorlevels you have to do the tests in descending order. The action is usually GOTO a label because otherwise every level below the one you want will be executed also. (do you understand why?)

if errorlevel 5 action
if errorlevel 4 action
if errorlevel 3 action
if errorlevel 2 action
if errorlevel 1 action

Better to use the (since Windows 2000) NT type errorlevel variable where the order does not matter and you can specify more tests and the test can be exactly what you want

e.g.

if %errorlevel% equ 4 action

if %errorlevel% gtr 0 action

Also, in Windows, && does not mean what you think it does.
ok i see why i would want to use %errorlevel%

how would i fix this line if i should not use &&?
Code: [Select]if %errorlevel% 5 echo echo %date% %time% Disk write error occurred on %1>> .\LOG.TXT
if %errorlevel% 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time% Insufficient disk access, space, on %1>> .\LOG.TXT

Now is there anyway to output a list of files that have an error?

Currently it will only tell me that there was an error but not what files were the cause.

Is there something better to use than xcopy? (FREE for commercial use)

Running on XP win7 server2003 & server2008

Quote
how would i fix this line if i should not use &&?

Just use one ampersand (&) if you merely want to join commands in one line

In Unix and Windows & is the command separator

command1 & command2 means "execute command1 and then execute command2"

&& is a conditional EXECUTION operator

command1 && command2 means "execute command1 and if command1 returns a zero errorlevel then execute command2"

The opposite is ||

command1 || command2 means "execute command1 and if command1 returns a non-zero errorlevel then execute command2"

Quote
Is there something better to use than xcopy? (Free for commercial use)

Many people like Robocopy



Thanks
614.

Solve : Batch keypress help?

Answer»

Ok so i have a program that closes every 30 minutes and i wanted it to loop so it goes infinity. first my thought camed to that i could make it loop every 30 min but then i remembered that i have to set it up after every startup so now i wonder if any of u experienced bat coders could make me a bat code or say the commands to make it happen

this is the order

Start (program)
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press Enter
Wait a minute for next action
Press TAB
Press TAB
Press Enter
Wait a minute(for next action
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press TAB
Press Enter
And a timer at the end on 31 minutes and then start this bat up again

Please i would love an answer would really mean alot  This would be a lot more easily done in a VBScript. I'm currently getting my feet wet with VB, so I do not know all of the nuances about the CODING, but as a ROUGH go at it, try:

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WshShell.Run "Program", 1
WshShell.Sleep 60

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1860000
Loop

This script will loop indefinetely, so if you are needing it to stop at any point, you are going to have to kill the process manually or look into coding some exit do conditions. Also, the sleep numbers are in milliseconds, so if you need to make the sleep times between sending the keys longer, you just need to increase that number.wont work ?= :S
 is coming up wich in english means

Script .... u know that urself

Row 3
Characters 16
Error : statement expected
code : 800A0400
Source: Compile error in Microsoft VBscript

Code screen: Quote from: Raven19528 on November 03, 2011, 11:24:11 AM

This would be a lot more easily done in a VBScript. I'm currently getting my feet wet with VB, so I do not know all of the nuances about the coding, but as a rough go at it, try:

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WshShell.Run "Program", 1
WshShell.Sleep 60

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1860000
Loop

This script will loop indefinetely, so if you are needing it to stop at any point, you are going to have to kill the process manually or look into coding some exit do conditions. Also, the sleep numbers are in milliseconds, so if you need to make the sleep times between sending the keys longer, you just need to increase that number.
Quote from: sobbo90 on November 03, 2011, 01:36:50 PM
wont work ?= :S
 is coming up wich in english means

Script .... u know that urself

Row 3
Characters 16
Error : statement expected
code : 800A0400
Source: Compile error in Microsoft VBscript

Code screen:

any help please :S
You need quotation marks and a file extension, I think.
Like:
Code: [Select]WshShell.Run "C:\blah\blah\blah\blah.exe", 1Syntax error, line 3 of the script. Ah I see Cheezey beat me to it. The shell object expects a string. Strings have quotes. If the program you want to run is not on the PATH then you need the full path, filename and extension.

Quote from: Cheezey on November 03, 2011, 02:00:31 PM
You need quotation marks and a file extension, I think.
Like:
Code: [Select]WshShell.Run "C:\blah\blah\blah\blah.exe", 1
Ok fixed that and now i did put it in the same directory did fix quotes and get full location but it says it cant find the file
This is error picture :

Uploaded with ImageShack.us
The Fel:(Error) means that it cannot find the file
This is the code

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WshShell.Run "C:\Users\Linus\Desktop\wowrob\WowRobot Evolution", 1
WshShell.Sleep 60

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1860000
LoopIs WowRobot Evolution a program file?
Quote from: Salmon Trout on November 03, 2011, 02:04:16 PM
Syntax error, line 3 of the script. Ah I see Cheezey beat me to it. The shell object expects a string. Strings have quotes. If the program you want to run is not on the PATH then you need the full path, filename and extension.

OKEY tried to fix this but now i get error where it says that it cant find it even thoe i did put the script in same directory and did full path length this is code

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WshShell.Run "C:\Users\Linus\Desktop\wowrob\WowRobot Evolution", 1
WshShell.Sleep 60

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1860000
Loop 



Uploaded with ImageShack.us At the "Fel" (ErroR) it says cannot find the file. Quote from: Salmon Trout on November 03, 2011, 02:26:33 PM
Is WowRobot Evolution a program file?
Quote from: Salmon Trout on November 03, 2011, 02:26:33 PM
Is WowRobot Evolution a program file?
Filetype is Program.exetestet to add .exe on the end of the file path. no success Quote from: Salmon Trout on November 03, 2011, 02:29:42 PM


Okey i changed some directory names and file names etc...
 
do u see anything in this script that should't work?

Code: [Select]Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WshShell.Run "C:\Users\Linus\Desktop\wowrob\hejsan\Enkel.exe", 1
WshShell.Sleep 60

WshShell.SendKeys "{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{ENTER}"
WshShell.Sleep 1000

WshShell.SendKeys "{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}"
WshShell.Sleep 1860000
Loopdoes this file and path exist exactly as SHOWN?

"C:\Users\Linus\Desktop\wowrob\hejsan\Enkel.exe"

Don't PM for special help.

You should wait for Raven to answer, it's his script.

Shouldn't it be Wscript.sleep?

Quote from: Salmon Trout on November 03, 2011, 02:55:21 PM
does this file and path exist exactly as shown?

"C:\Users\Linus\Desktop\wowrob\hejsan\Enkel.exe"

Don't PM for special help.

You should wait for Raven to answer, it's his script.

Shouldn't it be Wscript.sleep?

Thanks now its no error and yes it did i dont know if i did get dot or something in it cause now it launches and same with sleep command. i only have one problem left after i started the program i need it to get "TARGETED" as the window that i am on so that the tab and enter have any effect cause now it only starts and then it presses tab and enter in the same folder as the script

Yeah sorry for that wont do that again
615.

Solve : xcopy error report to txt file help.?

Answer»

I am copying large amounts of files to different servers using the following command

Code: [SELECT]XCOPY  *.* "\\192.168.1.99\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k

How can I output individual file errors to a LOG.TXT file?

Currently I have this, but i need more detailed info of what was not copied. not just that an error occurred withing the 100+ files copied. I WANT to know what files were not copied.
Code: [Select]if errorlevel 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time% Insufficient disk access, space, on Serve 1>> .\LOG.TXT
if errorlevel 5 echo echo %date% %time% Disk WRITE error occurred on Server 1>> .\LOG.TXT
I havent used xcopy much, but if it outputs errors to the screen, you can CAPTURE them with

Code: [Select]XCOPY  *.* "\\192.168.1.99\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k > LOG.TXT 2>&1which copies both 'normal' and error messages

616.

Solve : How to delay the execution of a file??

Answer»

I want to know how to delay the execution of a batch file for some hours
Ty regards
Gellytry USING the task scheduler in windows or look AROUND the web for some old EXTERNAL .com files that will start your batch ..   Some of the old Norton utilities may have had something along this line.  You'll have to find a really old VERSION thats pure dos.  You might look at some of the EXPANDED dos functions that must be turned on using the cmd \? , there is a %time% function which may serve your needs

617.

Solve : getting a file's directory?

Answer»

Hi all,

I have a file called myfile.bat in the C:\A\B directory.  The file is normally run from C:\A not the file's directory of C:\A\B.  I want to set a variable within myfile.bat to KNOW that it is in C:\A\B.  How do I do this?  

When I try %cd% I always get "C:\A" since that's the WORKING directory.

Any help would be appreciated.  FYI, I am USING Windows XP.

Thanks,
Ajit

use the "if exist c:\a\b\myfile.bat "

then TAKE some action based on findings

forgot to set the variable..

"if exist c:\a\b\myfile.bat set filefound = T "

now the variable %filefound% contains the result.

618.

Solve : Extract network alias in batch file?

Answer»

I am trying to use the hostname as a conditional in a batch file.  I would like to use the alias (not %COMPUTERNAME% mind you) I added to the hosts file and have to make no other CHANGES (i.e. set an env var at startup).  This would be equivalent to doing a "hostname -a" in UNIX and greping for the alias name.  I haven't found any EVIDENCE that parsing exists using batch so I guess I just need a command that will return that alias.  Is it out there or any nifty WORK arounds?

ThanksIm not a network guru, but if the %computename% provides the name and alias you might be able to extract the alias using the expanded SET command.

619.

Solve : How do u use EDLIN i a batch file??

Answer»

If i use edlin in a batch file it loses control because of the * prompt that appears after the edlin execution. Is there anyway to over come this???Is there any other command that can SEARCH and replace stringsyou might be ABLE to use the expanded dos options to do the JOB..  Look for info on the SET command in its expanded form.  It allows for string replacements and other features.

620.

Solve : BAT file to copy a file to a different name every time?

Answer»

I would like to be able to do the following in a bat file , if possible ,

Copy a file called chauffeur.accdb to a file called chauffeur1.accdb
 
The next time the bat file is run copy the file to chauffeur2.accdb . the next time to chauffeur3.accdb etc
 
also to throw into the mix delete the oldest version (retaining 5 copies on disk)
 
Many thanks
 
Thanks David

Works well

Regards

ianWho's David ? ?

Did Bill PM you ? ?IAN, please post "David"'s code. This is not a private help service. (What is his USERNAME?)


Addressing the requirements expressed in the post that opened the thread, one way of doing this, it seems to me is:

Each time the script is run:

check if chauffeur1.accdb exists,
if it does,
check if chauffeur2.accdb exists
if it does not,
copy (or rename) chauffeur.accdb to chauffeur1.accdb
(repeat for 2 to 6)

If the new filename was chauffeur5.accdb (or less)
exit
If the new filename was chauffeur6.accdb
delete chauffeur1.accdb
for n=2,3,4,5,6: rename file chauffeur(n).accdb as chauffeur(n-1).accdb
exit

Tomorrow, the code!
Quote from: Salmon Trout on November 04, 2011, 06:00:26 PM

Tomorrow, the code!

Code: [SELECT]echo off
set maxnum=5
set filenum=1
:loop
if exist chauffeur%filenum%.accdb set /a filenum +=1 & goto loop
ren chauffeur.accdb chauffeur%filenum%.accdb
if %filenum% leq %maxnum% goto end
set /a oldnum=1
set /a stopnum=%maxnum%+1
:renum
set /a newnum=%oldnum%-1
ren chauffeur%oldnum%.accdb chauffeur%newnum%.accdb
set /a oldnum+=1
if %oldnum% leq %stopnum% goto renum
del chauffeur0.accdb
:endHi Salmon Trout

Your code works well but what it doesn't do is retain the original chauffeu.accdb therefore I would have to change my desktop SHORTCUT everytime I ran my DB

best regards

Ian Quote from: ian1956 on November 05, 2011, 07:28:24 AM
what it doesn't do is retain the original chauffeu.accdb therefore I would have to change my desktop shortcut everytime I ran my DB

Answered via PM but we might as well let the whole world see...

Code: [Select]echo off
set maxnum=5
set filenum=1
:loop
if exist chauffeur%filenum%.accdb set /a filenum +=1 & goto loop

REM uncomment the next line if you want to RENAME chauffeur.accdb to the next available number (1-5)
REM ren chauffeur.accdb chauffeur%filenum%.accdb > nul

REM uncomment the next line if you want to COPY chauffeur.accdb to the next available number (1-5)
REM copy chauffeur.accdb chauffeur%filenum%.accdb > nul

if %filenum% leq %maxnum% goto end
set /a oldnum=1
set /a stopnum=%maxnum%+1
:renum
set /a newnum=%oldnum%-1
ren chauffeur%oldnum%.accdb chauffeur%newnum%.accdb
set /a oldnum+=1
if %oldnum% leq %stopnum% goto renum
del chauffeur0.accdb
:end


Note: chauffeur0.accdb is the oldest file that has dropped off the bottom of the list; instead of simply deleting it you could move it somewhere else to archive it if you wanted to.


Hi Salmon Trout

Much appreciated works well

Best regards

Ian
621.

Solve : How to make a batch file full screen without making a shortcut??

Answer»

Does anyone here know how to make a batch file full screen without making a shortcut?This question was answered before by SlayerOf.

Code: [SELECT]echo off
reg query HKEY_CURRENT_USER\Console /v FullScreen | find "1" >nul
if %errorlevel% == 0 goto continue
reg add HKEY_CURRENT_USER\Console /t reg_dword /v Fullscreen /d 1 /f >nul
start %0

:continue
rem your command goes here

pause

exit Hi guys

Have tried this but how do you reverse the action

when running any BAT file now for 1 user (the user that I ran this code on) I dont see the script at all

But when I change user and run any bat file I see the script running

IanYou could also have an open.bat file to open it with the following:

Code: [Select]start /max C:\program.bat

Then you can use the open.bat for when you want it full screen and just the regular command when you don't. SIMPLE, but it works.Hi Guys

Thats not exactly what I wanted to convey

After running this script under 1 user name , when I now run cmd.exe I don't even see the shell box on screen . But when I switch user (of which I haven't run this script) and run cmd.exe I see the shell box.

I am assuming that the script has done something to the First users settings.

regards

Ian

622.

Solve : renaming multiple files in a different directory?

Answer»

Hi all,

I WANT to rename files which are present in a different directory from the batch file location.

batch file location : C:\users\god\desktop\batch.bat
rename files location : C:\users\god

Only two files will be there apyo042a_yyyy_mm.dat and apyo042a_yyyy_mm.done ..
I want it to be renamed as
yyyy_mm_dd_apyo042a_yyyy_mm.dat
and
yyyy_mm_dd_apyo042a_yyyy_mm.dat


date appended front will be currentdate and year,month appended last was the date when the files reached that directory. That year,month will change every month. thats the tricky part. Else i can rename like

rename c:\users\god\filename.* yyyy_mm_dd_filename.*


But for this situation i dont know whats the WAY. I am doing this through batch. and the path is taken as a parameter.

Please advise.

You can use chdir like below and just include the filename. \.. is relatively the folder above the current. Either way will WORK, don't do both.

Code: [Select]chdir C:\Users\god Code: [Select]chdir ..THANK you. I figured ANOTHER way by using forfiles.


forfiles /p %1 /m *.dat /c "cmd /c rename file %DATE_DIS%[email protected]"
forfiles /p %1 /m *.txt /c "cmd /c rename file %DATE_DIS%[email protected]"

Thanks anywayCertainly. If you need help in the future, I'll be here.

623.

Solve : [Tutorial] Manually Encrypting Batch Files [Easy]?

Answer»

Ok, this is my first official tutorial. Here we go!

Description: This tutorial will show you how to make wicked looking batch files that are encrypted to fit your desires. HOWEVER, it is best to use a BAT to EXE compiler/converter in some cases. This will work for most batch files. Have fun!

Step 1: Open Notepad and type the following code:

Code: [Select]echo off
set aa=He
set bb=ll
set cc=o
set dd=Wo
set ee=rl
set ff=d
set gg=!
set hh=I
set ii=am
set jj=an
set kk=en
set ll=cr
set mm=yp
set NN=te
set oo=d
set pp=ba
set qq=tc
set rr=h
set ss=fi
set tt=le
set uu=!!
set vv=!!
echo %aa%%bb%%cc% %dd%%ee%%ff%%gg%
echo %hh% %ii% %jj% %kk%%ll%%mm%%nn%%oo% %pp%%qq%%rr% %ss%%tt%%uu%%vv%
pause >nul
Now save this as "whatever.bat". Now run it. It should say "Hello World! I am an encrypted batch file!"

Now, onto explaining this:

The variables are set to certain words and phrases, or word parts. This means that you can scramble the variables however you want, just don't mess with the final two echos in this case. FINALLY, all of the variables come together in perfect harmony in a final echo. There you go! An encrypted batch file! That is not encryption.
However, obfuscation is serious business, you can have a future in politics.
We can not go on any further,
- there are forum rules on  this sort of thing.
  problem being that this only encrypts what is output...The other problem is writing a bunch of batch/script codes that accomplish nothing...

But i imagine it's good practice...Carry on...You posted this EXACT same script elsewhere...Where would someone on here find it? Quote from: lmsmi1 on November 05, 2011, 09:58:31 PM

Where would someone on here find it?

in the bin? Quote from: BC_Programmer on November 05, 2011, 10:05:04 PM
in the bin?
Well said BC, well said. Quote from: lmsmi1 on November 05, 2011, 07:06:58 PM
this is my first official tutorial

What is "official" about it? It is your very far from first piece of useless nonsense. Why should anybody accept a "tutorial" from an idiot? Or rather a bumptious kid who has LEARNED a few basic commands, but not how to use them for anything anybody would want.

By now you should have got the hint, but it seems not...

Quote from: BC_Programmer on November 05, 2011, 10:05:04 PM
in the bin?

*Facepalm*

How old are you?Tutorial: In Windows 7 environment (not sure about other OS's):

1. Right-click on batch file; Select Properties
2. Click Advanced button in General Tab
3. Check mark "Encrypt contents to secure data"

It's manual because it involves the user doing something.
It's encryption because it is ACTUALLY encrypting the file.

Wow. That seems a LOT easier than the originally proposed method. Maybe I should get into this official tutorial business.  Quote from: Raven19528 on November 08, 2011, 11:58:05 AM
Tutorial: In Windows 7 environment (not sure about other OS's):

1. Right-click on batch file; Select Properties
2. Click Advanced button in General Tab
3. Check mark "Encrypt contents to secure data"

It's manual because it involves the user doing something.
It's encryption because it is ACTUALLY encrypting the file.

Wow. That seems a lot easier than the originally proposed method. Maybe I should get into this official tutorial business. 
Yes! Go for it! Your first Official Tutoriall!
624.

Solve : how to bypass the no valid cd rom device selected?

Answer»

Hi everyone. I am new to this board and hope someone can help me. My husband just brought home and old Dell 486/33 that has been upgraded to a 486/66. The cd rome has been taken out and I just keep getting the message Device driver not found, No valid cd rom device selected. (1) How do I bypass this? and is a cd rom actually needed to run ms dos on this computer ? (2) and can I install windows 98 on this computer?  I have a windows setup hard disc and a windows startup hard disc. (3) Do I need to install a cd rom and get a cd with windows on it to do this? Hope you all can help I am learning little by little about computers.

THANKS,
RONDA
Quote

...Dell 486/33 that has been upgraded to a 486/66. The cd rome has been taken out and I just keep getting the message Device driver not found, No valid cd rom device selected. (1) How do I bypass this? and is a cd rom actually needed to run ms dos on this computer ? (2) and can I install windows 98 on this computer?  I have a windows setup hard disc and a windows startup hard disc. (3) Do I need to install a cd rom and get a cd with windows on it to do this? ...


Dell 486/66 PROBABLY has DOS 6.22 and Win3.1.
(1) Ignore it.  CDROM not required for DOS.
(2) Win98 requires the following:
http://support.microsoft.com/default.aspx?scid=kb;en-us;182751
486/66 w/16MB is minimum.  It might work but, it's gonna be slow.
You said you "...have a windows setup hard disc and a windows startup hard disc. .."  You mean CD, not disc?

(3)  Install of Win98 requires CDROM, unless you have Win98 on floppy disks.
Thanks for answering _commando.
I meant to say I have windows 98 setup and windows 98 startup on a floppy disc. Do I have what I need or do I need windows 98 on cd? I tried these floppy disc and kept getting an a:> prompt and I don't know what to put in the prompt.

Thanks
Ronda Quote
...I meant to say I have windows 98 setup and windows 98 startup on a floppy disc. ...


Not ENOUGH.  You need the installation CD.  Win98 CD is bootable.  Floppy disk is for computers that don't support booting from CD's.  Yours probably won't boot from CD.  Dell 486/66 was manufactured around 1992.  You can look it up on Dell's website.  Look for service tag number on the back of the computer.
Okay, now that I know what I need to get windows installed. Can you tell me what to do now when I boot up this computer and it has a C:/ prompt. You said I can ignore the cd rjom part. But it won't go pass the C:/ prompt.

Thanks again Computer_Commando
RondaType "win" (without the quotes).  If Windows is there it's probably Win3.1.

More info on Win3.1:  http://www.wown.com/j_helmig/win31.htm
That was it! It worked! Thanks. I see something called Microsoft Mail and I don't have a password for this. Could this computer be stripped of everything but this?

Thanks Ronda Quote
...
(1)I see something called Microsoft Mail and I don't have a password for this.

(2)Could this computer be stripped of everything but this?


(1) Probably an old version.  Ignore it...for now.
(2)  You could...but I wouldn't recommend it.  I have a 486/66 notebook...tried to put Win98, then Win95...no luck.  Almost booted, but couldn't completely plug and play all the old hardware.  It has no CDROM and no FDD.  WENT back to MSDOS6.22/Win3.1.  I still use DOS for image backups on my WinXP/Win2k/Win98 computer.  Keep what you got and learn DOS.  Many DOS commands still work at the Command Prompt.  Once you use DOS and Win3.1, you may find WinXP easier to use and understand.  Much of the "source code" has not changed.
okay computer_commando, Thanks a lot you were a lot of help. Nice to have people like you online that can help people. I guess it's up to my husband  and whatever he wants to do next. Thanks Again. Bye.
Ronda Hunt
625.

Solve : FTP - Capture Success messages?

Answer»

Hi all.

I'm trying to build an dos batch file that opens an dos FTP session and MAKE file exchanges.

how can i register a log or CAPTURE sucess/failure messages from ftp session?first see if your ftp client produces a result or errorlevel upon its completion..  if so then test for it using a "if errorlevel ==  " to steer your batch.

you might also be able to pipe the result code  to a file upon the sessions completion.   Look for info on loading result codes and piping output to VARIABLES and other devices.  

Piping is done via "|"  dec 124, shift of the "\" KEY on some keyboards.

626.

Solve : input paramatertar?

Answer»

Hi, can anyone hellp me please.....?
I am RUNNING a batch file which inputs a control file(ctl). WITHIN the control file i have to hard code the filename (csv). CNA anyone please let me know how I can GET the contolr file to ask for the filename. ie when I run the batch file it calls the control file and from there I need a prompt to ask for the filename to input.....hope all that makes sense.
Thank you.why not pass the control file name to batch from the START by passing it as a parameter on the command line.

batch.bat control.fil

use the "%1" to pass the parameter to your exe file.

627.

Solve : Batch file to pre-pend text to multiple filenames?

Answer»

Hi folks, from the Windows7 command line, the following command prepends "text_" to all csv files in the current directory
Code: [Select]FOR %A IN (*.csv) DO REN "%A" "test_%~nA%~XA"
e.g. 1234.csv to test_1234.csv

Question: how do you run this command from a batch file instead of directly from the command PROMPT?
Many THANKS, Pete.
Each %A must be %%A in the batch file.Also, when using variable modifiers, you can combine them so that...

%~nA%~xA

can be replaced by:

%~nxA

628.

Solve : File and directory names?

Answer»

Running XP Home.
In the command line I am having trouble CHANGING directories. I know that there is a limit to the number of characters ( I thought it was 8) in a file name but I can't REMEMBER how to handle it.  I am trying to do "cd program files" comes BACK with "too many PARAMETERS" then I try "cd program~" and "cd program*" and get back "invalid file name"
Help please?
Thanks,
Barkleyhttp://techrepublic.com.com/5100-6270-5035182.htmlThe file name completion thingy is already on, ie set to 9. Thanks for the reply HOWEVER.

629.

Solve : batch file in two parts?

Answer»

I have been asked t help write a BATCH FILE.
It comes in TWO parts.
Part two should only execute if part one finishes befoe 10pm.
How can I check the time from WITHIN the batch file and tell it to skip part two if part one finishes after 10pm?

Thank you,

Jamestry using the %time% to compare the time to..  I haven't used it in years but you MAY have to turn it on with the cmd /v  option.

630.

Solve : Mind is blown, should be easiest batch file ever, but stumped.?

Answer»

Hello Everyone, thanks for your help in advanced.

This is blowing my mind, i cant find ANYTHING on google or any forums i have VISITED

All i NEED is a little batch file that will go through all the directories on a drive and list LIST all the files that over a year old.  Doesnt have to delete the files or move them at all, all i need is a list.

Why is this so difficult?  If you have a better way than a batch file please feel free to include it in a post.

THANKS!If you don't need this to be self contained in a batch, here is how I would do it:

Use the windows search feature to find the files over a year old. Once it is done, copy those files to a separate directory. Then open command prompt and go to that directory and type dir /b > files.txt. There you go. Now you have a list of all those files. You can the just delete that directory that you copied to when done. Quote from: Linux711 on November 04, 2011, 10:54:55 AM

If you don't need this to be self contained in a batch, here is how I would do it:

Use the windows search feature to find the files over a year old. Once it is done, copy those files to a separate directory. Then open command prompt and go to that directory and type dir /b > files.txt. There you go. Now you have a list of all those files. You can the just delete that directory that you copied to when done.

GREAT IDEA, the only problem is, this drive is almost full and its 6 tb.  I just started at this job as the FIRST IT person and no one has gone through these files in almost 8 years. So that would be a ton of copying.    Quote
i cant find ANYTHING on google

How hard did you look?

I Googled "list files older than date". This told me about the forfiles command. I next Googled for "forfiles" which got me the MICROSOFT documentation page. Included in the examples is this one liner.

Total TIME 2 minutes approx.

Code: [Select]forfiles /s /m *.* /d -365 /c "cmd /c echo path is at LEAST one year old."
631.

Solve : variable increment?

Answer»

Hello!
Please help!
I am trying to increment a VARIABLE by 1.
This is what I do:
>>set VAR=2
>>echo %VAR%
2
>>set /A VAR=%VAR%+1
>>echo %VAR%
2
Why isn't the value of VAR 3?  How do I increment it?
I am using DOS with Windows ME.
I am trying to create a loop in a batch file
with IF ...  GOTO LABEL  that will execute a series of
commands 100 times, so I NEED to increment VAR until
VAR=100.  
Can someone help me?  
Thank you sooooooooooo MUCH,
Dorothyhttp://www.cknow.com/tutorcom/batch03_subcmd1.htmyou might want to take a closer look at expanded SET commands and using the !var!.  You'll also need to turn some of them on with the cmd /v command.

632.

Solve : String Replace with Wildcard?

Answer»

This question is regarding modifying text files
I need to replace a constant string followed by a variable string with a dynamic string like so:

Code: [Select]Constant::Hello   -&GT; Constant::English
Constant::Bonjour -> Constant::French
To the best of my knowledge, using a wildcard is the way to locate the string within the file:

Code: [Select]Constant::*
but this doesn't seem to work with the replace macro (for the lack of the right name) I'm using in my bat:

Code: [Select]SET str=!Constant::*=Constant::%language%!
I've also tried setting the new and old strings as variables:

Code: [Select]set old = Constant::*
set new = Constant::%language%

// loops

set str=!%old%=%new%!
I urgently need to find a way to do this, preferably using the macro (or whatever) I'm already using

I don't really use DOS, i'm used to coding in C++ and it's takes me a while to get used to the way variables are used.
I find it rather hard to read, so please comment your suggestions for ease of reading.
I'd like to avoid using non-standard FUNCTIONS if possible

Thanks
Could you explain a bit more clearly what you are trying to do, and what you mean by the word "macro"?

You can replace a literal string with another like this

set variable=%variable:search=replace%

to replace father with mother:

set string1=hello::father

set string1=%string1:father=mother%

To use a variable, DOUBLE the percent signs around the replace variable

set string1=hello::mother
set string2=father
echo %string1:mother=%%string2%%

(result: hello::father)







'macro' is just the best name I could think of for the '%string1:father=mother%' bit.

I know that line replaces a literal string, but I need to find a literal string followed by a variable (wildcard) string.

A wildcard needs to be found (like 'Content::*' where * is a wildcard)
This script loops through lots of files which contain something like:

Content::Hello
Content::Bonjour
Content::Goodbye
Content::Ciao
Content::AuRevoir

Which need to be replaced with:

Content::English
Content::French
Content::English
Content::Italian
Content::French

The fact it's languages and how the language is determined doesn't matter, it's just an example.

I managed to get it replacing with a variable, but to clarify what you've said, is it:

echo %string1:mother=%%string2%%

or

echo %string1:mother=%%string2%%%

because in the end I used a %%a (character?) variable rather than a %string% variable. I may be misunderstanding the significance of some of the %.
Also i'm using Delayed Expansion, so my line looks like this:

set str=!str:Content::=Content::%%a_!

(the '_' is because it's inserting before rather than replacing the original string, so 'Content::Hello' becomes 'Content::English_Hello')

Ultimately I want to be left with 'Content::English' rather than 'Content::English_Hello' but having a better understanding of what the % are for would be useful too.

I hope that clarifies everything, as I need to solve this asap.
 You can check this out and possibly solve your issues.

Also, it may be easier to set the for token to a named variable earlier in the loop to avoid issues and confusion. I.e.

set VAR1=%%a

then

call set str=!str:Content::=Content::%%var1%%!

633.

Solve : delete first character of all lines in a text file.?

Answer»

Here is a sample of the text file:

~ === SALES Order Confirmation Message ===
~     Customer: 0023410
~     **** Delivery Date Exception. Promised Date greater than Required Date. ****
~     Required Date: Thu 10-Nov-11                Promised Date: Fri 11-Nov-11
~     NEW Sales Order: 1343943 | OW Order: 1436

I would like to delete the first character of every line.
I've tried doing find and replace, but can't seem to get it to work.
Any help would be appreciated. Code: [SELECT]echo off

setlocal enabledelayedexpansion

for /F "tokens=*" %%A in (myfile.txt) do (
set line=%%A
echo !line:~1! >> newfile.txt
)

Replace myfile.txt and newfile.txt with your own.Add in this at the end (outside the parenthesis) to make it transparent:

Code: [Select]del myfile.txt
ren newfile.txt myfile.txt

634.

Solve : delete all zero byte files in a folder . . .?

Answer»

I know everyone is saying this, but I REALLY am new at attempting batch files, so please forgive any stupid QUESTIONS.   
I tried running this exact code, which had already been posted as a solution to someone else's post, but am getting an error.
Maybe something in the code is implied and I'm supposed to know enough to replace what's there with my own variable?
***************************
  set zerofile=zerobyte
  copy nul %zerofile% >nul
  for /f "delims=" %%a in (%d_qdbconf%) do (
    fc %zerofile% "%%a" >nul && del "%%a"
  )
  del %zerofile%
***************************
%d_qdbconf% is the path where the files reside that I want to delete if they are 0 byte.

I've attached a screen print of the cmd.exe window.



[REGAINING space - attachment deleted by admin]Got it!!   
This works perfectly . . .

Set d_qdbconf=\\sourdough\crossdata\ftp\qd\test\out\conf_temp
dir %d_qdbconf%\*.*  |  find " 0 "  >  %d_qdbconf%\zerotxt.txt
for /f "tokens=5 delims= " %%i in (%d_qdbconf%\zerotxt.txt) do del /F  %d_qdbconf%\"%%i"

Thanks anyway! Code: [Select]for /f "delims=" %%A in ( ' dir /b /a-d %d_qdbconf%\*.* ' ) do if %%~zA equ 0 del "%%~dpnxA"Thanks Salmon TROUT,
I'm assuming you are saying that I should be able to replace my TWO lines of code with your one line of code?
Remember, I'm new at this. 
If so, I tried to do this and it doesn't work.
It finds the zero byte file in the d_qdbconf directory, but then tries to delete the file from the directory where my bat file is running, not the d_qdbconf directory.

635.

Solve : how can i count number of lines of text files in one folder into one test file u?

Answer»

Dear All,

I just want to know, how can i count number of lines of text files in one folder into one test file using bat file.
I want to run bat fie. output like 
file name1.txt : 257 lines.
file name2.txt : 290 lines.

like thatDear All,

I just want to know, how can i count number of lines of text files using bat file.
I want to run that bat fie. in one particular folder output in a new text file like
file.txt
file name1.txt : 257 lines.
file name2.txt : 290 lines.

like that..
Please rpl asap.... Code: [Select]echo off
setlocal enabledelayedexpansion

:loop
  set /p folder="Enter Folder Name: "
  if not exist %folder% goto loop

pushd %folder% 

if exist %TEMP%\count.txt del %temp%\count.txt

for /F "tokens=* delims=" %%i in ('dir /b "%folder%"') do (
  for /f "delims=:" %%W in ('findstr /n /r ".*" "%%~dpnxi"') do set tot=%%w
    echo  "%%~nxi" : !tot! lines >> %temp%\count.txt


popd

You will be prompted for the folder name. The output file goes to %temp%\count.txt.

 There is an utility that does that. You can either make one or use one somebody else made. And you can easily do in in a batch.
You just want to count lines, - Right?

636.

Solve : Remake a config file?

Answer»

Sorry for the weak subject. I didn't come up with a better one since English isn't my spoken language
I have a config file that i have to remake some. The file name is PROF_SAVE_profile with no file extension and looks like this

Code: [Select]GstAudio.AudioQuality 1GstAudio.CarRadio 0GstAudio.DialogueVolume 0.700000GstAudio.MusicVolume 0.700000GstAudio.SoundSystemSize 20GstAudio.StereoMode 1GstAudio.VOLanguage 0GstAudio.Volume 1.000000GstAudio.YourSoundSystem 2GstRender.AmbientOcclusion 0GstRender.AnisotropicFilter 2GstRender.AntiAliasingDeferred 0GstRender.AntiAliasingPost 0GstRender.Brightness 0.779070GstRender.Contrast 0.500000GstRender.EffectsQuality 1GstRender.Enlighten 1GstRender.FieldOfView 80.000000GstRender.FullscreenEnabled 1
What i want is to have a new line after every sentence that starts with Gst so it looks like this instead.

Code: [Select]GstAudio.AudioQuality 1
GstAudio.CarRadio 0
GstAudio.DialogueVolume 0.700000
GstAudio.MusicVolume 0.700000
GstAudio.SoundSystemSize 20
GstAudio.StereoMode 1
GstAudio.VOLanguage 0
GstAudio.Volume 1.000000
GstAudio.YourSoundSystem 2
GstRender.AmbientOcclusion 0
GstRender.AnisotropicFilter 2
GstRender.AntiAliasingDeferred 0
GstRender.AntiAliasingPost 0
GstRender.Brightness 0.779070
GstRender.Contrast 0.500000
GstRender.EffectsQuality 1
GstRender.Enlighten 1
GstRender.FieldOfView 80.000000
GstRender.FullscreenEnabled 1

Yes i could do everything manually but the file is huge and it would take some time to do that Quote from: Apexi on November 25, 2011, 03:02:56 AM

Code: [Select]GstAudio.AudioQuality 1GstAudio.CarRadio 0GstAudio.DialogueVolume 0.700000GstAudio.MusicVolume 0.700000GstAudio.SoundSystemSize 20GstAudio.StereoMode 1GstAudio.VOLanguage 0GstAudio.Volume 1.000000GstAudio.YourSoundSystem 2GstRender.AmbientOcclusion 0GstRender.AnisotropicFilter 2GstRender.AntiAliasingDeferred 0GstRender.AntiAliasingPost 0GstRender.Brightness 0.779070GstRender.Contrast 0.500000GstRender.EffectsQuality 1GstRender.Enlighten 1GstRender.FieldOfView 80.000000GstRender.FullscreenEnabled 1

Is this all on one single line?
If this is a 1-off job, then use an editor
replace
Gst
with
{cr}Gst

where {cr} is a lineend Quote from: Salmon TROUT on November 25, 2011, 03:07:38 AM
Is this all on one single line?

Hmm it's like 60 lines totaly. Quote from: Apexi on November 25, 2011, 03:19:36 AM
Yes, exactly as i posted in the first code tag.

hard to tell because it is wrapped
Quote from: Salmon Trout on November 25, 2011, 03:20:59 AM
hard to tell because it is wrapped

Sorry my missunderstanding. I edited my post.please post whole of the file you wish to convert. Is it 1 line or 60 lines?
Lol that was easy. Just opended up the file with MS Office and it manage to break the lines right.

But still to learn something new i want to know how to make the batch file. But i cant paste the whole config since would fill up the entire site, as i said, it's huge.
To explain the problem in details. I want a linebreak before every "Gst"Hard to do in batch, easy to do in VBscript.

Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile = wscript.arguments(0)
sdelm = wscript.arguments(1)
Set oFile = oFSO.OpenTextFile(sFile, 1)
sMyString = oFile.ReadLine
oFile.Close
aSplitstring=Split(sMyString, sDelm, -1, 1)
For j = 1 To UBound(aSplitstring)
   wscript.echo sDelm & aSplitstring(j)
Next

Save script as (for example) convert.vbs

This is PROF_SAVE_profile

GstAudio.AudioQuality 1GstAudio.CarRadio 0GstAudio.DialogueVolume 0.700000GstAudio.MusicVolume 0.700000GstAudio.SoundSystemSize 20GstAudio.StereoMode 1GstAudio.VOLanguage 0GstAudio.Volume 1.000000GstAudio.YourSoundSystem 2GstRender.AmbientOcclusion 0GstRender.AnisotropicFilter 2GstRender.AntiAliasingDeferred 0GstRender.AntiAliasingPost 0GstRender.Brightness 0.779070GstRender.Contrast 0.500000GstRender.EffectsQuality 1GstRender.Enlighten 1GstRender.FieldOfView 80.000000GstRender.FullscreenEnabled 1

at the command line, or in a batch:

cscript //nologo convert.vbs "PROF_SAVE_profile" "Gst" > "PROF_SAVE_profile.new"

This is PROF_SAVE_profile.new

GstAudio.AudioQuality 1
GstAudio.CarRadio 0
GstAudio.DialogueVolume 0.700000
GstAudio.MusicVolume 0.700000
GstAudio.SoundSystemSize 20
GstAudio.StereoMode 1
GstAudio.VOLanguage 0
GstAudio.Volume 1.000000
GstAudio.YourSoundSystem 2
GstRender.AmbientOcclusion 0
GstRender.AnisotropicFilter 2
GstRender.AntiAliasingDeferred 0
GstRender.AntiAliasingPost 0
GstRender.Brightness 0.779070
GstRender.Contrast 0.500000
GstRender.EffectsQuality 1
GstRender.Enlighten 1
GstRender.FieldOfView 80.000000
GstRender.FullscreenEnabled 1

How long before the "After I've made edits, how do I join them all back together?" question... ?
Quote from: Salmon Trout on November 25, 2011, 04:37:40 AM
How long before the "After I've made edits, how do I join them all back together?" question... ?

Sorry dont understand what you are meaning, but thanks for the explanation on the script.
I've never try VBscript before so it's just funny to learn something new.

Cheers Quote from: Apexi on November 25, 2011, 08:23:13 AM
Sorry dont understand what you are meaning

The game REQUIRES this

Code: [Select]GstAudio.AudioQuality 1GstAudio.CarRadio 0GstAudio.DialogueVolume 0.700000GstAudio.MusicVolume 0.700000GstAudio.SoundSystemSize 20...
You wanted to GET this

Code: [Select]GstAudio.AudioQuality 1GstAudio.CarRadio 0
GstAudio.DialogueVolume 0.700000
GstAudio.MusicVolume 0.700000
GstAudio.SoundSystemSize 20
...

Why? What is it for? The game cannot read the new format, can it? I thought you might want to edit the VALUES.
Quote from: Salmon Trout
Why? What is it for? The game cannot read the new format, can it? I thought you might want to edit the values.

Ah now i undestand. It belongs to Battlefield 3, and as usally i always check the config file on all games a play since some developer doesn't show all options under settings ingame.
This way make it just easier to read and change. Later on when you start up the game it automatically change back to the old layout, but the settings you change remains.I don't know what editor or viewing method you you are using where you see all the entries mashed up against each other; they should be one to a line I think (see link below, scroll down for raw data) have you tried Wordpad?

http://pastebin.com/jKGBnbPq





637.

Solve : Program Trouble?

Answer»

So I have the following program that I am trying to run. I've managed to take a screenshot of the program before it dies (it dies quickly) and it says "( was unexpected at this time". I have combed over the entire code, and even the input files, but I can't find any "("s that are out of PLACE or not needed. I am using this program to combine two fairly extensive lists of people into one. I just can't see what is causing that error.

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=1-3 DELIMS=," %%A in (c:\users\Raven\desktop\List.csv) do (
  set copycheck=0
  call :isolateloop %%A
  set lname=!output!
  call :isolateloop %%B
  set fname=!output!
  set Idate=%%C
  for /f "tokens=1-4 delims=," %%J in (c:\users\Raven\desktop\code\batch\test\ListUsers.csv) do (
    call :isolateloop %%J
    set lcheck=!output!
    call :isolateloop %%K
    set fcheck=!output!
    if !lname!==!lcheck! (
      if !fname!==!fcheck! (
        echo !lname!,!fname!,%%L,%%M,!Idate!>>%userprofile%\desktop\UpdateUsers.csv
        set copycheck=1
      )
    )
  )
  if !copycheck! neq 1 echo !lname!,!fname!,"","",%%C>>%userprofile%\desktop\UpdateUsers.csv
)

goto eof

:isolateloop
set iso=%1
:floop
set fletter=%iso:~0,1%
if a%fletter%a==a"a (
  set iso=%iso:~1%
  goto floop
)
if "%fletter%"==" " (
  set iso=%iso:~1%
  goto floop
)
:lloop
set lletter=%iso:~-1%
if a%lletter%a==a"a (
  set iso=%iso:~0,-1%
  goto lloop
)
if "%lletter%"==" " (
  set iso=%iso:~0,-1%
  goto lloop
)
set output=%iso%Have you run the script with Echo on to show which command line is failing?Some editors have a nifty little feature that allows the user to click on an opening block character (paren. curly brace, square bracket) and the closing counterpart will be highlighted.

It appears the outermost for loop is not balanced.

Also the goto in line 26 is missing a colon.

Using echo on is a tried and true method of DEBUGGING. I also recommend testing as you write. Waiting until the code is complete to search for errors can be most frustrating amd time consumming.

Happy Hunting. 

Ran with echo on and was able to isolate it to the isolateloop subroutine. Specifically the following:

Code: [Select]if a%fletter%a==a"a (
  set iso=%iso:~1%
  goto floop
)
Why would an open parenthesis in a subroutine cause this PROBLEM? Also, what format could I use to write it all in one line? Would this do the same thing?

Code: [Select]if a%fletter%a==a"a set iso=%iso:~1% && goto floop
If I can more easily take the parenthesis out of the subroutine rather than figure out why it doesn't like it, then I think I should probably go that route.Update: It was the quotation marks that were causing the issue. What the line was expecting was the == that is there, but is TECHNICALLY within quotes. Batch is looking for a"a==a"a to == something else. Ridiculous what quotes will do.

Solution: Escape(^) the variables and escape the hardcoded quotes.

Code: [Select]:isolateloop
set iso=%1
:floop
set fletter=%iso:~0,1%
if a^%fletter%a==a^"a (
  set iso=%iso:~1%
  goto floop
)
if "^%fletter%"==" " (
  set iso=%iso:~1%
  goto floop
)
:lloop
set lletter=%iso:~-1%
if a^%lletter%a==a^"a (
  set iso=%iso:~0,-1%
  goto lloop
)
if "^%lletter%"==" " (
  set iso=%iso:~0,-1%
  goto lloop
)
set output=%iso% Quote from: Raven19528 on November 17, 2011, 09:14:05 AM

Also, what format could I use to write it all in one line? Would this do the same thing?
Code: [Select]if a%fletter%a==a"a set iso=%iso:~1% && goto floop

Nearly - you only need one ampersand ("&"). In Unix and Windows, the ampersand syntax is as follows:

command1 & command2 - execute command1 and then execute command2

command1 && command2 - execute command1 and only if command1 exits with no error, execute command2

note also

command1 || command2 - execute command1 and only if command1 exits with an error, execute command2

638.

Solve : DOS to Monitor?

Answer»

Hi
I'm very new to the world of dos and I'm hoping to stay away from it as i'm more the easy interface kind of GUI (get it ?) anyway , I was wondering if on a separate monitor or just window it would be possible to show the cmd / dos OUTPUT of any .exe (or most) .
E.G- I presume when I sync my IPHONE in iTunes it runs thousands of horribly long lines of dos and these are presented in a nice GUI .
Would this be possible ?
ThanksClosest thing i can think of that matches what you want is PROCESS Explorer which shows whats going on: http://en.wikipedia.org/wiki/Process_Explorer


Quote

it can show the command lines used to start a program, allowing otherwise IDENTICAL processes to be distinguished.
Thanks Quote from: keirjohnharry on November 11, 2011, 01:28:44 PM
E.G- I presume when I sync my iPhone in iTunes it runs thousands of horribly long lines of dos and these are presented in a nice GUI .

your presumption is wrong.
639.

Solve : Changing file extension case?

Answer»

From a batch script, how do I change all specific file extension combinations to all lower case

testfile.CSV
afile.Csv
somefile.csV

Thanks...if its just one file extension, then
ren *.csv *.csv worksThat works except is the file is named file5.CSV2, it is changing it to file5.csv.  I only WANT it to touch files with extension ".csv", I am not sure why rename is touch that file.

Code: [Select]11/15/2011  12:36 PM    <DIR>          .
11/15/2011  12:36 PM    <DIR>          ..
08/01/2011  01:59 PM            41,534 a.tmp
07/30/2011  05:44 AM    <DIR>          Desktop
11/14/2011  01:31 PM    <DIR>          Favorites
11/15/2011  12:36 PM                 0 file1.Csv
11/15/2011  12:36 PM                 0 file2.CSV
11/15/2011  12:36 PM                 0 file5.CSV2
03/18/2011  02:29 PM                10 MT.txt
03/16/2011  03:21 PM                 7 mt_file
04/11/2011  09:21 AM    <DIR>          My Documents
11/15/2011  12:36 PM                 0 somefile.csv
03/13/2009  01:46 PM    <DIR>          Start Menu
03/24/2011  01:18 PM                11 testfile.txt
09/23/2009  09:47 AM    <DIR>          Testing
03/05/2010  08:37 AM               198 xyz.bat
               9 File(s)         41,760 bytes
               7 Dir(s)   8,771,514,368 bytes free


>rename *.csv *.csv

>dir


11/15/2011  12:37 PM    <DIR>          .
11/15/2011  12:37 PM    <DIR>          ..
08/01/2011  01:59 PM            41,534 a.tmp
07/30/2011  05:44 AM    <DIR>          Desktop
11/14/2011  01:31 PM    <DIR>          Favorites
11/15/2011  12:36 PM                 0 file1.csv
11/15/2011  12:36 PM                 0 file2.csv
11/15/2011  12:36 PM                 0 file5.csv
03/18/2011  02:29 PM                10 MT.txt
03/16/2011  03:21 PM                 7 mt_file
04/11/2011  09:21 AM    <DIR>          My Documents
11/15/2011  12:36 PM                 0 somefile.csv
03/13/2009  01:46 PM    <DIR>          Start Menu
03/24/2011  01:18 PM                11 testfile.txt
09/23/2009  09:47 AM    <DIR>          Testing
03/05/2010  08:37 AM               198 xyz.bat
               9 File(s)         41,760 bytes
               7 Dir(s)   8,771,514,368 bytes free
Well, it will change the c, s, and v in all extensions, but you could use this:

Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in ('dir /b [/s] /a-d') do (       
  set ext=%%~xA
  set ext=!ext:C=c!
  set ext=!ext:S=s!
  set ext=!ext:V=v!

  set newname=%%~nA!ext!

  echo ren %%~dpnxA !newname!
)

Use the /s if you are wanting to hit all subdirectories as well.

When you are satisfied with the result, remove the "echo" from the last line. Code: [Select]for %%A in (*.csv) do ren "%%A" "%%~nA.csv"
Before:

Code: [Select]C:\Users\Test>dir *.csv
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of C:\Users\Test

15/11/2011  18:30                16 animals.CsV
12/11/2011  10:05                44 Myquotes.cSv
11/11/2011  06:59                23 quotes.cSV
12/11/2011  10:01               525 test.CSV

After:

Code: [Select]C:\Users\Test>dir *.csv
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of C:\Users\Test

15/11/2011  18:30                16 animals.csv
12/11/2011  10:05                44 Myquotes.csv
11/11/2011  06:59                23 quotes.csv
12/11/2011  10:01               525 test.csv

The OP is trying to avoid changing the .CSV2 extension. I suppose a little modification can take care of that:

Code: [Select]for %%A in (*.csv) do if /i "%%~xA"==".csv" ren "%%A" "%%~nA.csv"
Quote from: Raven19528 on November 15, 2011, 11:59:47 AM

The OP is trying to avoid changing the .CSV2 extension. I suppose a little modification can take care of that:

No modification needed. The OP's requirement is catered for. The *.csv filespec will only find files with the extension (any case, upper lower or a mixture) ".csv" that is, a dot and the three characters (only) c , s and v - to include .csv2 it would have to be *.csv* or *.csv?

Before:

Code: [Select]C:\Users\Test>dir *.csv*
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of C:\Users\Test
15/11/2011  18:30                16 animals.CsV
12/11/2011  10:05                44 Myquotes.cSv
11/11/2011  06:59                23 quotes.cSV
12/11/2011  10:01               525 test.CSV
15/11/2011  19:01                12 test.CSV2
15/11/2011  19:01                12 testxxx.CSV2
               6 File(s)            632 bytes
               0 Dir(s)  26,632,110,080 bytes free

After:

Code: [Select]C:\Users\Test>dir *.cs*
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of C:\Users\Test

15/11/2011  18:30                16 animals.csv
12/11/2011  10:05                44 Myquotes.csv
11/11/2011  06:59                23 quotes.csv
12/11/2011  10:01               525 test.csv
15/11/2011  19:01                12 test.CSV2
15/11/2011  19:01                12 testxxx.CSV2
               6 File(s)            632 bytes
               0 Dir(s)  26,632,110,080 bytes free




Hmmm... Maybe my cmd prompt is different than yours. When I run dir *.csv I get all of the .csv2 extensions as well.

Code: [Select]Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Raven\Desktop\Code\Batch\Test>dir *.csv
 Volume in drive C is OSDisk
 Volume Serial Number is 008C-D47E

 Directory of C:\Users\Raven\Desktop\Code\Batch\Test

11/15/2011  10:18 AM                 0 New.csv
11/15/2011  10:18 AM                 0 New2.csv2
11/15/2011  10:18 AM                 0 New3.csv2
11/15/2011  10:18 AM                 0 New4.csV
               4 File(s)              0 bytes
               0 Dir(s)  193,769,201,664 bytes free
odd...

Windows 7 SP1 (64 bit, 64 bit command prompt)

(Edit - the result is the same with 32 bit command prompt)

64 bit command prompt: %windir%\System32\cmd.exe
32 bit command prompt: %windir%\SysWoW64\cmd.exe

Code: [Select]Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\Users\test>dir *.csv
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of c:\Users\test

15/11/2011  18:30                16 animals.csv
12/11/2011  10:05                44 Myquotes.csv
11/11/2011  06:59                23 quotes.csv
12/11/2011  10:01               525 test.csv
               4 File(s)            608 bytes
               0 Dir(s)  26,631,081,984 bytes free

c:\Users\test>dir *.csv*
 Volume in drive C is Win07
 Volume Serial Number is E4DB-A92A

 Directory of c:\Users\test

15/11/2011  18:30                16 animals.csv
12/11/2011  10:05                44 Myquotes.csv
11/11/2011  06:59                23 quotes.csv
12/11/2011  10:01               525 test.csv
15/11/2011  19:01                12 test.CSV2
15/11/2011  19:01                12 testxxx.CSV2
               6 File(s)            632 bytes
               0 Dir(s)  26,631,081,984 bytes free
Is your Windows 7 32 or 64 bit?
Very weird. I run a 32-bit Win7 environment. That may need to be researched as to why that little anomoly is happening.

To et_phonehome_2:

The solution to your exact issue may vary depending on the OS you are running.

I suggest opening your cmd prompt and going to the directory these files are in and typing dir *.csv  If you see .csv2 extensions, use my code, if not, use Salmon Trout's.I thought it might be to do with the filesystem having short-filename creation enabled on your system and disabled on mine, but I checked and it is enabled on mine. This is going to BUG me until I find out what is going on...


[Update] I have done a bit of Googling, and it seems that there is a bug in Win32 wildcard expansion, when the wildcard has exactly 3 chars e.g. *.csv - it finds all the .csv and then all the csv2 csvNNNN etc.

I am going to do some checking in XP 32 bit.

[Edit]

There ya go...

Code: [Select]Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator\test>dir *.csv
 Volume in drive C has no label.
 Volume Serial Number is 24FE-A31E

 Directory of C:\Documents and Settings\Administrator\test

15/11/2011  09:16 PM                 8 test.CSV
15/11/2011  09:17 PM                 8 test.csv2
15/11/2011  09:17 PM                 8 test1.CSV
15/11/2011  09:17 PM                 8 test1.csv2
15/11/2011  09:20 PM                 8 test1.csvN1
15/11/2011  09:20 PM                 8 test1.csvN2
15/11/2011  09:20 PM                 8 test1.csvN3
15/11/2011  09:20 PM                 8 test1.csvN4
15/11/2011  09:17 PM                 8 test2.CSV
15/11/2011  09:18 PM                 8 test2.csv2
15/11/2011  09:17 PM                 8 test3.CSV
15/11/2011  09:18 PM                 8 test3.csv2
              12 File(s)             96 bytes
               0 Dir(s)  132,692,742,144 bytes free

C:\Documents and Settings\Administrator\test>dir *.csvN*
 Volume in drive C has no label.
 Volume Serial Number is 24FE-A31E

 Directory of C:\Documents and Settings\Administrator\test

15/11/2011  09:20 PM                 8 test1.csvN1
15/11/2011  09:20 PM                 8 test1.csvN2
15/11/2011  09:20 PM                 8 test1.csvN3
15/11/2011  09:20 PM                 8 test1.csvN4
               4 File(s)             32 bytes
               0 Dir(s)  132,692,742,144 bytes free
So I believe your check (that the extension is just ".csv" and no longer) is vital for compatibility with all Windows versions.


dir /x shows short filenames generated for non- 8-dot-3 compatible filenames. They have .csv extensions thus win32 finds them and matches the wildcard.
Code: [Select]C:\Documents and Settings\Administrator\test>dir /x
 Volume in drive C has no label.
 Volume Serial Number is 24FE-A31E

 Directory of C:\Documents and Settings\Administrator\test

15/11/2011  09:20 PM    <DIR>                       .
15/11/2011  09:20 PM    <DIR>                       ..
15/11/2011  09:16 PM                 8              test.CSV
15/11/2011  09:17 PM                 8 TEST~1.CSV   test.csv2
15/11/2011  09:17 PM                 8              test1.CSV
15/11/2011  09:17 PM                 8 TEST1~1.CSV  test1.csv2
15/11/2011  09:20 PM                 8 TEST1~2.CSV  test1.csvN1
15/11/2011  09:20 PM                 8 TEST1~3.CSV  test1.csvN2
15/11/2011  09:20 PM                 8 TEST1~4.CSV  test1.csvN3
15/11/2011  09:20 PM                 8 TE3013~1.CSV test1.csvN4
15/11/2011  09:17 PM                 8              test2.CSV
15/11/2011  09:18 PM                 8 TEST2~1.CSV  test2.csv2
15/11/2011  09:17 PM                 8              test3.CSV
15/11/2011  09:18 PM                 8 TEST3~1.CSV  test3.csv2So more than likely, my system is searching the 8-dot-3 filenames in which case any extension starting with .csv shows up. That's a weird bug. Wonder if they are planning to patch that, or if I'm just out of date with the updates and patches.
640.

Solve : regrouping . . . need help with finding specific string(s) . . .?

Answer»

within a text file, then using those strings to rename the file.
Initially, the code would need to loop through all files in a specific directory, where the file names start with I*.

Here is an example of the  text file contents:
 --------------------------------------------------------------------------------------------------
                                              SFC - 011
                                  Transmission Confirmation Message
 For: 90111 Qd                                       Processed: Wed 09-Nov-11 04:04 PM
 --------------------------------------------------------------------------------------------------
 === Sales Order Confirmation Message ===
     Customer: 0057687 QD-GLENWOOD
     **** Delivery Date Exception. Promised Date greater than Required Date. ****
     Required Date: Thu 10-Nov-11                Promised Date: Fri 11-Nov-11
     New Sales Order: 1343944 | OW Order: 417
                --------------------------------------------------------------------

This is an example of the renamed file format that I need:
confirm.057687.000417.110512.083950.cnf
I can get the date/time part, but I need to get the "057687" and "000417" data from inside the file. (Customer:  0057687 on the third line and OW Order: 417 on the sixth line, thought I could use "Customer:" and "OW Order:" strings to find the data to the right of them?)
I've been trying to do this in pieces, but I think I'm making it harder than it needs to be.  At least I'm hoping that's the case.   

Any help would be GREATLY appreciated.Customer:  0057687 on the third line and OW Order: 417 on the sixth line........but I think I'm making it harder than it needs to be

That could be - does Customer: 0057687 not appear on the seventh line and OW Order not appear on the tenth?

so sorry, my mistake on that.  it was only for reference purposes in my post.
Okay, please test this lazy method.  If the file format you provided is correct then the script might extract the Customer and Order numbers for inclusion in the renaming of the file.

Code: [Select]echo off
cls
setlocal enabledelayedexpansion

set zeros=00000
for /f "tokens=*" %%A in ('dir /b /a-d I*.*') do (

more +6 %%A > %temp%\iidiocy
set toks=2
CALL :loop
set Customer=!output!

more +9 %%A > %temp%\iidiocy
set toks=8
call :loop
set Order=!zeros!!output!
set order=!Order:~-6!

echo Customer=!customer!   Order=!order!
)
exit /b

:loop
set /p input=<%temp%\iidiocy
for /f "tokens=%toks%" %%1 in ("!input!") do (
    set output=%%1
)

I in no way present this as being better than T.C.'s solution, I just enjoyed puzzling it out so I thought I might as well post it

Code: [Select]echo off
setlocal enabledelayedexpansion

REM Set file search folder to the same folder as the batch location (testing purposes)
set folder=%~dp0

REM for each file in search folder starting with I
REM you might want to play around with the file mask
for /f "delims=" %%A in ( ' dir /b "%folder%\I*" ' ) do (

REM Search each line in each file for the data we need
for /f "delims=" %%B in ( ' type "%%~dpnxA" ' ) do (

REM use quotes in this way to neutralize some "poison characters" such as | < > etc
set "string=%%B"
REM also replace pipe character ("|") with dot to neutralize it
set "string=!string:|=.!"

REM isolate line with string "Customer:" & get it into variable
echo.!string! | findstr "Customer:">nul && set CustomerLine=!string!

REM isolate line with string "OW Order:" & get it into variable
echo.!string! | findstr "OW Order:">nul && set OWOrderLine=!string!
)

REM get 2nd space delimited token in line with "Customer:"
for /f "tokens=1-2 delims= " %%C in ("!CustomerLine!") do set CustomerNo=%%D

REM Truncate from left to 6 digits
set CustomerNo=!CustomerNo:~-6!

REM get 8th space delimited token in line with "OW Order:"
for /f "tokens=1-8 delims= " %%E in ("!OWOrderLine!") do set OWOrderNo=%%L

REM Add arbitrary number of leading zeros then
REM Truncate from left to 6 digits
set OwOrderNo=00000000!OwOrderNo!
set OwOrderNo=!OwOrderNo:~-6!

REM Generate new filename
REM You said you can get the part I represent as QQQQQQ.RRRRRR
set newfilename=confirm.!CustomerNo!.!OwOrderNo!.QQQQQQ.RRRRRR.cnf

REM Remove "echo" when you are happy it works
echo Ren "%%~dpnxA" "!newfilename!"

)I am sure the provided solutions work fine, but it seems like the problem you are trying to SOLVE is beginning to look like something that could be done more effectively in a real programming language. Quote from: Linux711 on November 12, 2011, 07:29:04 PM

I am sure the provided solutions work fine, but it seems like the problem you are trying to solve is beginning to look like something that could be done more effectively in a real programming language.

Your post is really off-topic for this thread, so I will keep my answer short. People using a computer at work often are not able to install anything extra at all. They have to work with what is actually on the computer that their employer has provided for them, and they have to work within the RESTRICTIONS that their employer's IT department lays down. So no downloads. No fancy programming languages. The supplied Microsoft scripting tools such as Powershell, Visual Basic Script and the NT family command environment (which is not "DOS" as many people think) are all that they can use. And they can do a lot, particularly in a fairly simple text processing scenario like this one, which is what they were designed for. So any considerations of elegance of code etc are misplaced in such a situation. If you look at the original post you will see many clues that the person is working is a commercial corporate environment. (i.e. he's got a "job".) In any case, the code supplied (partly by me admittedly) does the job, so the problem is, in essence, solved. (Pending the OP's return, if that ever happens).
 



Good Morning!
Just got to work and saw these awesome responses!  Thank you sooo much!
Salmon Trout is correct.  I am at work, and usually, the only time we have to use batch files is when we have to rename a translated file to a specific format for our customers that are going to be picking up the file, via ftp.  Unfortunately, our translation software does not allow us to specify the file name upon translation, so we have to manipulate the file name after translation.  Our translation software has a job scheduler that will call a batch file, so that's what calls the batch file after translation.  It's rather a pain, but it is what it is.

I am going to try both of these wonderful pieces of code and I'll post back after I test them here.  Hopefully, I won't have any more questions!

Again, thanks so much!Ok, I was overly optimistic that I might not have any questions . . .
I started with the more simple looking code and I STILL have questions.  Believe me, I KNOW these are embarrassingly simplistic questions, but I'm not familiar with Batch syntax and have just started using it.  BTW . . . if anyone knows of a link to something that would show and explain what all the different characters and commands mean, that would be awesome.  Anyway . . . for this code . . .
T.C.,
Could you possibly add some rem to explain each command and maybe what some of the characters do?
Like what does it mean when you have an "!" before and after a variable?
Was it implied that I was supposed to set a value to %temp%  ?
and was I also supposed to set a value to "iidiocy"  ?
Again, I apologize for the simplistic questions.

echo off
cls
setlocal enabledelayedexpansion

set zeros=00000
for /f "tokens=*" %%A in ('dir /b /a-d I*.*') do (

more +6 %%A > %temp%\iidiocy
set toks=2
call :loop
set Customer=!output!

more +9 %%A > %temp%\iidiocy
set toks=8
call :loop
set Order=!zeros!!output!
set order=!Order:~-6!

echo Customer=!customer!   Order=!order!
)
exit /b

:loop
set /p input=<%temp%\iidiocy
for /f "tokens=%toks%" %%1 in ("!input!") do (
    set output=%%1
)

I've done some commenting on the script but somewhere along the line the script has been compromised.   Please don't run this version

For a fairly comprehensive list of Commands and their syntaxes please go here.. But you don't show your OS so it might not be spot-on specific.

Salmon Trout posted a spiel on environment Variable expansion, perhaps he will post a link to it.

Hope this helps.

Code: [Select]echo off    & REM Turn the echo command to Off so that command lines are
                   not displayed during execution

cls          & REM Clear the display screen

setlocal enabledelayedexpansion
REM                Set the environment to Local i.e. any Set value applied
REM                is valid only within the script and lost when an Endlocal
REM                command is encountered or the script runs to completion or
REM                crashes.   Environment variables are expanded when the
REM                script commences, if the environment variable is to be
REM                expanded during some processing, especially within parenthesis,
REM                then delayed expansion must be invoked.  The environment
REM                variable must be
REM                enclosed in !..! when this is so.

set zeros=00000    & REM  Set the environment variable Zeros

REM  Standard For loop, for info on FOR at the Command Prompt enter For /?
REM  More COPIES the file(s) listed in the Dir listing to a temporary file
REM  iidiocy in the %temp% directory skipping the lines shown by +6 and +9.
REM  To see where your temporary directory is located at the Command Prompt
REM  enter SET T  You should not need to change this in the script, it
REM  should already be set.
REM  The temporary filename need not be changed but you can so do if you wish.

for /f "tokens=*" %%A in ('dir /b /a-d I*.*') do (
                   
more +6 %%A > %temp%\iidiocy
set toks=2
call :loop
set Customer=!output!

more +9 %%A > %temp%\iidiocy
set toks=8
call :loop
set Order=!zeros!!output!
set order=!Order:~-6!

echo Customer=!customer!   Order=!order!
)
exit /b

:loop
REM  set the first line in %temp%\iidiocy as Input.
set /p input=<%temp%\iidiocy

REM Another standard For loop which parses the first line in the file and
REM extracts the customer number on the first call and the OW order number
REM on the second call.
for /f "tokens=%toks%" %%1 in ("!input!") do (
    set output=%%1
)


 T.C.
Thank you so much, this helped tremendously.
It assigns 'output' perfectly, but I've been trying all morning to get it so that I can actually use the variables 'Customer' and 'Orders' to rename the file to:  confirm.!Customer!.!Order!.!Dattim!.cnf  rem do I use the ! around the variables here?

Here's the code that is working to get the specific data for the variables:
echo on rem the only way I know how to debug and watch what gets processed

cls

setlocal enabledelayedexpansion
Set d_qdbconf=\\sourdough\crossdata\ftp\qdoba\test\out\conf_temp  rem the name of the file in here is:  I799126_tlrt_20111114_164903.1
Set tloc_qdbconf=\\sourdough\crossdata\ftp\qdoba\test\out\temp


for /f "tokens=*" %%A in (' dir /b "%d_qdbconf%\I*" ') do (
more +7 %d_qdbconf%\%%A > %tloc_qdbconf%\iidiocy
set toks=2
call :loop
set Customer=!output!

more +9 %d_qdbconf%\%%A > %tloc_qdbconf%\iidiocy
set toks=8
call :loop
set order=!output!
set Order=!order:~-6!


for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set dat=%%k%%i%%j
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set tim=%%i%%j%%k
set Dat=!dat:~-6!


)
exit /b

:loop
set /p input=<%tloc_qdbconf%\iidiocy
for /f "tokens=%toks%" %%1 in ("!input!") do (
set output=%%1 
pause[loop]
)

:finish Quote from: jpilch on November 15, 2011, 01:21:17 PM
It assigns 'output' perfectly, but I've been trying all morning to get it so that I can actually use the variables 'Customer' and 'Orders' to rename the file to:  confirm.!Customer!.!Order!.!Dattim!.cnf  rem do I use the ! around the variables here?
...
for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set dat=%%k%%i%%j
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set tim=%%i%%j%%k
set Dat=!dat:~-6!


)
exit /b

Before the end parenthesis, try adding this:

Code: [Select]set newname=confirm.!Customer!.!Order!.!Dat!!tim!.cnf
echo ren %%A !newname!
Be sure the echo command shows you what you want to see, then remove the echo and watch it roll. (you may want to add a pause after the echo so you can verify what you are looking at and Ctrl+C to change the code back. Quote from: Original post by jpilch
I can get the date/time part, but I need to get the "057687" and "000417"

Raven has possibly answered your queries but hey, you wanted 000417 not 417.  Are you changing the spec for the script without advising?   Chaos could ensue if you are working from a different spec from us mere mortals. Quote from: T.C. on November 15, 2011, 01:58:18 PM
Raven has possibly answered your queries but hey, you wanted 000417 not 417.  Are you changing the spec for the script without advising?   Chaos could ensue if you are working from a different spec from us mere mortals.

He clearly showed he wanted 000417 in the very first post, and this has been addressed in the answers. Did you read them?


Sorry if I confused anyone, but I don't think I changed anything??

This is getting sooo close!

FYI . . . I had to add some code to 'trim' the 'Customer' and 'Order' variables.  I don't know the code well enough to know why they had trailing spaces, but they did.  So, I looked up how to 'right trim' them and now it looks good . . . I think. 

This is the code I'm running, and I can see the 'move' command and it looks correct now, but it's not doing the 'move'.  Am I missing something?
I tried the 'ren' command, too and it didn't work either.

echo on

cls

setlocal enabledelayedexpansion
Set d_qdbconf=\\sourdough\crossdata\ftp\qdoba\test\out\conf_temp
Set tloc_qdbconf=\\sourdough\crossdata\ftp\qdoba\test\out\temp


for /f "tokens=*" %%A in (' dir /b "%d_qdbconf%\I*" ') do (
more +7 %d_qdbconf%\%%A > %tloc_qdbconf%\iidiocy
set toks=2
call :loop
set customer=!output!
echo."!customer!"
for /l %%a in (1,1,15) do if "!customer:~-1!"==" " set customer=!customer:~0,-1!
echo."!customer!"

set Customer=!customer:~-6!
echo."!Customer!"
pause[trimcustomer]

more +9 %d_qdbconf%\%%A > %tloc_qdbconf%\iidiocy
set toks=8
call :loop
set order=!output!
echo."!order!"
for /l %%a in (1,1,15) do if "!order:~-1!"==" " set order=!order:~0,-1!
echo."!order!"

set Order=!order:~-6!
echo."!Order!"
pause[trimorder]


for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set dat=%%k%%i%%j
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set tim=%%i%%j%%k
set Dat=!dat:~-6!

set newname=confirm.!Customer!.!Order!.!Dat!.!tim!.cnf
echo move %d_qdbconf%\%%A %tloc_qdbconf%\!newname!

pause )
exit /b

:loop
set /p input=<%tloc_qdbconf%\iidiocy
for /f "tokens=%toks%" %%1 in ("!input!") do (
set output=%%1 
pause[loop]
)
641.

Solve : DOS Wildcard or ....?

Answer»

DOS supports the use of wildcards using a ? [question mark].  I have files of all different names, but I am looking for files that meet a specific criteria:

I have files of the names:
 
somename.csv
abc2ee.csv
file344.csv
debt32.csv
....
somename1108112.csv   &LT;< i want this >>
abc2ee1108112.csv         << i want this >>
file3440822451.csv        << i want this >>
debt321008213.csv        << i want this >>
....

The number PART of the above files can be any number, is there a way to replace something like Code: [Select]somename???????.csv, that is, insteading of typing so many question marks like use some multiplier?

While I am on the subject, how can I say give me EVERY file which is preceeded only by7 digits before the ".csv"?


THANKS....dir somename*.csv      --> lists any file starting with somename and with csv extension

Regarding last question, i don't remember well, but i think you cannot combine both wildcards ("?" and "*") in the same expression. So [i think] you can search for a file with exactly n digits, but not at least n digits. I mean, you can do

dir .csv   --> will list any 3-digit filename with csv extension

but you can't do

dir *.csv   --> Error. Cannot combine both wildcards.


In case anyone is interested, here is what I have DONE to resolve my issue:

REM  Perform a "dir" on the SOURCE_PATH, and then save a list of all files which
REM  have the extension ".csv" preceeded by 6 digits.
REM
dir /B %%SOURCE_PATH%% | findstr ".*[0-9][0-9][0-9][0-9][0-9][0-9]\.csv" > tmp.txt
........

642.

Solve : Bat file for chkdsk for other logical drives !!!?

Answer»

Hello FOLKS i want to make a batch file that would Check the Disk of my other partition irrespective if they are scheduled for the chkdsk and that provide a report.log of the event of the chkdsk.

At the moment i am using this commands :

" echo y> confirm.txt
  chkdsk /r   shutdown -r|      " 


This is something which i straight away took from a website,and kept for a schedule check, which it does after a reboot. I have no problem with that.
 But i want the to look at the report.log, can anyone make it for me.   

Any suggestion is greatly appreciated.Without testing, why wouldn't this work?
Code: [Select]chkdsk /r /y>report.log
shutdown /r Quote from: Raven19528 on November 06, 2011, 05:54:53 PM

Without testing, why wouldn't this work?
Code: [Select]chkdsk /r /y>report.log
shutdown /r

Almost promising but it didn't work my friend, it didn't even start the chkdsk process.Okay, try this ONE then:

Code: [Select]echo y>confirm.txt
(
chkdsk /r <confirm.txt
) > output.txt
shutdown /r
Quote from: Raven19528 on November 07, 2011, 09:27:55 AM
Okay, try this one then:

Code: [Select]echo y>confirm.txt
(
chkdsk /r <confirm.txt
) > output.txt
shutdown /r

Sorry mate that didn't work too, it restarted after 30 sec, but didn't do the chkdsk, too bad. It created log file CALLED confirm.txt and output.txt.
What does you're original code show you when the chkdsk STARTS running?

I'll need to do a little tinkering to see what's going on with everything, but that information will help. Quote from: Raven19528 on November 08, 2011, 11:47:21 AM
What does you're original code show you when the chkdsk starts running?

I'll need to do a little tinkering to see what's going on with everything, but that information will help.

Code: [Select]echo y> confirm.txt
  chkdsk /r <confirm.txt
  shutdown -r|     
This is the code , it actually starts the countdown to 30 sec, and then reboots and does the chkdsk, but it doesn't produce an output report or log, that is what i want.By running CHKDSK at boot, all the Windows services are not available.

GO to Control Panel and double click Administrative Tools
Double click Event Viewer
Double click Application log

Look down the Source column and double click the first Winlogon entry you find. The CHKDSK log should be there.

 



Quote from: Sidewinder on November 09, 2011, 07:02:47 AM
By running CHKDSK at boot, all the Windows services are not available.

Go to Control Panel and double click Administrative Tools
Double click Event Viewer
Double click Application log

Look down the Source column and double click the first Winlogon entry you find. The CHKDSK log should be there.

 

Nope that too doesn't work , as you mentioned the i.e.,
Code: [Select]Go to Control Panel and double click Administrative Tools
Double click Event Viewer
Double click Application logYou may have omitted a step:

Quote
Look down the Source column and double click the first Winlogon entry you find. The CHKDSK log should be there.

If not, what didn't work? Did you not find admin tools in the control panel? Did you not find the event viewer? Did you not find the Application log?

The procedure is best followed immediately after CHKDSK is run during the boot process. Otherwise you may have to look deeper into the log for a Winlogon entry.

643.

Solve : Continuously ping script?

Answer»

To mention it, i'm not looking for an DDOS script.
I have problem with my internet connection and my ISP want believe me since they only use the ping command prompt, and that only pings four times.
So i need a script that pings a host for like an hour and make an log in a .txt file, and with timestamps on every ping would be great. Quote

i'm not looking for an DDOS script
((Your not looking for a script???)) yet what I have below is the best method I can come up with, and it requires a batch script unless of course you want to hand key it to execute it manually, but the goto routine I dont think you could run unless you create a single lined concatenated batch file...lol

Best solution I can suggest is a goto loop in a batch file that writes the output to a text file. I would also add Date/Time Stamp to it in between each write of ping results so that when you have issues, you will have a somewhat good idea as to when it happened and for how long.

Code: [Select]echo OFF
:REPEAT
echo. %date% at %time% >>PingLog.txt
ping www.google.com >>PingLog.txt
goto REPEAT
I used a batch similar to this a while back for issues, but got further info from traceroutes where my ISP had a bad DNS path due to them buying up cheap and not so reliable taps to the Internet Backbone. The engineer at my ISP who took quite a few on hold phone hops to get to found it rather embarrasing that a home user was able to find this issue through a batch file and traceroutes, while most people would just accept poor performance or blame their home hardware.

If you are having strange issues with DNS being resolved, manually change your DNS to an IP from another DNS provider like OpenDNS and see if you get different results. Maybe you too will find out your ISP has JUNKY DNS paths to the Internet.

*Also this batch is very crude, in that you could make it better to strip it of everything but the ping results to be written to file if you want something clean with date/time and ping response times. Also you can change your ping path etc. I used Google since it is usually the best indicator of ISP issues since you should have pings less than 80ms, with 30-40ms being the best I have seen from my location. Also you may see the IP's change from where Google resolves as it is handled by the many Points of Presence that Google has for their search engine. Last time I checked I think the count was like 14 different IPs that www.google.com resolves at.

Also you can alter the ping www.google.com to ping www.google.com -n 60 >>PingLog.txt if you want say 60 pings per date/time stamped interval, using the -n followed by the ping-count of times to ping as shown.Thanks. It looks so simple when someone else write it  Dont know if i had brainfreeze yesterday.
I added -t after ping and now it works as i wanted. Quote from: DaveLembke on October 31, 2011, 06:40:56 PM
((Your not looking for a script???))

He wrote "I'm not looking for a DDOS script" (note the 2 D's) A DDOS attack is a distributed denial of service attack, where many thousands of computers (usually in a botnet) ping the same host and effectively shut it down becaue it can't respond to legitimate traffic.

It is worth noting that some hosts do not service ICMP requests (that is, they silently swallow ping requests and the remote (your) ping command times out)

Code: [Select]C:\>ping www.microsoft.com

Pinging lb1.www.ms.akadns.net [207.46.131.43] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 207.46.131.43:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
If you go persistent with -T, you can run it as a single LINE such as:

Code: [Select]ping www.google.com -t >PingLog.txt
or if you want to APPEND to end when restarted replace > with >> in that instruction. Guessing you will want to use > to overwrite the old data when run again since with -T you wont be getting date/time stamps to know when it cuts out. Also Salmon had a good point in regards that many shut off the ping responses and thanks for picking up on the DDOS while I took it as a typo..lol  As of writing this google still echos back ping results.Been looking for a way to ping internal network devices by running a batch file. 

I need to keep an eye on 15 different network sites and have been pinging them by opening up the cmd prompt and pinging each site continuously.  My problem is that I will have to open up 15 different cmd prompts and manually type in the ping command as well as the address that I want to ping.

My questions is how do I write a batch file to open cmd prompts, enter the address I want to ping, then open a new cmd prompt, enter the next address i want to ping, etc...Then I would like it to tile the boxes horizontally so I can keep an eye on all of them.


I got this far but do not know how to enter the text into the cmd prompt to start the ping.

I am very skilled in hardware troubleshooting/replacement but not so much in programming. 

echo
   start c:/windows/system32/cmd.exe




Any HELP is greatly appreciated.  I have searched some more and what I am trying to accomplish is probably very easy.  He is what I have so far:

start cmd.exe
ping xxx.xx.xx.xxx -t
start cmd.exe
ping xxx.xxx.xxx.xxx -t


 The first cmd prompt opens and pings the first address, however the second cmd prompt opens but does not ping the second address.   The problem I had was the batch file would not execute the next line of code after the ping -t command because that would not stop.

Ended up writing 14 batch files, each one opening the next batch file before executing the ping -t command. 

I am SURE there was a easier way to do it but it works for me.zuc, you are not supposed to hijack another person's thread, you should have started a new one.

You need to use start like this

start "window title" "command"

start "" "command"

window title can be blank, just 2 quotes but you must not omit it.

Example:

Script will start each command in separate window. To terminate each click on title bar or in box and type CTRL + C or click window close icon.

Code: [Select]start "yahoo" "cmd /c ping www.yahoo.com -t"
start "google" "cmd /c ping www.google.com -t"



644.

Solve : For Loop Token - How to use as variable?

Answer»

Hello,

I'm new at this and hope someone can help. I want to read in a text file with three fields a number, a file extension (e.g. .pdf), and a URL. The goal is to download the file from the URL and save it with a new name.
I am trying to construct one variable ("NewName") with the concatenation of fields read from the table but having no luck after many tries.
The field comes up blank as you can SEE from the batch output. Would appreciate any help in figuring out what I am doing wrong. I would also appreciate help understanding how to use the For loop tokens. I UNDERSTAND they are only "valid" in the loop itself but - are they always prefixed with two %% when using them, can they be assigned to variables?

Thanks a lot,

Diane

CODE:
set outputfile=Test.csv
set count=pharme

if exist %outputfile% del %outputfile%


FOR /F "tokens=1,2,3 delims=," %%G IN (spectrumnoformat.txt) DO If "%count%"=="pharme" (

set "NewName=%%G %%H"


echo "NewName=" %NewName%


download pharmetest.txt /batch /output:"c:\pharmefiles"\%NewName%

echo %%G,%%H,%%I >> %outputfile%) else goto :EndBatch

:EndBatch

echo "ending...."


Exit

[regaining space - attachment DELETED by admin]If I remember correctly, I think you need SetLocal enabledelayedexpansion on the first line. Then you access the vars with !G! instead of %%G or something. I haven't used batch in a while so I may be wrong. Quote from: Linux711 on November 09, 2011, 07:16:47 PM

If I remember correctly, I think you need SetLocal enabledelayedexpansion on the first line. Then you access the vars with !G! instead of %%G or something. I haven't used batch in a while so I may be wrong.
You'd still use %%G with delayed expansion enabled, but you'd use !newname! instead of %newname%.Thanks Linux711 and Helpmeh, though still need more help. I added the setlocal enabledelayedexpansion and changed % to !. Now the echo commands show the variable name, not it's value. I've tried this with many variation, but no luck. I finally tried to save the prefix and suffix to individual variables and then concatenate them. Still no go. Would you have any other ideas on where my error is? I've searched looking for clues but have found none.  Thanks a lot. Diane

CURRENT CODE:


set outputfile=PharmElog.csv
set count=pharme

if exist %outputfile% del %outputfile%

setlocal enabledelayedexpansion
 

FOR /F "tokens=1,2,3 delims=," %%G IN (spectrumnoformat.txt) DO If "%count%"=="pharme" (

set prefix=%%G
set suffix=%%H

echo !prefix!
echo !suffix!


set NewName=!prefix! !suffix!


echo !NewName!

[regaining space - attachment deleted by admin]Why are you setting %count% equal to "pharme" and then testing if %count% is equal to "pharme"? And why are you doing that weird DO IF? And where is the final parenthesis?

Quote
Now the echo commands show the variable name, not it's value.

It looks OK from here... you might see this better by putting ECHO OFF at the top of your file.  Your screenshot shows

Code: [SELECT]1
".pdf"
1 ".pdf"
These are the values of prefix, suffix, and newname when your echo commands run.  Just because it shows "ECHO !prefix!" in the output doesn't make it incorrect, that's just the way delayed expansion works.  I would however suggest removing the double quotes in your suffix, and removing the space in your NewName.  The first is accomplished by

Code: [Select]set suffix=%%~H
And the second by simply removing the space

Code: [Select]set NewName=!prefix!!suffix!SalmonTrout,

I agree the count is weird. I just started working with DOS and really want to have a record count and test the value of the string %%G but didn't know how do it (at least yet).  Would appreciate a tip on that. Sort of ditto for the For command. Going through forums that's method that was presented for reading a text file. Are there other methods?

My previous DOS experience is just a few system commands, so this is proving to be a good learning experience.

Thanks for your comments and would appreciate alternatives.

DianeYou didn't answer my question. I don't see why you are setting x=y and then straight away checking if x=y? Did you think it might have changed?

Quote from: DianeM on November 09, 2011, 06:32:47 PM
I would also appreciate help understanding how to use the For loop tokens. I understand they are only "valid" in the loop itself but - are they always prefixed with two %% when using them, can they be assigned to variables?

Check out this post for a good explanation from Salmon Trout on the use of tokens in a FOR loop.

I don't understand exactly on the count either. Are you hoping to have numbered lines that you are going through and want to ensure that the lines match up correctly? I guess the whole thing is that if you have no immediate need for the count variable now, lets dismiss it and concentrate on exactly what you are needing help with. Then later we can help explain some other things as you get a better understanding how all of the commands work.I was looking for a way to read a .txt file and then complete several steps - download a file and write a log to excel. I understood the FOR statement allowed one command after the DO. In looking for a way to have multiple steps I found the current method of FOR DO IF. I couldn't figure out how to deal with the field (via my prior response on testing the value) so I put in something that would be "true" to enable me to test the following steps and come back to that later.

Given how things have progressed, I don't need that IF statement and would prefer to just have multiple steps after the DO including a record count. Prior to adding the DO IF, I tried using the DO with a call to a label but could not get the %%G, etc. values to be present in the subroutine.

Does that help explain? It's been a crooked learning path.

DianeNow that we've figured that out, let's move on to solving this problem. 

Quickly, yes, the FOR loop can perform multiple commands, it does not require a DO IF to do so, only an open parenthesis at the end of the same line as the FOR command.

If you think your subroutine will work, you can call the routine after setting some of the variables in the FOR loop. Example:

Code: [Select]for /f "tokens=1,2* delims=," %%G in (spectrumnoformat.txt) do (
  set prefix=%%G
  set suffix=%%H
  call :subroutine
)
I would really only suggest a subroutine if you are trying to setup a loop within the FOR command. There are a few times this is legitimately the case (many times when errorchecking, for example) but in this case, if you think the subroutine will work, go ahead and use it.

To add a record count, simply add set /a count+=1 somewhere in the for loop (be sure to set count to a number somewhere before the for loop starts though.)

Please post if you are needing further explanation of things. Try to be as specific as you can, so that we can answer the correct question.Thanks a lot for clarifying the FOR statement. I'll probably end up simplifying a lot when I get a better understanding of how they actually work. Another gentleman pointed out I was missing an end bracket via email, so I'll spend some time going back over this routine to clean it up.

I really appreciate your help and interest.

I'll post back hopefully with news of success.

Thanks to all 
DianeYes!   The routine is now humming along.

I had to put my concatention in quotes as NewName only contained the suffix - set "NewName=!prefix! !suffix!"

Raven19528, I did not use a subroutine as it was not needed to accomplish the task. I also checked on the post you suggested by SalmonTrout but did not see any entries by him. Is there another entry?

Thank you for getting me on the right track.

Diane Quote from: DianeM on November 10, 2011, 06:18:36 PM
I also checked on the post you suggested by SalmonTrout but did not see any entries by him. Is there another entry?

I think he means Sidewinder.

Quote from: Salmon Trout on November 10, 2011, 11:55:06 PM
I think he means Sidewinder.

I did. It was late. It was my Friday. Both your names start with "S". I'm too poor to pay attention. (I've got plenty of excuses... )

In any case, sorry for confusion, and sorry to Sidewinder and Salmon Trout for the mix up.
645.

Solve : How to check if a program is running in cmd??

Answer»

So I'm writing some python and I want to make an if statement that checks if a program is RUNNING I figured the simplest way would be to use subprocess and check with cmd if the program is running. Since the program needs to be running at all times, it would also be ideal to have it start the program if it is not running.

I was hoping for SOMETHING such as:

IF [NOT] RUNNING foo.exe foo.exe

but as far as I have found, there isn't really anything like that. Sorry if this in almost unbearably easy, this is my first year really doing any programming, so I'm learning one STEP at a time haha. Code: [Select]tasklist /FI "IMAGENAME eq progname.exe">nul || start progname.exe
tasklist /? for help

tasklist to see a list of running programs.

Quote from: smckee6192 on November 19, 2011, 03:14:25 PM

So I'm writing some python and I want to make an if statement that checks if a program is running I figured the simplest way would be to use subprocess and check with cmd if the program is running.


I found this python code  that uses WMI to get a list of processes on Win32.

Code: [Select]import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
for objItem in colItems:
   PRINT "NAME: ", objItem.Name
   print "File location: ", objItem.ExecutablePath
646.

Solve : Need help with symbolic links!?

Answer»
Okay, so in a nutshell, I made a batch file that would rename .minecraft(minecraft's directory) to minecraft(3), then it would rename minecraft(2) to .minecraft, before renaming minecraft(3) to minecraft(2). This effectively allows me to, by the click of a mouse, switch between a modded game directory, and the regular version of the game. The modded directory is also a game version that has support for specific MODS, while the regular directory is the up to date version.

But I have one remaining problem. Whichever directory I am playing with at the time of a save, holds the save files in a folder titled "saves", which it must be titled to in order for minecraft to find the saves. This means that the other directory will not have the world saved at the spot I left off in the current directory, so if I switch directories I'd have to copy the saves to the new one, which is about 90% of the space in the whole directory. This would make the batch file - which is basically just for convenience, sense I wouldn't have to copy files - pointless.

So sense minecraft can't read a shortcut file(I tried putting a shortcut to one directories saves to the other, and retitled it from "saves - shortcut" to simply "saves"), I'm resorting to symbolic links.  I'm trying to use a command line with the MKLINK command. But everytime I type in the link and the target, it tells me "Cannot create a file when that file already exists." I've never used this before, and seeing how the first time it was used it gave me this error, I obviously can't actually have the file. So I'm assuming there's something wrong with my command line, which is where I need some help.

Here's my command line:

C:\Users\Noah>MKLINK /J C:\Users\Noah\AppData\Roaming\minecraft(… C:\Users\Noah\AppData\Roaming\.minecraft…

Legit is a folder, titled by minecraft when you create a world. So in other words, I have a world on minecraft named Legit, and in my saves folder, one of the folders is called Legit, and it contains the world's files. In case this is part of the problem, there IS another folder inside of the folder aswell. It is titled region, and contains more files(no folders). The folder in it's entirety contains 2 .dat files, a .lock file, a .settings file, and a folder containing 9 .mcr files.

and as I said before, I'm GETTING the error, "Cannot create a file when that file already exists."

Thanks for any help.Bump(not sure if I can bump my own thread) Quote from: Noahmcdx on November 21, 2011, 01:56:51 PM
Bump(not sure if I can bump my own thread)

You can, in the trivial sense that it is possible to for you to bump your own thread, but if you meant you weren't sure if it was good forum etiquette, the answer is "no it isn't". It really isn't. Bumping to raise your thread to the top of the recent posts list is seen as screaming for attention, and can DETER PEOPLE from answering, except in the MANNER of this post. If anyone (a) knows how to help you and (b) wants to, they will.

using multiple MC versions in this manner only requires you to rename the minecraft.jar file. I've been doing that since around Beta 1.3 when I need to.

Basically, I'd have a batch file for each version, which first copies minecraft.jar and VERSION files to backups, then renames a given file (like say Minecraft121.jar for Minecraft Beta 1.2_01, or Minecraft13.jar for 1.3, etc. to minecraft.jar, and another VERSION file to VERSION. Then it executes nlauncher (the new Minecraft Launcher) (using /wait if necessary) and afterwards it copies the backup files back.

You could give this jar switcher a whirl, instead.

http://www.minecraftforum.net/topic/514289-tool-minecraft-jar-switcher-and-backup-tool-v10/

647.

Solve : If Filename contains...?

Answer»

I want to make a batch file where I can drag-drop a number of DIFFERENT FILES into it. Then it NEEDS to check if the filename is similar to ONE of the predefined filenames and if so, execute a function to copy that file to the same directory with another filename.

Is this POSSIBLE and if so, how?http://www.outertech.com/index.php?_charisma_page=product&id=1

648.

Solve : skip last line using a for loop?

Answer»

using sqlcmd option in sql server, i generated a text file

in a batch script am taking that text file as input and processing a for loop there.

but how can i skip the LAST LINE of the text file without running in the for loop

i can USE skip=2 to skip the two lines.

in the ending i have query result information LIKE '40 row(s) selected '

I want to skip that without processing by for loop

Any help or idea is enough.. please helptry this in the loop
Code: [Select]for /f "delims=" %%a in ( ' find /v "(s)" yourfile.txt ' ) do ???????This filters out the unwanted lines from your fileAnother way is to use two FOR loops... the first one just counts the lines and thus you you know the number of the last line, the second one echoes all the lines except the last one

Code: [Select]echo off
setlocal enabledelayedexpansion
REM Loop (1) count lines
set line=0
for /f "delims=" %%L in ( ' TYPE "myfile.txt" ' ) do set /a line+=1
REM Subtract 1 from total
set /a maxline=%line%-1
REM Loop (2) echo every line in file except the last
set line=0
for /f "delims=" %%L in ( ' type "myfile.txt" ' ) do (
if !line! lss %maxline% echo %%L
set /a line+=1
)

649.

Solve : Complex batch file help?

Answer»

I know little about batch scripting so I am in NEED of some help. This script is a compilation of research and then left to gather dust. I really want it to work but it SEEMS like it skips some of the commands. My goal with the script is to do each section 1 at a time and then wait for an exe to close and then close different things 1 at a time.

I play a game called Minecraft. What I *want* the script to do is 1) close server.exe if it is running, 2) wait for exe to close and download server.exe again to make sure I have the latest greatest build, 3) wait until download is done then start a windows service that opens a VPN program I have, 4) start the server.exe i downloaded, 5) pause script until the server.exe is closed by me, 6) stop the service that was started earlier and THE END!


Code: [Select]echo off

:PREP
:: to make sure the server is dead
for /f "usebackq" %%A in (`tasklist /fi "windowtitle eq Minecraft server"`) do if %%A==INFO: goto DOWNLOAD
taskkill /f /fi "windowtitle eq Minecraft server" & GOTO DOWNLOAD
PING -n 1 -w 2000 1.1.1.1 > NUL
GOTO PREP

:DOWNLOAD
:: to download an updated server EXE
URL2File -d https://s3.amazonaws.com/MinecraftDownload/launcher/Minecraft_Server.exe Minecraft_Server.exe

:LOOP1
:: to make sure download is complete
for /f "usebackq" %%B in (`tasklist /fi "imagename eq URL2FILE.exe"`) do if %%B==INFO: goto CONTINUE
GOTO LOOP1

:CONTINUE
:: to start Hamachi if it isn't yet
for /F "tokens=3 delims=: " %%C in ('sc query Hamachi2Svc ^| findstr "        STATE"') do (
  if /I "%%C" NEQ "RUNNING" (
   sc start Hamachi2Svc
  )
)
GOTO STARTSERVER

:STARTSERVER
:: start the newly downloaded server EXE
start "" "C:\Program FILES (x86)\Minecraft\Minecraft_Server.exe"

:LOOP2
:: wait for server EXE to close before clean-up
for /f "usebackq" %%D in (`tasklist /fi "windowtitle eq Minecraft server"`) do if %%D==INFO: goto DONE
PING -n 1 -w 6000 1.1.1.1 > NUL
GOTO :LOOP2

:DONE
:: close out Hamachi
sc stop Hamachi2Svc
Oh I forgot to mention that I am not entirely sure how to write the FOR commands that are in my script. What I have done is attempt to nest IF commands inside every FOR command. Is this allowed? If so why doesn't my script work completely? If not what alternatives do I have?

My script *seems* to get all the way to the LOOP2 section and then just quits. Also it doesn't seem like it does any waiting.At a first glance, one thing I can see that MIGHT possibly make a script bomb is unquoted strings either side of an IF test. If %%D should ever evaluate to nothing (e.g. because the output of tasklist includes a blank line) then you will get a test like this

if ==INFO:

so try quotes like this (this is a good habit to get into)

if "%%D"=="INFO:" goto DONE

because

if ""=="INFO:"

is a valid test.

the section I am referring to:

:LOOP2
:: wait for server EXE to close before clean-up
for /f "usebackq" %%D in (`tasklist /fi "windowtitle eq Minecraft server"`) do if %%D==INFO: goto DONE
PING -n 1 -w 6000 1.1.1.1 > NUL
GOTO :LOOP2

:DONE

YOu could comment out the echo off line (REM echo off) and then you can see the script's progress. That might give some information.

By the way, I see you use the unofficial, unsupported double colon comment line starter ("::"). Beware because if you use this inside a loop, it will break it.



650.

Solve : Need help with finding a string in a file and then . . .?

Answer»

Our translation software translates a file and then writes it to a specific folder.  The batch file I'm writing needs to rename the file, but first, needs to determine if the file translation is finished before I try to do anything else, so, I need to first loop through the first file in a folder, look for the string 'end of file'.
If it finds 'end of file', then continue on with the rest of the code
else
try two more times to find the 'end of file' and if it doesn't find it, then move the file to an error folder and go to the next file.

The translations only takes seconds, but we've had issues in the past where every once in a while, the timing will be so that the batch file call will be just before the file gets finished translating, and cause problems.

Thanks for any help you can provide.

Jeanette
The translation software should have the file "open" and therefore unable to edit when it is writing to it. Is this statement not true in this case? If so, why?

An easy check would be to see if the file is indeed "open" and then act depending on ERRORLEVEL. Here's a simple construct of the test. It WORKS because you are not able to rename a file if it is being edited by another process.

Code: [Select]:loop
ren %filename1% %filename2%
if errorlevel 1 (
  ping 1.1.1.1 -n 1 -w 2000>nul
  goto loop
) else ren %filename2% %filename1%

You can also use some coding using the tasklist command to check and see if the translation task is still running. I'll see if I can find the old post that shows a good code on how to do that.
Quote from: Raven19528 on November 23, 2011, 01:04:22 PM

The translation software should have the file "open" and therefore unable to edit when it is writing to it. Is this statement not true in this case? If so, why?
Whether a file is open has no bearing whatsoever on whether the file can be CHANGED. That depends on the dwShareMode parameter that was used when the file was opened, which is usually as lax as possible. In this case the ShareMode would have to include FILE_SHARE_DELETE to allow renaming the file.

In any case, my point is that whether a file is open is entirely separate from whether it can be opened, read, written, renamed, or deleted. Quote from: BC_Programmer on November 23, 2011, 02:04:15 PM
In any case, my point is that whether a file is open is entirely separate from whether it can be opened, read, written, renamed, or deleted.

Right. Again, BRAIN too involved with visions of turkey INDUCED coma in very near future.

In any case, this post shows how to use the tasklist command to see if a program is running. It may provide a more accurate assessment of whether the translator program is running or not.