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.

651.

Solve : How Use Errorlevel Handler?

Answer»

I have scripts which has many DOS copy / xcopy / move statements.  I do not want to code if %ERRORLEVEL% after each statement which is completely inefficient, anyone have thoughts for the best way in handling this? 

copy statement 1
call errorhandler
copy statement 2
call errorhandler
copy statement 3
....
if errorfile size greater than zero, email error
:end

-----------------------------------------------------------------------------------------------------------------------
In the errorhandler, it would be best if it can CHECK for the errorlevel from the copy | xcopy | move,
if errorlevel equal zero:  return to caller
if errorlevel greater than zero:
   write to some errorfile
   return to caller to EXECUTE next statement....

I would think that as soon as I issue a call statement, the errorlevel would change.  Any ideas? Quote from: et_phonehome_2 on November 20, 2011, 09:02:48 AM

I do not want to code if %ERRORLEVEL% after each statement which is completely inefficient

Do you want to abort the script if a copy statement threw an error ? What do you mean "inefficient"?

I want it to continue onward, eg., execute copy1 then call the errorhandler, then return to execute copy2,.....

copy1
call errorhandler  # will always return to the next stmt whether there is an error or not
copy2
call errohandler   # will always return to the next stmt whether there is an error or not
.....
copyN
So the errorhandler will write a message to a log file and then return?

What message?

Will the errorhandler do ANYTHING else?

Why do you think you need to "call" the error handler?

You see, I don't understand why you think this...

Code: [SELECT]copy command1
call :errorhandler %errorlevel%
copy command 2
call :errorhandler %errorlevel%
...
copy command N
call :errorhandler %errorlevel%
goto end

:errorhandler
if %1 gtr 0 echo %date% %time% Copy error happened! >> error.log
goto :eof

:end
echo script finished

is more efficient than this:

Code: [Select]copy command1
if %errorlevel% gtr 0 echo %date% %time% Copy error happened! >> error.log
copy command 2
if %errorlevel% gtr 0 echo %date% %time% Copy error happened! >> error.log
...
copy command N
if %errorlevel% gtr 0 echo %date% %time% Copy error happened! >> error.log
echo script finished

When running a batch script that has copy | xcopy | move, it is possible to be unaware of an error not until someone tells you they are missing a file. 

You are correct that the error handler probably is not more efficient especially if I just want to OUTPUT that there was an error encountered since I am not zeroing in on a particular error code.
It's always good to get others ideas....  Thanks Salmon Trust.
I do not recall, what would the errorlevel be for the following:

copy path1\file path2\file >> /tmp/log.txt 2>&1
if %errorlevel% gtr 0 echo %date% %time% Copy error happened! >> error.log

the ">>" is just to capture the resultant output from the copy | move | xcopy command...
if the copy failed, but the ">>" was successful, what would the errorlevel be set to?
if the copy was successful, but the ">>" to a file failed, what would errorlevel be set to?
652.

Solve : Sample of an If statement, comparing two variables . . .?

Answer»

I'm used to using the PL SQL if-then-else CONCEPT, so this is really frustrating me.  I've found some examples, but evidently I'm doing something wrong, because when I add my if statement to the code, the file just bombs out and can't even capture what the error is.  Anyway, can someone show me a good example of an If statement, comparing two variables?

THANK you.
Jeanette Code: [Select]if %var1%==%var2% (
  echo Match
) else (
  echo No match
)
Use this when comparing two string variables to see if they match (Note: That is two equal signs.) As far as the structure goes, the "THEN" in what you are used to is implied after the logic test, making it a simple IF-ELSE structure, or even just an IF statement if nothing needs to happen if the logic test returns a "no" value. As I learned earlier today, watch out for quotation marks within the strings, as if there is only one, it can cause the IF construct to not WORK.

If you are comparing numerical values, you can use different compare operations such as equ, neq, gtr, lss, geq, leq; equal, not equal, greater than, less than, greater than or equal to, less than or equal to; respectively. Also, be sure that your parenthesis (if used) are correctly placed. The open parenthesis must start on the same line as either the IF or the ELSE commands, and the ELSE must be on the same line as the close parenthesis from the IF statement.Raven  .  .  .  thank you very much.  I will TRY that.  All the samples I found didn't use the 'else'.  Good to know that I can.

Thanks again.

653.

Solve : First time batcher needing help.?

Answer»

First let me appologise if this has been covered somewhere. i did look, but its hard to find something when you dont know the words you need

ok when you install games and programs in windows, it asks you to choose an installation location.

Is there a way to put into a batch file code that will seek the location of the folders you wish to modify.

in most instances the FOLDER i seek would normally reside in either C:\Games\folder or C:\Program Files\Folder.

based on my need, this would be run on several OS's(mainly XP/Vista/7), but hopefully apart from any syntax issues, it should be a simple batch that is able to run on all.

If it is not possible to program the batch to seek the location, is it possible to enable the user to manually enter it through the cmd box?

I really hope you guys can help You seem to be wanting the use of the dir command if you are just looking for locations.

dir /s /b "*somegame*"

That will search for all instances of "somegame" in the directory the batch is run under (which means if you "cd.." until you get to just the drive, you will search the entire drive.) Most times, where you run your batch will not be more than 10 folders deep in the file structure, however you can add more onto the below if you think you need to. Put this before the dir to search the entire structure:

cd..\..\..\..\..\..\..\..\..\..\

If you are just wanting to search in the specified folders (Games and Program Files) then change the cd command to cd c:\games or cd "c:\Program Files"

Of course all of this just outputs the full file path of the location of those files. When you say Quote

Is there a way to put into a batch file code that will seek the location of the folders you wish to modify.
I honestly don't know how to help unless you give me a little more information. Are you wanting explorer to open up to the file location? Are you wanting a batch to perform some tasks on the files within the folder? What modification are you looking to perform?

BTW, these commands will work equally well on all listed OS's.Sorry i should have explained what the entire job of the batch file is.
this is just an expresion of intent as i dont know batch language very well at all.

1. find install location.
2. create back up folder
3. move files from installed/subdir to install/subdir/backup
4. copy new files from /modinstall folders to installed/subdir
5. run /installed/file.exe
6. wait for file.exe to terminate
7. delete files(that we copied) from installed/subdir
8. restore files from /installed/subdir/backup to /installed/subdir

It will be fairly simple i think to do most of that, but in order for the whole thing to work, the batch file needs to be able to locate /installed or the entire script is for nothing.would just like to point out, im only asking for help with step 1, the rest i want to try myself, but i wouldnt know where to begin on step 1Okay, this gets a little tricky, because the location could be quite variable as far as where in the subdir the actual files you are trying to modify are located. If you are willing to do a little preliminary work, I can help you with a simple batch that will get the location. Let me know if you would like to do that, or if you are wanting ONE that will find what you are looking for WITHOUT prelim work.im willing to do whatever it takes to get this thing working.

the main thing is that the user recieving my files doesnt have to do anything except run the bat (and maybe type in their install location if it cant be auto DETECTED)

basicly the point of this bat is to make something that is complicated quite simple for them. can we use the file.exe as the anchor? its in the top directory of everything that needs to be modified.If you are looking for the "file.exe", then it becomes easy, so long as it is a unique name.

Code: [Select]echo off
cd ..\..\..\..\..\..\..\..\..\..\
for /f %%A in ('dir /s /b "file.exe" ') do set location=%%~dpA

Now if you are not certain if the "file.exe" will be unique (for example install.exe), then you just have to add a little more to ensure you grab the right one.

Code: [Select]echo off
cd ..\..\..\..\..\..\..\..\..\..\
for /f "delims=" %%A in ('dir /s /b "file.exe" ') do (
  echo %%A | find "[Unique folder string]"
  if errorlevel 0 set location=%%~dpA
)

Obviously you would need to substitute the [Unique folder string] with something that is unique to the name of the folder you are trying to get.

After either of these, the location variable should hold the folder you are trying to grab. If you need any help with any of the additional steps, please let us know. Quote from: Raven19528 on November 14, 2011, 09:47:04 AM
Most times, where you run your batch will not be more than 10 folders deep in the file structure, however you can add more onto the below if you think you need to. Put this before the dir to search the entire structure:
cd..\..\..\..\..\..\..\..\..\..\


Or just use \ to specify the root directory. Quote from: BC_Programmer on November 15, 2011, 11:01:30 AM
Or just use \ to specify the root directory.

Or that... Thank you very much!

LoL, i dont understand it, but it does look like the kind of thing that will work.

its going to be a very steep learning curve for me, and may take weeks till i get my head round it.

i will pop back in and report my progress and ask for more help if desperate...once i finish...or fail to finish, as the case may be. i will post the entire code here and the specific use it has come to.

It is very tempting to keep asking, i have more questions than answers atm, but as they say, "give a man a fish and he will eat for a day, teach him how to fish and he will eat for the rest of his life" Quote from: GiGaBaNE on November 15, 2011, 11:41:27 AM
"give a man a fish and he will eat for a day, teach him how to fish and he will eat for the rest of his life"

Yeah, but that's pretty close to, "The best way to teach a man to swim is to throw him in the water. The success rate is 100% for those who survive."  Quote from: Raven19528 on November 15, 2011, 11:48:37 AM
Yeah, but that's pretty close to, "The best way to teach a man to swim is to throw him in the water. The success rate is 100% for those who survive." 

The thing is, many people who visit forums like this regularly prefer helping someone who has made some kind of effort, to writing a whole script for somebody who isn't really interested in how it works.
654.

Solve : move files where filenames are not having extensions?

Answer» I have  a list of file names in File.txt, where they look like 'x yz.doc', 'ab c.doc'
the below code is working only if they are WRITTEN like this 'x yz.doc.docx', 'ab c.doc.docx' in File.txt.

Is there any way to make the below PROGRAM work for the list having 'x yz.doc', 'ab c.doc'??

Please help..



echo off
set old=c:\InPut
set new=c:\OutPut

REM create a text file for log purpose for the files which missed moving
echo Files not having DB entries > Missed.txt
echo --------------------------------- >> Missed.txt

for /f "delims= skip=1" %%G in (File.txt) do (
if EXIST %old%\%%G (
MOVE %old%\%%G %new%\
) else echo %%G >> Missed.txt
)

pause
Sorry I can not help.   
For the benefit of others, here is a reference to the skip options and some other things about the FOR command.
http://ss64.com/nt/for_f.htmlTo be sure that file handling code will correctly work with paths and file names that may have spaces, enclose them in QUOTE MARKS. This applies generally.

Code: [SELECT]for /f "delims= skip=1" %%G in (File.txt) do (
if EXIST "%old%\%%G" (
move "%old%\%%G" "%new%\"
) else echo %%G >> Missed.txt
)
655.

Solve : Bat To Exe error?

Answer»

I just finished my epic program, now I need it to run in the background.
I compiled it with BAT To Exe Converter and set it to invisible, but when I try to run it, i get the following error:
Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.
Does anybody know why this is happening and how to fix it?
Which OS do you have?
Some folders belong to other users or are somehow restricted to you. How this works depends on the OS and the SECURITY policy on you computer. In a BUSINESS environment the policy might have been set by SOMEBODY else.

This is Windows XP. I just use it at home, and I have administrator rights.
Here's the top of the error box (it's a popup):
C:\Documents and Settings\Owner\Local Settings\Temp\3E2.tmp\run.bat
By the way, my batch works on its own, but the converted format gives the error.bat2exe only works on plain DOS batch files. If you use long file names or any NT command-line extensions than it won't work.Try this one instead.
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.htmlIt works like a CHARM, but I just tried it on a different Windows 7 computer, so I'm not 100% sure it'll still work (the new Bat to Exe looks just like the one I was using!). I'll try it on the XP on Saturday.

EDIT: Holy crap, I cannot get it to stop. I've ended the run.bat process in Task Manager, but it keeps running! D:Try posting the revised code so we can determine what it's doing and why,,,Maybe at the end of your code you could use the taskkill command on conhost.exe.

656.

Solve : Script created to change log on account/password services help?

Answer»




i'm trying to write a script to stop a group of services , change the Log on name / set password for each service and then start then back up. For this examples I used the BITS Service in windows .....
What I have so far are as FOLLOWS:

I'm not sure about MUCH of this and any help would grateul!

sc query state= all | grep "SERVICE_NAME: BITS" > C:\sc.out


-----------------Start Services Change Script-------------------

sc config OBJ= TeeCee etc.
sc stop . . .
sc start . . .



C:\>sc stop

sc stop [BITS]

C:\>sc start

sc start [BITS] ...

C:\>sc config

SYNTAX:
sc config [BITS]
DisplayName=
password= ...


CONFIG OPTIONS:
NOTE: The option name includes the equal sign.
type=
start=
error=
binPath=
group=
tag=
depend=
obj=
DisplayName=
password=


---------------END--------------------------------------

 

It would seem you already have your code, you just need to put it together.

Code: [Select]sc <server> stop [BITS]
sc <server> config [BITS] obj=TeeCee DisplayName=<TESTUSER> Password=password
sc <server> start [BITS]

I don't use batch for a lot of network things, and this is untested.What would you suggest? I am trying to create something to run for a group of services...


Its about 8 services that I always changed per clients server to the correct domain\Log On and Password save it and restart services
but i have to do this for each of them everytime on tons of different servers so i was trying to find a better way..

Thanks for the help !!!!!!"It would seem you already have your code, you just need to put it together.


Code: [Select]
sc stop [BITS]
sc config [BITS] obj=TeeCee DisplayName= Password=password
sc start [BITS]

I don't use batch for a lot of network things, and this is untested."

and YES anything to help me put this together is greatly appriciated!Try this batch file. You will need to create a plain text list (in notepad) of servers using a carraige return to seperate them. I.e.


>>List.txt<<
server1
server2
server3
etc.

You will also need to fill in the [service1],[service2] in the below code with the services you are needing to change. Most of this code just allows you to run the batch file and determine the username and password when you run it instead of having to modify the batch every time. If the services tend to change often, you may want to run an embedded "for" loop to help alleviate your need to modify the batch program. Let me know if you would like to see that coded out.

Code: [Select]echo off
:username
cls
echo.
echo Enter the UserName
set /p user={User}
cls
echo.
echo %user%
echo.
echo Is this correct?
set /p yn1={y/n}
if /i "%yn1%"=="y" goto password
goto username
:password
cls
echo.
echo Enter the password
set /p pass={Password}
cls
echo.
echo %pass%
echo.
echo Is this correct?
set /p yn2={y/n}
if /i %yn2%"=="y" goto services
goto password
:services
for /f "delims=" %%A in (List.txt) do (
  sc %%A stop [service1]
  sc %%A config [service1] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [service1]
  sc %%A stop [service2]
  sc %%A config [service2] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [service2]
  ...lather, rinse, repeat...
)
Thank you kind sir!
What I have is as follows:

I created a list.txt and placed it in my root (C) , i'm also not sure what belongs in the field... i'm assuming my computer name , but after running it i'm getting a syntex error

Thoughts?

echo off
:username
cls
echo.
echo Enter the UserName
set /p user={User}
cls
echo.
echo %user%
echo.
echo Is this correct?
set /p yn1={y/n}
if /i "%yn1%"=="y" goto password
goto username
:password
cls
echo.
echo Enter the password
set /p pass={Password}
cls
echo.
echo %pass%
echo.
echo Is this correct?
set /p yn2={y/n}
if /i %yn2%"=="y" goto services
goto password
:services
for /f "delims=" %%A in (List.txt) do (
  sc %%A stop [BITS]
  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [BITS]
  sc %%A stop [BITS]
  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [BITS]
  ...lather, rinse, repeat...
)
Quote from: animalkrack3r on November 30, 2011, 04:49:20 PM
Code: [Select]for /f "delims=" %%A in (List.txt) do (
  sc %%A stop [BITS]
  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [BITS]
  sc %%A stop [BITS]
  sc %%A config [BITS] obj=TeeCee DisplayName=%user% Password=%pass%
  sc %%A start [BITS]
  ...lather, rinse, repeat...
)
*chuckles*

I love how you used the exact script... you can take out the lather, rinse, repeat line, it was in there so you would know that any additional services you wanted to update would have the same syntax as what you see there.

The server name needs to be the full computer name of the server. I.e. if you are on a domain, it needs to have the "dot domain name" included. If it is just your computer (or just the computer that it is going to run on), you can actually replace that with a "." and you will accomplish the same thing. If it is the same services that have to be configured on each server then wy not make a text file with the services that need to be configured and create an inner for loop to parse that as well.lol excuse my extreme noobness with batch files, thank you very very much Raven!

Squashman, explain ? thanks!
657.

Solve : Batch File That Opens A Specific Window In Outlook?

Answer»

Hello all,

This is my first time posting here. I have been googling this non-stop and I can't seem to find anything to make a batch file do what I want it to do, so I figured i'd ask you gentlemen.

My goal is to (through a batch file) open Microsoft Outlook's Global Address List preferably for a specific user.

Right now all that I have is start outlook.exe, which opens outlook to the main screen.

Inside outlook there is a search bar ALONG the top, if I could get this batch program to insert a pre-defined username into that box and then press enter- that would do EXACTLY what I need it to do.

Does anyone KNOW if this is possible via batch? Or if not that way, is there any other way to achieve my goal?

Thank you all in advance for any help.
A MUCH better way to do this would be through a VBscript. I'll try to work one up.Here is the VBscript for this. I am not a VBscripter by any definition of the term, but I know enough to get by. There may be some others on this board who can clean this script up, but it gets the job done that you are looking to get done. Type this out in notepad and save it as "VBOutlook.vbs" (or something similar, but with the .vbs extension.)

Code: [Select]On Error Resume Next
dim WshShell,oArgs

set oArgs=wscript.Arguments

sName=oArgs(0)

set WshShell = WScript.CreateObject("WScript.Shell")

rc=WshShell.Run("cmd", 2, FALSE)
Wscript.Sleep 1000
WshShell.AppActivate(cmd.exe)
WshShell.SendKeys CHR(34) & "c:\Program Files\Microsoft Office\Office12\outlook.exe" & CHR(34) & VBCRLF
WshShell.AppActivate(cmd.exe)
WshShell.SendKeys "exit" & VBCRLF
Wscript.Sleep 1000
WshShell.AppActivate(outlook.exe)
Wscript.Sleep 10000
WshShell.SendKeys "+^b"
Wscript.Sleep 1000
WshShell.SendKeys sName

set WshShell=Nothing
set oArgs=Nothing

Open the cmd prompt to the location of the script and type

Code: [Select]cscript VBOutlook.vbs Name

The sleeps are delays in milliseconds. I put in some LENGTHY delays because I know sometimes outlook doesn't like to open fast for me. You can adjust these numbers to suit your needs.Thanks for the help. I guess it just isn't possible from batch then, maybe I can have my batch script call this vbs. If I could make it transition smoothly this might work. Thank you very much for the script  , I will use this as a launching point to figure out if I can make this work or not.

658.

Solve : How to Copy the file in subfolders and move the same file to new folder?

Answer»

I want to COPY the file from subfolder C  (Folder--->subfolder A----> subfolder B------>subfolder C) and move the same file to a new folder.
Kindly assist me. Thanks in advanceTry using the copy command.

Code: [Select]copy "c:\folder\a\b\c\file.doc" "c:\newlocation\"
Hi Raven,
Thanks for your reply.

I think i have not explained the issue properly.

I need to copy *.txt from set of folders->subfolders->subfolders to a specific path.

i.e
C:\>Dir *.txt/s

I want to copy above out put files to a particular path.

should be similar to that of below command.
copy dir *.txt/s d:\text
But this will THROW error.
Hope i have explained clearly

thanks in advance
Jas
 Then try:

Code: [Select]xcopy "c:\folder\a\b\c\*.txt" "c:\newlocation\"

You may need to add some switches if you are needing additional THINGS, like subdirectories created and such. I would at least throw a /c in there so that the entire command completes despite errors which you can then review later. Try typing xcopy /? at the cmd prompt to see a full list of the switches available. If you are looking for everything in the subfolder, just endquote after the folder name: eg. "c:\folder\a\b\c" Quote

I need to copy *.txt from set of folders->subfolders->subfolders to a specific path.

i.e
C:\>Dir *.txt/s

for /f "delims=" %%A in ('dir /b c:\*.txt' ) do copy "%%~dpnxA" "d:\text"
The Poll is coming along nicely... just use xcopy if more than one file ie: xcopy c:\folder\folder\folder x:\destination
 oh and not SURE but file types need{ *.*.whatever} to WORK Quote from: patio on November 28, 2011, 05:09:23 PM
The Poll is coming along nicely...
I don't understand this specific Poll, both options are the same  Quote from: kbit on November 28, 2011, 10:51:25 PM
just use xcopy if more than one file ie: xcopy c:\folder\folder\folder x:\destination
 oh and not sure but file types need{ *.*.whatever} to work

I thnk you can safely ignore this post.
OMG prompt responses ... Tx a ton for every one for their replies....

But ,

Lemme explain you further about my folder structures.
*************
Tree ---> A -->1 -->2 -->3 --> xyz.txt
Tree ---> B -->1 -->2 -->3 --> abc.txt
Tree ---> C -->1 -->2 -->3 --> rxy.txt
Tree ---> D -->1 -->2 -->3 --> tuv.txt
Tree ---> E -->1 -->2 -->3 --> unv.txt
*************
Likewise, we have many folders, which were created by an application.  From the "Tree" directory,  i want to copy all the *.txt files to D:\Test

C:\Tree> Dir *.txt/s  ---- This displays all the txt files from the subdirectories.

My requirement : c:\Tree> Copy Dir *.txt/s D:\Test --- This command will not work, just to tell what is our requirement.

If i apply XCopy in the Tree Directory, it will copies *.txt files with their directories. BUT I NEED ONLY TXT FILES. We will be doing further process with the txt files.

Thanks in advance
Cheers
Jas



Try using the following code snippet:

Code: [Select]cd /d c:\tree
for /r %%A in (*.txt) do copy %%A d:\test

Please let us know either way if it works or not.

If you are trying to run this from the cmd prompt instead of a batch file, only use one "%" for the variable. I.e. %A instead of %%AThis is Awesome.......

Its working....Raven Thanks a lot


Cheers,
Jas
659.

Solve : Problem with cd?

Answer»

Hi.  I have a program where the user specifies a game directory and I create a bat file to launch the game.  Part of the bat file is switching to their directory.  I'm having an issue when people have foreign characters in their directory.  For example, someone from Brazil causes this command in their bat file:

Code: [Select]C:
cd "C:\Sérgio\Games"

Now, when I setup that same directory on my system, it WORKS fine.  But, I'm from USA.  However, on his, it doesn't work, and I suspect it's because he's USING a different language Windows (Portuguese). 

So, my QUESTION is, how can I deal with ISSUES like this?  My program simply cd's to their game directory in the batch file.  This is a big problem because I suspect many foreign users may have these characters in their path and I need to be ABLE to switch to this directory in order for things to work correctly.
You could try setting the console codepage to one with accented characters, e.g. 1252

Code: [Select]chcp 1252
I'll try that.  I'm starting to think it might be a Unicode thing since he's from Brazil and I'm from USA.  My program doesn't use Unicode.
*censored*, you were right.  Thanks!

660.

Solve : Remove the content of Temp Directory!????

Answer»

Hello folks, i want a bat file to remove every thing from the %temp% directory and my code is Code: [Select]del /q "%userprofile%\Local Settings\Temp\*.* but this bat file only removes the files and not the folders as ccleaner does.
So i am asking if anyone knows of a better bat files that could remove the folder as well.

Thank you, hoping for a suitable solution:Try using this:

Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"

You may need to add this to ensure you don't have system issues.

Code: [Select]md "%userprofile%\Local Settings\Temp"

BTW, this isn't working on my system because there are processes still running that are connected to files within the Temp directory. You may need to taskkill some stuff before the whole thing will work.

Personally, I think they should just bring back deltree and we'll call it a day.  Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*

There is no reason to delete the temp folder itself. And using that path specification is specific to Windows XP... why not use:

Code: [Select]del /q /s "%temp%\*.*"

This is more of a suggestion than an answer to your question, but anyway. It's so much nicer to just make a RAM disk and then re-route all your temp files to the RAM disk so whenever you reboot, then temp is automatically lost because the RAM is cleared. If you're going to delete the temp anyway, then why even store it on the hdd? It's just going to get fragged faster and bloated with crap. I think this should be built into future versions of Windows. BC: I know you're going to say why I am wrong. Go ahead.

Anyway, if you're interested, I can provide you with more instructions on how to do this. Quote from: Linux711 on November 15, 2011, 10:49:03 AM

BC: I know you're going to say why I am wrong. Go ahead.

Main problem would be rerouting the temp files to the RAM disk, since %TEMP% is a per-user variable. And of course the issue of using up your RAM for the otherwise menial task of storing temporary files. Aside from that, it's not a terrible idea on XP and earlier if the system has GOBS of RAM but low disk space. Quote
Main problem would be rerouting the temp files to the RAM disk, since %TEMP% is a per-user variable.

True. That's why I have created a batch that sets temp variables easily, so that it can be done for each user.

Code: [Select]echo off
SET /P DIRNAME=Type the path to the RAMDrive:
REG ADD "HKCU\Environment" /v TEMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKCU\Environment" /v TMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TEMP /t REG_EXPAND_SZ /d %DIRNAME% /f
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v TMP /t REG_EXPAND_SZ /d %DIRNAME% /f
Quote from: Raven19528 on November 15, 2011, 10:11:58 AM
Try using this:

Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"
BTW, this isn't working on my system because there are processes still running that are connected to files within the Temp directory. You may need to taskkill some stuff before the whole thing will work.

aannnnn Raven19528 what do you know Code: [Select]rd /s /q "%userprofile%\Local Settings\Temp"
your code works and it removes the folder as well as the files. Good going, by the way rd is the remove directory isn't it:then how come it removes the file as well . Sorry BC Programmer your code i.e., Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*  doesn't work it only removes the files same like my code except giving the /s switch. Same was for the other codes.

Anyways isn't it GREAT to know what a bat file can achieve to do the same task.

PS: Just thanked Raven for this job.is the 4KB used for the folder's directory entry really that critical? Quote from: Floppyman on November 16, 2011, 02:30:57 AM
by the way rd is the remove directory isn't it:then how come it removes the file as well .

Using the /s switch on the rd (which yes, is remove directory, same as rmdir) causes it to remove the folder and all files and folders within the directory. You can view the full explanation by typing rd /? at the cmd prompt.Hello hello newsflash Code: [Select] rd /s /q "%userprofile%\Local Settings\Temp" this code of Raven has stopped working , last time i had to perform a System Recovery and what do you know the bat file doesn't work to well.
 It removes the TEMP folder entirely, has  anyone even been trying this out. Its really important for me.

BC programmers does perform a little better Code: [Select]del /q /s "%userprofile%\Local Settings\Temp\*.*
Any suggestion i have to be better aware next time when i thank someone.
Little HELP here. Quote from: Floppyman on November 25, 2011, 10:07:04 PM
Any suggestion i have to be better aware next time when i thank someone.
Little help here.

What I do is perform rd /s . (can you see the dot?) from within each directory I want to clear. Being logged in to a directory via the CD command means it won't get deleted. I tend to always add the /d switch to the cd command but I guess that's a personal preference.

To turn off the "., Are you sure (Y/N)?" prompt, use the /q switch and if you don't want to see the messages about what it couldn't delete, add 2&GT;nul to redirect stderr to the null device.

For example: (the paths are mine, yours may differ)

cd /d %temp% & rd /s . /q 2>nul
cd /d %windir%\temp & rd /s . /q 2>nul


And Floppyman, maybe a bit less of the smart mouth? People have given their time freely to help you, and have done their best. Crude ungrateful sarcasm spoils the forum and looks bad. Anyhow, that's just my opinion.
Quote from: Floppyman on November 25, 2011, 10:07:04 PM
Little help here.

No need for this either. Helping you is not obligatory, and the goodwill that motivates people to do so is a fragile thing that is easily dispersed, as I hinted above.

I use to have this on a CD
Of course my 'CleanIt' folder also contained these files:
AllDone.exe (this is a 'dropcount' file)
CHOICE.com
sizeOLD.exe (this is a 'dropcount' file)
sizeNEW.exe (this is a 'dropcount' file)
taskkill.exe
TempClose.exe (An old AutoIt file)
wscript.exe

Anyway, if you want me to zip it up and attach all this stuff let me know
Actually not even sure if I'm allowed to do that?

It was originally made by me for Windows XP terminals that needed their Temp folders cleaned out periodically.
I also put an invisible script on it http://forums.techguy.org/dos-other/644932-solved-howto-run-batch-file.html

But these days, CCleaner has command prompt options, so its of no use anymore

Quote
echo off
TITLE ^>^>Temp Cleaner^<^<
start %cdrom%\CleanIt\sizeold %temp%
start /D%temp% /max .
rem start /D%temp% .
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im sizeold.exe
attrib -r -s %temp%\*.* /s
del %temp% /f /s /q
rmdir %temp% /s /q
del "%userprofile%\Recent" /q
start %cdrom%\CleanIt\sizenew %temp%
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im sizenew.exe
call %cdrom%\CleanIt\CHOICE /T:N,1
start %cdrom%\CleanIt\tempclose.exe
start %cdrom%\CleanIt\AllDone %temp%
call %cdrom%\CleanIt\CHOICE /T:N,3
call %cdrom%\CleanIt\taskkill /im AllDone.exe
exit
If there is ONE thing I've yet to understand, it's people's obsession with files in the temp directory, and treating their deletion like some kind of ritual involving relatively complex scripts. Could not agree more...course there are 100's of other relatively simple tasks we see people attempting to write complex scripts for as well.
661.

Solve : Batch file compiled into exe doesn't work correctly...?

Answer»

Hey, I compiled my batch file into an exe and it does not work. When I run it, it just says "Press any key to continue. . ." (pause).
Here is the code:
Code: [SELECT]ECHO OFF
SET BINDIR=%~dp0
CD /D "%BINDIR%"
"%ProgramFiles%\Java\jre6\bin\java.exe" -Xincgc -Xmx1G -jar Minecraft_Server.jar
PAUSEI'm using Windows 7 Home Premium if that makes any difference.
I have the bat to exe compiler from here: http://www.f2ko.de/programs.php?lang=en (not the online version)
-NathansswellNever mind, no help is needed. I just changed the directory from %programfiles% to C:\Program Files\ and took out all of the BINDIR stuff. Quote from: Nathansswell on December 03, 2011, 05:51:29 PM

I'm using Windows 7 Home Premium if that makes any difference.
[/quote
It would if it is 32 bit or 64 bit.  With a 64 bit OS, java is installed in the the Program Files (x86) folder.
Quote from: Squashman on December 03, 2011, 06:11:52 PM
With a 64 bit OS, java is installed in the the Program Files (x86) folder.

Only the 32 bit Java goes there. Like many people I have both. 64 bit apps (e.g. 64 bit browsers) use the 64 Java in C:\Program Files. 32 bit apps use the 32 bit Java in C:\Program Files (x86).

Anyhow, to the OP, and anyone INTERESTED in the topic of batch-to-exe converters, they are entirely unofficial, the quality of coding can be very variable, and they only support a subset of batch commands and features. If you really must have an .exe, use a different language e.g. FreeBasic.

And another thing... these so called batch-to-exe "compilers" don't actually compile anything; they just take your batch and ENCLOSE it in a wrapper. When the resulting .exe file is run, it extracts the original batch to a folder somewhere and runs it, so it is quite possible that %0 expands to something you don't expect.





Quote from: Salmon Trout on December 04, 2011, 01:42:36 AM
When the resulting .exe file is run, it extracts the original batch to a folder somewhere and runs it, so it is quite possible that %0 expands to something you don't expect.

Like this:

Test.bat

Code: [Select]echo off
echo %%0 values:
echo %%0                    %0
echo %%~dpnx0               %~dpnx0
echo %%~d0                  %~d0
echo %%~p0                  %~p0
echo %%~n0                  %~n0
echo %%~x0                  %~x0
echo %%programfiles%%        %programfiles%

Run test.bat in 64 bit CMD session:

Code: [Select]%0 values:
%0                    test.bat
%~dpnx0               c:\Batch\Bat_To_Exe_Converter\Test.bat
%~d0                  c:
%~p0                  \Batch\Bat_To_Exe_Converter\
%~n0                  Test
%~x0                  .bat
%programfiles%        C:\Program Files

Run test.bat in 32 bit cmd session:

Code: [Select]%0 values:
%0                    test.bat
%~dpnx0               C:\Batch\Bat_To_Exe_Converter\Test.bat
%~d0                  C:
%~p0                  \Batch\Bat_To_Exe_Converter\
%~n0                  Test
%~x0                  .bat
%programfiles%        C:\Program Files (x86)

Compile test.bat to test.exe and run from same folder:

Code: [Select]%0 values:
%0                    "C:\Users\UserName\AppData\Local\Temp\3564.tmp\Test.bat"
%~dpnx0               C:\Users\UserName\AppData\Local\Temp\3564.tmp\Test.bat
%~d0                  C:
%~p0                  \Users\UserName\AppData\Local\Temp\3564.tmp\
%~n0                  Test
%~x0                  .bat
%programfiles%        C:\Program Files (x86)

Run compiled test.exe from Drive Y: (a pen drive)

Code: [Select]%0 values:
%0                    "C:\Users\UserName\AppData\Local\Temp\C0A3.tmp\Test.bat"
%~dpnx0               C:\Users\UserName\AppData\Local\Temp\C0A3.tmp\Test.bat
%~d0                  C:
%~p0                  \Users\UserName\AppData\Local\Temp\C0A3.tmp\
%~n0                  Test
%~x0                  .bat
%programfiles%        C:\Program Files (x86)
662.

Solve : Echo repeatedly in same place without 3rd party exe?

Answer»

No need for GNU echo or other 3rd party apps.

Code: [Select]echo off
REM You need this
setlocal EnableDelayedExpansion

REM How to print over and over again on the same line

REM      This is a trick to get an ASCII 13 character
REM      (CR - Carriage Return) into a variable
for /F %%a in ('copy /Z "%0" nul') DO set "CR=%%a"

REM This is a demo that repeatedly echoes the time in the same place
REM Stop with CTRL + C
:loop

  REM <nul set /p "=xxx yyy zzz" is a trick to print xxx yyy zzz without a new line
  REM and echoing !CR! returns the cursor to the start of the line
  REM Must use the ! delayed expansion format for !CR!
  <nul set /p "=The time now is is %time%!CR!"

  REM make a delay
  ping -n 1 127.0.0.1 > nul

goto loop

It didn't perform in XP, the output was displayed as one continuous line indicating that both CR and LF were suppressed.  Any words of wisdom?

This worked, a tad slow probably due to the Cls repeats but gets there.  Same Ctrl+C to exit:

Code: [Select]echo off

:loop
  cls
 
  <nul set /p ="The time now is %time%"

  ping -n 1 127.0.0.1 > nul

goto loop


Quote from: Dusty on December 01, 2011, 07:26:59 PM

It didn't perform in XP, the output was displayed as one continuous line indicating that both CR and LF were suppressed.  Any words of wisdom?

This worked, a tad slow probably due to the Cls repeats but gets there.  Same Ctrl+C to exit:

Code: [Select]echo off

:loop
  cls
 
  <nul set /p ="The time now is %time%"

  ping -n 1 127.0.0.1 > nul

goto loop


I have run the same code that I posted above, in Windows 7 (64 bit) and Windows XP SP3 (32 bit) and it works equally well in both. Are you running exactly the same code? (That is, did you re type it or copy-and-paste?)


Quote from: Salmon Trout on December 02, 2011, 12:09:36 AM
I have run the same code that I posted above, in Windows 7 (64 bit) and Windows XP SP3 (32 bit) and it works equally well in both.

... and Windows 2000 SP4 also.




Right, thanks for all your work.   The script was copied/pasted.   I was probably a bit too hasty in completely condemning the script but still have a problem.

Although I've only tested in XP Home and XP Pro Corporate I cannot get the script to run successfully if Cmd.exe is opened then the bat filename entered using Start>Run>Cmd or opening a Cmd window using a shortcut..  This is true regardless of where the script is located.

The result is:

Code: [Select]The time now is is 17:33:53.56TheThe time now is is 17:33:53.73TheThe time now is is 17:33:53.90TheThe time now is is 17:33:54.06TheThe time now is is 17:33:54.25TheThe time now is is 17:33:54.40TheThe time now is is 17:33:54.57TheThe time now is is 17:33:54.75TheThe time now is is 17:33:54.92TheThe time now is is 17:33:55.09TheThe time now is is 17:33:55.25TheThe time now is is 17:33:55.43TheThe time now is is 17:33:55.59TheThe time now is is 17:33:55.78TheThe time now is is 17:33:55.95TheThe time now is is 17:33:56.09TheThe time now is is 17:33:56.28TheThe time now is is 17:33:56.42TheThe time now is is 17:33:56.60TheThe time now is is 17:33:56.78TheThe time now is is 17:33:56.93TheTerminate batch job (Y/N)?
Note the STUTTERING "The"

A wee bit of sleuthing shows that CR is being set to The in the first loop.

However the script does run successfully if run in the GUI (by clicking to open the file).   Any pearls of wisdom as to what I'm doing wrong?

Are you gonna believe it?    I was invoking the batch script using only the filename (without extension) so %0 contained just Trial1

When I invoked the script using Trial1.bat all went smoothly.   Another lesson learned.

Thanks again S.T.

D.I am gonna believe it, because of my own mistake! I saw the "trick to get a carriage return into a variable" ages ago and saved the line to play around with sometime. In the original code, it wasn't %0 - it was %~dpnx0 which expands to the full drive letter, path, name and extension of the script being run. I thought I'd simplify it and it worked OK for me because I always called it either in a command session using the name + extension or from Windows Explorer by double clicking the script icon. From what I can see, the trick exploits the fact that COPY /Z generates a CR for FOR /F to capture after a successful operation, (copying the current script to the null device must always work), and %0 works if you specify the extension, %~nx0 works if you are calling it from a different folder on the same drive, and you need %~dpnx0 if you are calling it from a different drive. I GUESS this makes sense in terms of how the shell assumes the current drive, path, etc when commands are typed, and knowing that Windows Explorer uses the whole drive/path/name/extension. So that %~dpnx0 was there for a reason, and you have very kindly helped me get that straight in my head, by your alertness and patient testing, for which I thank you.
Gee whizz, my ego has just done a quantum leap forward.

I've also found that if any accessible filename is USED instead of of %0 the script is quite happy to proceed when invoked using only the filename, obviously the file must be a permanent fixture in its location.   I have had success using %comspec%.

Onward and upward, thank you for the very interesting explanation.



I have found another way to get an ASCII 13 (or any other) character into a batch variable, this time using the jscript engine's String.fromCharCode function.

Code: [Select]echo WScript.echo (String.fromCharCode(WScript.arguments(0))); > ascii2string.vbs
For /F "delims=" %%a in ('CSCRIPT //NOLOGO /E:JScript ascii2string.vbs 13') Do Set "CR=%%a"
del ascii2string.vbs

The above replaces this line

for /F %%a in ('copy /Z "%0" nul') DO set "CR=%%a"

OK, it's 3 lines instead of 1 line, (although you can combine them into one using & ) and you need the batch to be in a writeable location, but you can specify which ASCII code you want in the variable e.g. 8 which is BACKSPACE. The trouble with using backspace is you have to count how many you want to use whereas CR just takes you back to the start of the line.

I am working on a way of actually embedding the jscript into the batch so it doesn't need to create and kill a separate temp vbs file and therefore could be run on a non-writeable medium.


Quote from: Salmon Trout on December 04, 2011, 07:05:29 AM
I am working on a way of actually embedding the jscript into the batch so it doesn't need to create and kill a separate temp vbs file and therefore could be run on a non-writeable medium.

Code: [Select]set Dummy=1;/*
echo off
REM The first line of this hybrid JScript/CMD script
REM begins with a command which is common to both script languages
REM and which makes the remainder of the line inconsequential to CMD.
REM CMD sets "Dummy" with the value "1;/*",
REM JScript sets "Dummy" to the value "1" and the /* starts a comment block
REM So the CMD part goes here where JScript will ignore it

setlocal EnableDelayedExpansion

REM PASS this script to the JScript engine to get CR character in a variable
For /F "delims=" %%a in ('cscript //nologo /E:JScript "%~dpnx0" 13') Do Set "CR=%%a"

REM This is a demo
for /L %%N in (1,1,100) do (
  <nul set /p "=!date! !time! %%N!CR!"
  ping -n 2 127.0.0.1 > nul
)
Echo Finished
pause
goto :eof

REM Below is the end of the JScript comment block
REM Under that is the JScript part of the hybrid script
REM We make CMD exit the script with goto :eof so it
REM never gets to the /*
REM NB Unlike VBScript, JScript is case sensitive
REM e.g. WScript needs
REM capital W and capital S and cript in lower
*/
WScript.Echo (String.fromCharCode(WScript.arguments(0)));
Just brilliant S.T.    Great fun, I added a beep as each time was displayed.   Great toy to play with for a while.

Thank you.It might have a practical use e.g. display the progress of some task or other; you could make a progress bar out of characters such as #
663.

Solve : how to find current directory from which batch file is executed?

Answer»

Hi
I am new to IT.
I have a batch file named myfile.bat placed at D:\myfolder1\

I WANT to know batch script which can identify the directory from which this batch file is currently executing even if the file has been moved to a new location.

is it possible? if yes then how? The parameter %~dp0 contains the batch script's DRIVE and path


Quote from: khurram Ilyas on December 02, 2011, 10:24:05 PM

Hi
I am new to IT.
I have a batch file named myfile.bat placed at D:\myfolder1\

I want to know batch script which can identify the directory from which this batch file is currently executing even if the file has been moved to a new location.

is it possible? if yes then how?

The OS will first  look at the CURRENT directory for myfile.bat
If myfile.bat is not in the current directory, the OS will use the official search path to fo find myfile.bat


C:\Windows\system32>path /?
Displays or sets a search path for executable files.

PATH [[drive:]path[;...][;%PATH%]
PATH ;

Type PATH without parameters to display the current path.
Including %PATH% in the new path setting causes the old path to be
appended to the new setting.

C:\Windows\system32>


C:\>cd  \

C:\>dir /s myfile.bat 
rem the above code will find all locations of myfile.bat on your computerFred, that doesn't actually answer the question which was asked: how can a batch file know its own directory? Quote from: Salmon Trout on December 03, 2011, 05:58:42 AM
Fred, that doesn't actually answer the question which was asked: how can a batch file know its own directory?


What happens when myfile.bat is stored in more than one directory?  Quote from: Fred6677 on December 03, 2011, 06:06:08 AM

What happens when myfile.bat is stored in more than one directory?

Each one, when run, will know which directory it is in.
Oh. Er, Hi Bill!

Now we've got that out of the way, maybe I'd better address the confusion that Bill has introduced.

The OP asked how a batch file may know its own folder. He asked:

Quote
I have a batch file named myfile.bat placed at D:\myfolder1\

I want to know batch script which can identify the directory from which this batch file is currently executing even if the file has been moved to a new location.

This is a typical question asked when the batch file is going to be placed on a medium (CD-ROM, pen drive etc) where the drive letter is not known in advance. Often the batch file is required to copy files from its own folder.

A batch file has access to the %0 parameter which can be used with the standard parameter modifiers so the batch file can get information about itself, its location, etc.

Code: [Select]echo off
echo This batch file's full path and name %~dpnx0
echo This batch file's drive letter is    %~d0
echo This batch file's folder is          %~dp0
echo This batch file's filename is        %~n0
echo This batch file's extension is       %~x0
echo This batch file's file date is       %~t0
echo This batch file's size in bytes is   %~z0
echo.
pause


Code: [Select]S:\Test\batch>dir
 Volume in drive S is USB-S
 Volume Serial Number is 2C51-AA7F

 Directory of S:\Test\batch

03/12/2011  15:34    <DIR>          .
03/12/2011  15:34    <DIR>          ..
03/12/2011  15:34               371 ShowData.bat
               1 File(s)            371 bytes
               2 Dir(s)  168,383,356,928 bytes free

S:\Test\batch>ShowData.bat
This batch file's full path and name S:\Test\batch\ShowData.bat
This batch file's drive letter is    S:
This batch file's folder is          S:\Test\batch\
This batch file's filename is        ShowData
This batch file's extension is       .bat
This batch file's file date is       03/12/2011 15:34
This batch file's size in bytes is   371

Press any key to continue . . .



and you run the batch file the result will be something like this


Quote from: Salmon Trout on December 03, 2011, 05:23:40 AM
The parameter %~dp0 contains the batch script's drive and path
Thanks Salmon Trout!
You provide the best & exact solution of my PROBLEM in only one line.
Thanks a lot
664.

Solve : wat is wrong in the syntax??

Answer»

the below code is working to move File.txt from Input folder to OutPut.

echo off
chdir c:\InPut
dir /B > File.txt
move File.txt c:OutPut
PAUSE

But when i try to move that to desktop, its telling error as
"the syntax of the command is incorrect".like below

echo off
chdir c:\InPut
dir /B > File.txt
move File.txt %userprofile%\Desktop\
pause
Have you checked the value of the %userprofile% variable? It probably CONTAINS space(s) which require you to use quotes.

Code: [Select]echo off
chdir c:\InPut
dir /B > File.txt
move File.txt "%userprofile%\Desktop"
pause

 If using Windows XP, it definitely contains SPACES, as it contains "Documents and Settings"Thanks Sidewinder - I made the same rookie mistake.
ANYHOW, the OP has cancelled his or account...
her... QUOTE from: patio on December 02, 2011, 12:03:12 PM

her...

I had "his or her account" in my brain but my fingers typed "his or account".

I knew that...
665.

Solve : Multiple variable with multiple text files?

Answer»

I am trying to do something I think is simple however I am having difficulty. I am trying to create a simple smpp application to send messages that will read the Numbers as well as text from a file as a variable. I can do one or the other but have been unable to do both at the same time.
This will send to the list of phone numbers in the list1.txt file

echo off
FOR /F "tokens=*" %%I in (C:\Users\Clay\Desktop\batch\list1.txt) do call :smppclient %%I goto :eof

:smppclient

echo %TIME% >> bulk.txt
smppclient -u username -p password -a ipaddress/port -s 1 -T "batch file test" -O Alerts -D %1  >> bulk.txt
:: DONE



The above will read the numbers from the  text file called list1.txt and send the text batch file test to each number.

What I want to do is one step FUTHER and make the text "batch file test" a variable and put it in a seperate text file.
Any help is appreciated and or samples / examples.


Clay
[email protected]
FOR /F "tokens=*" %%I in (C:\Users\Clay\Desktop\batch\list1.txt) do call :smppclient %%I goto :eof

Why is that there?

also, pls show at least part of list1.txt

Quote from: Zev on December 15, 2011, 02:04:00 PM

What I want to do is one step futher and make the text "batch file test" a variable and put it in a seperate text file.

I think the question you are thinking is not the question you are asking. The answer to this is:

Code: [SELECT]set bft="batch file test"
echo %bft% > seperate.txt
You seem like you probably already knew how to do this, so my question is, what exactly is your question?

In regards to your INITIAL statement, a FOR command like you have set up will capture text and numbers just the same. How do you know you are not able to capture both at the same time? Also, be aware that if there is text on one line, and a number on the next, then it isn't that the FOR command won't read them because they are different formats, but that it won't read them together because they are on different lines.

In any case, please expand and provide us with some better information so that we can give you the most correct answer.Are you saying that whatever  text message you want to send out to each number you just want to hard code it into a TXT file and read in that TXT file to send to each number?
This way you never have to edit the batch file.  You would only have to edit your list of phone numbers and the text message you want to send out.I have two text files.
First text file is list1.txt and contains the following
539990000
539990001
539990002
539990003
539990004
539990005
539990006
539990007
539990008
539990009
539990010
539990011
539990012
539990013
539990014
539990015
539990016
539990017
539990018
539990019
539990020
539990021
539990022
539990023
539990024
539990025
539990026
539990027
539990028
539990029
539990030


the second text file will contain up to 160 characters in this case for testing it will say
test of smppclient



contents of text.txt
test message


I have an application called smppproxy which I can manually inject messages I am trying to create a batch file to send to a list of numbers ( from a file) as well as use the text as a variable.
So if I want to send the text test message  to a given list of numbers ( list1.txt) with the text of (test mesage) I can
or I can change the text by having a different text in the text file.   


Below is the information on the smppproxy if that helps.  I apologize if I am not making myself clear. I have just been unable to read the text.txt file in as a variable
I have been able to send a message to an entire list of numbers with no trouble with the batch file below.  All I am trying to do is add one extra variable for the text
"batch file test" and the text is read from a file
The text also has to be in " "



echo off
FOR /F "tokens=*" %%I in (C:\Users\Clay\Desktop\batch\list1.txt) do call :smppclient %%I goto :eof

:smppclient

smppclient -u SMPPSMS -p TANSTAAF -a 208.52.110.18/16400 -s 1 -T "batch file test" -O Alerts -D %1  >> bulk.txt
:: DONE







C:\Services\executables>smppclient
Usage:

Option  Content     Description
------  -------     -----------
-h    BOOLEAN(0,1)    1 to print this usage message
-t    BOOLEAN(0,1)    1 to enable SMPP Tracing
-pp   BOOLEAN(0,1)    1 to enable Optional Parameter Printing
-lp   BOOLEAN(0,1)    1 to load Optional Params
-lap  BOOLEAN(0,1)    1 to load All Params
-pl   VALUE           1 to 8000, Payload length
-lm   BOOLEAN(0,1)    1 Send More Message Optional Parameter Value 1
-plt  VALUE           0-Default(WAP WDP),1-WCMP
-pf   STRING          Load the payload from this file name.
-V    VALUE           0x34 (Version 3.4)
-X    BOOLEAN(0,1)    ClientTransmitter = 1 (default)
                      ClientReceiver    = 0
                      ClientTransceiver = 2
-Q    BOOLEAN(0,1)    1 to Suppress output to screen
-k    BOOLEAN(0,1)    When unbinding, keep the TCP/IP session alive
-u    STRING(1..12)   Username, Ex: SYSID
-p    STRING(1..12)   Password, Ex: PASSWORD
-a    HOSTNAME/PORT   Ex: hostname/9703
-s    NUMBER(1..8000) number of Submits
-r    NUMBER(1..8000) number of Replaces
-c    NUMBER(1..8000) number of Cancels
-data NUMBER(1..8000) number of Data_sm
-sm   NUMBER(1..8000) number of Submit multis
-i    NUMBER(1..8000) number of Infos
-q    NUMBER(1..8000) number of Querys
-l    NUMBER(1..8000) number of EnquireLinks
-W    NUMBER(1..nnnn) Wait/Delay (milliseconds) between transactions
-rc   NUMBER(1..n)    Number of retries on connect fault
-rd   BOOLEAN(0,1)    Registered Delivery (mask)
                      0x00=None,   0x01:DlvNonDlv 0x02:NonDlv
                      0x04=DlvAck, 0x08:ManAck    0x10:IntAck
                      0x20=AlrAck
-ec   NUMBER          Esm Class, (mask)
                      0x00=Default 0x01=Datagram
                      0x02=Transactional 0x03=StoreForward
-rp   BOOLEAN(0,1)    ReplaceIfPresent    0 = No, 1 = Yes
-rb   BOOLEAN(0,1)    0 = No Rebind, 1 = Perform Rebind
-rcon BOOLEAN(0,1)    0 = No Reconnect, 1 = Perform reconnect and rebind
-dm   NUMBER(1..n)    Default message catalogue number
-vt   BOOLEAN(0..1)   Generate varied text strings
-T    DATA(1..128)    Message text
-d                    DCS/DataCodingScheme
-P    NUMBER(0..255)  PID/ProtocolId
-R    STRING          Address range for bind_receiver
-D    NUMBER          Dest Addr , Default 1230000...
-O    NUMBER          Orig Addr
-S    NUMBER          Service Type
-DT   STRING          DestTypeOfNumber
-OT   STRING          OrigTypeOfNumber
-DN   STRING          DestNumberPlan
-ON   STRING          OrigNumberPlan
-ba   STRING          Base Dest Address, will be incremented
-bo   STRING          Base Orig Address, will be incremented
-mp   NUMBER          Message Priority, 0 = Normal, 1 = Urgent
-mr   NUMBER          Message Reference - for Query/Cancel
-dt   UTC_TIME        Deferred Delivery Time  UTC_TIME: YYMMDDhhmmssnnp
-et   UTC_TIME        Message Expiry Time     UTC_TIME: YYMMDDhhmmssnnp
-st   STRING          System Type
-rt   NUMBER          Set the socket read timeout to NUMBER seconds. The default is no timeout.
-stats                Print statistics
-smcount NUMBER(1..8000) number of destinations per submit multi
-ws      NUMBER       The Bind Transmitter window size. The default is 1
-sp      NUMBER       WAP Source port
-dp      NUMBER       WAP Destination port
-ssu     NUMBER       WAP source subunit
-dsu     NUMBER       WAP destination subunit
-umr     NUMBER       User message reference

-mwi     NUMBER       Set the message waiting flags. The posible values are:
                      SMPP_MWI_OFF=0x00 - Turn MWI indication off
                      SMPP_MWI_ON =0x80 - Turn MWI indication on
                      The MWI ON/OFF values should be ored with these values:
                      SMPP_MWI_VOICE=0x00 - Voice mail message waiting
                      SMPP_MWI_FAX=0x01   - Fax message waiting
                      SMPP_MWI_EMAIL=0x02 - Email message waiting
                      SMPP_MWI_OTHER=0x03 - Other messaeg waiting
                      Count - No. of messages waiting [0-254] or 255(unknown)
                      Format: MWI or MWI,Count,...,MWI,Count
-rxcnt   NUMBER       messages count a client receiver will receive before sending an Unbind
Examples:
Submit:  smppclient -u 987654 -p PSWD -a hostname/5016 -s 10 -T HelloWorld -D 1234567
Replace: smppclient -u 987654 -p PSWD -a hostname/5016 -r 10 -T HelloWorld -D 1234567
Query:   smppclient -u 987654 -p PSWD -a hostname/5016 -q 10 -mr 1234...
Delete:  smppclient -u 987654 -p PSWD -a hostname/5016 -c 10 -mr 1234...
MWI:     smppclient -u 987654 -p PSWD -a hostname/5016 -s 1 -lp 1 -mwi 0x80,0x3,0x82,0x8




[regaining space - attachment deleted by admin]set /p message=I will remove myself from this very usefull  forum so you can deal with people on a higher level than I.I just gave you the answer.  You said you wanted to know how to put the contents of a TEXT file into a variable.  I just showed you that.

Code: [Select]H:\>set /p message=<text.txt

H:\>echo %message%
 Some text message I want to send

H:\>Will make it even easier for you.

Code: [Select]echo off
set /p message=<text.txt
FOR /F "tokens=*" %%I in (C:\Users\Clay\Desktop\batch\list1.txt) do (
echo %TIME% >> bulk.txt
smppclient -u username -p password -a ipaddress/port -s 1 -T "%message%" -O Alerts -D %%I  >> bulk.txt
)Hi Bill...Did he just delete his account.  Man that ticks me off.  Try and help someone and they just give up.  So all the time that you put in to helping them is just wasted. Quote from: Squashman on December 16, 2011, 09:42:37 AM
Did he just delete his account.  Man that ticks me off.  Try and help someone and they just give up.  So all the time that you put in to helping them is just wasted.

Can't change people Squashman, best to leave it be. You did answer the question, and if anyone else ever comes with the same or SIMILAR problem, you can refer them to this post instead of rehashing it again.

Best thing to do is just go pick up your favorite violent game and kill something. That always helps me feel better and is a great way to relieve FRUSTRATIONS.  Quote from: Raven19528 on December 16, 2011, 11:08:01 AM
Best thing to do is just go pick up your favorite violent game and kill something. That always helps me feel better and is a great way to relieve frustrations. 
I guess a quick game of Arkanoid will calm me down.
666.

Solve : help with drive letter changes to delete specified files from a usb key?

Answer»

hey guys new here, i wanted to pick your brains as im struggling to find an answer to what im looking for!

basically IVE got some software that my dad had wrote by a programmer it ships with hardware he sells, (vehicle diagnostics etc) im editting his installer that runs from a usb key which also acts as a security dongle so it has to be by dongle and i cant SWITCH to CD or DVD , it uses a batch file which i will eventually convert into a .exe as long as the code all works

the batch file works great, it all installs fine and goes thru spot on, the only thing i cant get to grips with is i would like to delete some driver files from the usb once it has installed, this is so people who try to steal the software will be missing crucial drivers (long story but go with me on this one for now!) my problem is when you put in a usb key, its normally a different drive letter everytime, so i cant link to a static drive letter to delete from  ie; C:/ D:/ etc etc, ive tried using CD\ (to go to top directory) and then DEL for delete but i cant seem to get it to work, im not overly experienced with ms dos, but ive coded in other languages so i understand the fundamentals just not the syntax,

heres what i have:

ECHO Y
CD\
del folder/file1.dll
del folder/file2.dll
del folder/file3.dll
del folder/file4.dll

i know its probably rubbish but hey ive tried for days on this before asking for help! thanks

SteveDo you care how long it is? If not, you could set up a bunch of if statements to search for a specific file on the drive then set the drive. A lot of this:

Code: [Select]if exist a:\folder\file1.dll set drv=a
if exist b:\folder\file1.dll set drv=b
etc...

Then you can do

Code: [Select]del %drv%\folder\file1.dll
etc.

Hope this helps. Let us know if not.
The OP had posted the same question in the Batch Programs Thread and I already answered it more fully, but in essence:

In a batch script %~d0 will expand to the drive letter of the drive that the script is on, so %~d0:\ is the root directory of that drive. You know the rest of the path to the files you want to delete so your commands will be something like this

Code: [Select]del "%~d0:\folder\file1.dll"
The quotes aren't essential if the whole path + filename does not contain any spaces but they don't do any harm. By the way the character after the percent sign is a ZERO.

Quote from: Salmon Trout on December 01, 2011, 01:21:26 PM

The OP had posted the same question in the Batch Programs Thread and I already answered it more fully, but in essence:

In a batch script %~d0 will expand to the drive letter of the drive that the script is on, so %~d0:\ is the root directory of that drive. You know the rest of the path to the files you want to delete so your commands will be something like this

Code: [Select]del "%~d0:\folder\file1.dll"
The quotes aren't essential if the whole path + filename does not contain any spaces but they don't do any harm. By the way the character after the percent sign is a ZERO.

that is what i was looking for thank you! instead of naming a drive i wanted to state THIS drive whatever letter it is it dont matter just this drive! rather than actually naming a drive! ill test it and see how it works thanks hopefully i wont bug no one anymore! ill defo stick around as its quite an interesting language im just completely unfamiliar with it

do i still use CD\ or is that now redundant as %~d effectively does the same thing?

thanks! Quote from: ekto on December 01, 2011, 01:28:11 PM
do i still use CD\ or is that now redundant as %~d effectively does the same thing?

CD\ will be redundant if you use the full path and filename.
that didnt seem to work? it gives this message: the filename, directory name, or volume label syntax is incorrect

it was all running from the usb key as well?

heres my code:

ECHO Y

del %~d0:\folder\file1.dll
del %~d0:\folder\file2.dll
del %~d0:\folder\file3.dll
del %~d0:\folder\file4.dll

pausewhat happens if you replace

del

with

echo del

?
it ECHOS on screen  like this:

F::\folder\file1.dll
etc
etc
etc

is it meant to have a double colon?

thanks
i tested with a single colon, i left it like this: del %~d0\folder\file.dll

but nothing happened and no files deleted, the only code i found that does work is this but it deletes the whole drive:

ECHO Y
CD ..
START CMD /C RMDIR /S /Q "%~dp0" Quote from: ekto on December 01, 2011, 02:44:30 PM

is it meant to have a double colon?


You spotted the problem. I made a mistake before, for which I apologise. The fact is that %~d0 becomes the drive letter and colon.

So the script should look like this

Code: [Select]del %~d0\folder\file1.dll
del %~d0\folder\file2.dll
del %~d0\folder\file3.dll
del %~d0\folder\file4.dll

Please forgive my error.
Quote from: Salmon Trout on December 01, 2011, 03:39:32 PM
So the script should look like this

Code: [Select]del %~d0\folder\file1.dll
del %~d0\folder\file2.dll
del %~d0\folder\file3.dll
del %~d0\folder\file4.dll

If that still isn't working, try putting quotes around it.

Code: [Select]del "%~d0\folder\file1.dll"
del "%~d0\folder\file2.dll"
del "%~d0\folder\file3.dll"
del "%~d0\folder\file4.dll"
Quote
\folder\file1.dll

We are presuming that this and the others are the actual folder and file names that need to be deleted? (I.e. they weren't just examples for discussion PURPOSES)

667.

Solve : Stop writing "echo"?

Answer»

Is there a way I could stop writing echo so many times but NOT in a continuous line?

What I mean is how could I do this

Code: [SELECT]echo Hi
echo other
echo stuff
echo here

but without writing echo so many times.

THANKS in advance!CTRL C
CTRL V ? ?I would still be writing a whole bunch of echos. The thing I'm trying to fix is not writing echo itself so many times.You could put your text into a file then TYPE it - as long as all the text is needed to appear together
So you don't like writing echo?  Join the madhouse!

Try this:

Code: [Select]set fred=echo

%fred% Hi
%fred% other
%fred% stuff
%fred% here
Quote

Is there a way I could stop writing echo so many times but NOT in a continuous line?

Yes, learn Powershell

If you mean NT batch, everything is a tradeoff. This little ditty requires a single echo command.. Better? You be the judge.

Code: [Select]echo off
for %%i in ("Hi" "Other" "Stuff" "Here") do echo %%~i

 
Code: [Select]set string="1 Paris" "2 London" "3 Rome" "4 Madrid"
for %%A in (%string%) do echo %%~A
Do you write with notepad?
Just write your stuff without using the word 'echo'. Substitute a symbol, maybe the character.
Then when you are done, use the replace all feature to change every to echo.
Is that not what you want?

Quote from: T.C. on November 14, 2011, 01:34:41 AM
So you don't like writing echo?  Join the madhouse!

Try this:

Code: [Select]set fred=echo

%fred% Hi
%fred% other
%fred% stuff
%fred% here

if you were brought up on BASIC you could do this to make yourself feel at home

Code: [Select]echo off
set gosub=call
set return=goto :eof

echo main code
%gosub% :subroutine
%gosub% :subroutine
%gosub% :subroutine
pause
exit

:subroutine
echo in subroutine
%return%


Quote from: Salmon Trout on November 17, 2011, 01:19:50 PM
if you were brought up on BASIC you could do this to make yourself feel at home


Would that be IBM Basic assembly language for system 360? Quote from: T.C. on November 17, 2011, 08:06:32 PM
Would that be IBM Basic assembly language for system 360?

IBM Basic assembly language doesn't have either RETURN or GOSUB instructions, which are pretty MUCH exclusive to dialects of BASIC. (BASIC != Basic)Just adding my two cents.
Code: [Select]echo off
CALL :ECHOS HI other stuff here
GOTO :EOF

:ECHOS
:ELOOP
IF "%1"=="" GOTO :EOF
echo %1
SHIFT
GOTO ELOOPMaybe the OP should tell us What he wants to do instead of How to do it.
As mentioned earlier, the TYPE command is used echo a whole text file.

Are you still thee? Please shoe an example whee you really did use echo many times in a batch file. He hasn't ben back in 3 WEEKS...
668.

Solve : VBS/Batchscript hybrid Eval.?

Answer»

Win XP Home 32 bit SP.3+ Cmd.exe

The following script returns Pi with 14 decimal places.  Is it possible to select the number of decimal places returned by Eval please?

Code: [Select]echo off
cls
setlocal 
echo wscript.echo eval(wscript.arguments(0))>%temp%\eval.vbs

set a=22
set b=7

set calc=%a%/%b%
call :calculate
set Pi=%result%

echo %Pi%

del %temp%\eval.vbs

exit /b

:calculate
for /f %%1 in ('cscript //nologo %temp%\eval.vbs "%calc%"') do (
    set result=%%1
)
Why?
Is this homework?
If you need a short  pi, just use a value you want as a global constant.
Of course, it will not be as accurate.

Pi to 12 decimal places is 3.141592653589Evaluate the expression

Code: [Select]Atn(1)*4
(instead of 22/7)Sorry, I didn't mean to ask how to calculate Pi, my question is Is it possible to select the number of decimal places returned by Eval please?     This holds good regardless what the values evaluated are, can Eval return a selected number of decimal places?

I'd like to use Eval when calculating dollar amounts.

Thanks.You are concerned with the visual output, - right?

Eval is common to several script things. Implementations vary. But yes, you can specify how many decimals to use. Read this:
http://en.wikipedia.org/wiki/Eval
The above article is a broad coverage. But it has the vital details.
Here is is the catch, you may have to provide some way for Eval to do what you want it to do. So you might want to use some other method to insure that your output is in a FIXED decimal format.
If you are lazy, use something that defines the output format.

What I want to say is that having two significant decimals is not the same as forcing two decimals in the visual output.
Example:
3.158 could be shown as 3.16
3.14 could be shown as 3.14
3.10 could be shown as 3.1   oops!!
you want a fixed decimal output, like currency, -Right?

Petroutsos writes, "The topic of PRINTING with Visual BASIC is a non-trivial topic...
Mastering Visual Basic .NET [Paperback]
Evangelos Petroutsos (Author)
http://www.amazon.com/Mastering-Visual-Basic-Evangelos-Petroutsos/dp/0782128777

But don't buy the book. Somebody will give you a clear answer.Call me crazy but I bet you can ROUND any number to the length of the decimal you want.1.

Quote

The following script returns Pi with 14 decimal places.

It does not. The fraction 22/7 is NOT equal to pi.

2. To use that VBScript one-liner to give a result rounded to 2 decimal places do this cscript //nologo %temp%\eval.vbs "round(%calc%,2)"

3. To get pi, use 4*ATN(1) as the expression to be evaluated

Code: [Select]c:\>for /f %A in ('cscript //nologo eval.vbs "round(4*ATN(1),5)"') do echo %A
3.14159
Remember to use 2 % signs in a batch (e.g. %%A)


what concerns me is the use of floating point with currency values, so I'll point out the existence of the CCur() function which will convert the VBScript value into a Currency (scaled 64-bit Integer) Variant, which is accurate to 4 decimal places and doesn't suffer from the various gotchas that one finds with floating point.

Quote
Petroutsos writes, "The topic of printing with Visual Basic is a non-trivial topic...
Mastering Visual Basic .NET [Paperback]
Nobody said anything about printing, or .NET, for that matter...Thank you all for your inputs.   

At my fairly basic level of knowledge some details in the replies are beyond my understanding but Round as shown by Salmon Trout does what I was looking for.

Kind regards to all.
Betty.Another option for you as well.
Code: [Select]C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,9)"') do echo %A
3.142857143 Quote from: Squashman on December 09, 2011, 04:57:34 PM
Another option for you as well.
Code: [Select]C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,9)"') do echo %A
3.142857143
Does not work for me.
Quote from: Geek-9pm on December 09, 2011, 05:31:46 PM
Does not work for me.
Did you create the eval.vbs script first?
Code: [Select]C:\Users\Squash\batch>echo wscript.echo eval(wscript.arguments(0))>eval.vbs

C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(22/7,5)"') do echo %A
3.14286

C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(4*ATN(1),5)"') do echo %A
3.14159

C:\Users\Squash\batch>for /f %A in ('cscript //nologo eval.vbs "FormatNumber(4*ATN(1),9)"') do echo %A
3.141592654if you don't want to round but rather want to truncate values:

Code: [Select]Function Truncate(ByVal Value,Byval NumDigits)
    Dim digitfactor
    digitfactor = (10^numdigits)
    Truncate = Fix(Value * digitfactor)/digitfactor
End Function
or just use that as part of the expression as needed, with eval.vbs.

Code: [Select]
for /f %A in ('cscript //nologo eval.vbs "Fix(Atn(1)*4*(10^4))/(10^4)"') do echo %A
replacing 4 with the desired number of significant digits. this should give back 3.1415 (rather than a rounded value of 3.1416)The OP started with the 22/7 thing and then later said she wanted to represent decimals like in dollar$. That is confusing. Who would ever calculate dollar values using a bad form of Pi?

And if for some reason you had to use Pi to calculate some kind of monetary thing, and if it was ever recursive or iterative, Pi would have to have more that just two decimals. The error would accumulate.

 Dollars requires a currency format. It has rules that go beyond Eval and Round and things like that. Currency imposes a strict format for the output as it would appear on a console or printer.

I still do not understand her intended use. Setting the number of decimal places does not mean that the output is consistent with a range of values that may occur in monetary transactions. They teach that in Computers 101. Is the OP just trying to bait us?
I'm back again to try to explain...

My original query was Is it possible to select the number of decimal places returned by Eval please? .   As simple as that.   

I now realise that I should not have posted referring to Pi or to currency amounts, those two subjects may have clouded the issue.   I had, and still have, no intention of calculating Pi, or using Pi in any calculation, the script was used as an example only and in my earlier vain attempts to solve my query without referring it to the forum.   All I wanted to know was if the number of decimal places returned by Eval could be selected.   

However, the experience has had its benefits, I now have several options and have enhanced my scant knowledge base.   It was never my intention to bait anyone, as a newbie I'm not clever enough or devious enough to do that, or to waste the very VALUABLE time of the forum gurus

If I ever post another query rest assured I will have given the format and WORDING of the query a lot more consideration than I did on this occasion.

Again thanks to all, please consider the subject closed.

Betty

669.

Solve : Help | I am new to making batch file :-(?

Answer»

Hi All,

I am new to creating batch file and need help with a basic batch file CREATION.  I guess it can be achieved in 2-3 lines.

I have CREATED a shortcut of the DUN object on my desktop (using a windows 7 machine) and am able to launch the DUN object with the following command
rasdial.exe C:\WINDOWS\Desktop\MyISP.lnk

What I want is a pause of 25 seconds before i launch the VPN program from my laptop.  Can someone please help with the pause and launching of the vpn program command line.

Thanks in advance.

Code: [Select]start "" "c:\path to folder\rasdial.exe" C:\WINDOWS\Desktop\MyISP.lnk
timeout /T 25 > nul
start "" "c:\path to folder\somevpnclient.exe"Thanks for the quick help/ response.  My VPN i sloading perfectly after the pause, but unfortunately My DUN is not launching/ dialing/ connecting automatically.  I have now moved the DUN short link on c:\MyISP.lnk.  Can you please suggest? Thanks in advance.

start "" "c:\path to folder\rasdial.exe" C:\WINDOWS\Desktop\MyISP.lnk
timeout /T 25 > nul
start "" "c:\path to folder\somevpnclient.exe"Please post the exact code you are using in the batch file.  Most of us here are not omniscient.I have TESTED the VPN code and it worked fine.  So i was just testing the following code to start the DUN object with the following code.

start "" rasdial.exe "C:\MyISP.lnk"

ThanksYou don't need to specify rasdial.  Rasdial does take command line options but you already have that all specified in your Shortcut Link.

Just use the Shortcut link
Code: [Select]start "" "C:\MyISP.lnk"
If you have a PHONE book entry for your connection you could then use the RASDIAL command as well.
Code: [Select]rasdial "office 2"
If you wanted to do it completely from scratch you could just do
rasdial username password /phone:9995551234
Code: [Select]C:\Documents and Settings\Squash\Desktop>rasdial /?
USAGE:
        rasdial entryname [username [password|*]] [/DOMAIN:domain]
                [/PHONE:phonenumber] [/CALLBACK:callbacknumber]
                [/PHONEBOOK:phonebookfile] [/PREFIXSUFFIX]

        rasdial [entryname] /DISCONNECT

        rasdial

670.

Solve : Password Encoder+Decoder?

Answer»

I'm making a Register Program and I was wondering if anyone had code to Encode and to Decode a String.

Thanks.Are you talking about encryption? Encoding would ESSENTIALLY be putting something into programming language. Please be more specific. Quote from: Raven19528 on December 16, 2011, 11:04:51 AM

Are you talking about encryption? Encoding would essentially be putting something into programming language. Please be more specific.

Encoding and Encryption are both routines that work with data. Has nothing to do with a programming language in either case. Encryptions purpose is to disguise the data so that it cannot be read by anyone but the intended recipient. Encoding is used merely to work with a data in a more suitable FORMAT, or for space or other concerns. For example, most compression algorithms are encoding/decoding algorithms.
in the case of a zip or other compressed file that is ENCRYPTED, you've got both.

That said, they do probably mean encryption. And if you don't know how to do something like this, I THINK it is time to reassess whether you really ought to spend time adding a pointless "feature" like this to a application when you could be working on new features and/or functionality of the application.
671.

Solve : Date by month-day-year in batch file??

Answer»

I am wondering if it is possible to have a batch file display the Month first, then the day, then the year.

I have this, but it is in the wrong order and I don't understand it. I found it off some forum, but it's not what I want...

Code: [Select]echo off
set date=%date:~10,4%%date:~7,2%%date:~4,2%
echo %date%
pause >nul
If this were today, it would echo "20110712."
I would like mine to be "December 07 2011."
If that is not possible then I'd be fine with "12072011"

Also, congrats for the next post in the "Microsoft DOS," you are the 8,888th topic!!!

-NathansswellThe date variable is dependent on your Regional settings in control panel.

My date is currently set like this.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date%
Wed 12/07/2011So the first thing you need to understand is that computers start counting by 0.  So if I want to pull out the day of the week I would need to reference position 0 for a length of 3.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date:~0,3%
WedIf I want the year I could do it two different ways.  I could reference the 11 position by using the number 10 for a length of 4.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date:~10,4%
2011Or I could reference from the back side by using a negative number first.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date:~-4,4%
2011
Does that help you out.I customized my SHORT DATE format in my Regional settings and there doesn't SEEM to be be a way to completely spell out the Month.  It will only give you the abbreviation of the month.  So I made my short date format MMMM dd yyyy and it comes out like this at the cmd PROMPT.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date%
Dec 07 2011
So if you want the Date spelled out completely you could just do a bunch of IF statements to match the Month and the set a variable to the full month name.Just remembered I did something similar like this a few weeks ago on another forum.
So again if your date variable outputs like this.
Code: [Select]C:\Users\Squash\batch\Increment>echo %date%
Wed 12/07/2011 Code: [Select]echo off
:: setting v to equal the current numeric month
set v=%date:~4,2%

:: putting all the possible months into a variable which will be parsed in the for loop
set month_text="01 January" "02 February" "03 March" "04 April" "05 MAY" "06 June" "07 July" "08 August" "09 September" "10 October" "11 November" "12 December"

:: for loop is parsing the month_text variable and using the find command with the numeric month to set the month variable
for %%I in (%month_text%) do echo %%I |find "%v%" &&set month=%%~I
:: Need to remove the Number and space
echo %month:~3% %date:~7,2% %date:~10,4%It will output this.
Code: [Select]C:\Users\Squash\batch>getmonth.bat
"12 December"
December 07 2011

672.

Solve : batch file to check whether a file is completely written?

Answer»

Hi all,

Can anyone suggest me whether its possible to write a batch to check whether a file is completely written or in the process of writing. filecheck.bat path\filename should tell whether that file is completely written or in progress.

Thanks in advanceI am unsure if this is possible in batch, but I know I could definitely do it in VB. If you want me to build it for you, feel free to PM me.Yes it is possible. You cannot rename a file which is in USE by another process, so all you have to do is test if the file exists and then ATTEMPT to rename the file to a dummy name (which does not exist). If the errorlevel is greater than 0 then the file is in use by another process and you cannot rename it. If the errorlevel is zero then the rename succeeded so you rename it back again to its real name. Of course we assume that other sources of error are taken care of e.g. read-only medium, dummy file already exists, etc.




Thanks both.

Bob can u help me in PROVIDING the vb script.

To clarify, I spoke of Visual Basic, not the Scripting variant of such. I could certainly help you if you wish. I just need about three days, because I don't have constant computer access.batch

Code: [Select]echo off
echo Testing file %~nx1
if not exist "%~dpnx1" echo File does not exist! & goto END
if exist "%~dp1\dummy.file" del "%~dp1\dummy.file"
ren "%~dpnx1" dummy.file
If %Errorlevel% gtr 0 (
echo file in use
) else (
echo file not in use
ren "%~dp1\dummy.file" "%~nx1"
)
:end
VBscript

Code: [Select]filespec=wscript.arguments(0)
set fso=createobject("scripting.filesystemobject")
on error resume next
if not fso.fileexists(filespec) then
    wscript.echo "File does not exist!"
    set fso=nothing : wscript.quit(1)
end if

wscript.echo "Testing file " & Filespec
set ots=fso.opentextfile(filespec,8,false)    'forappending
if err.number<>0 then
     wscript.echo "file in use" : err.clear
else
    wscript.echo "file not in use"
    ots.close
end if
on error goto 0
set ots=nothing : set fso=nothing
Never mind VB. Thank you, Salmon Trout.Thanks salman trout.I am thinking you could probably do this also with the OPENFILES command or the HANDLE Utility.
http://technet.microsoft.com/en-us/sysinternals/bb896655

673.

Solve : Problems in batch file running in parallel?

Answer»

this problem is associated with my SERVER (Windows Server 2003 R2 Enterprise x64 EDITION)

I have two scheduled tasks which runs two batch files respectively (let's called them A.bat and B.bat) on 2am and 7am everyday. The things they do are quite similar, exporting dump files in DATABASE for different schema (around 10 schema for A.bat and around 6 for B.bat) and zipping them accordingly.

Dump files for different schema are exported successfully but some of them couldn't be zipped. Usually those dump files which could not be zipped are created after 7am. I managed to do the zipping (7-zip) in parallel in cmd so parallel zipping should not be causing the problem. One strange thing that I observed is that the batch file continues to run, exporting dump file for next schema, even though it didn't zip the dump file for current schema. And usually A.bat doesn't execute the "goto endloop"

There is no sign of error in the log that I have kept.
Below is part of the batch file,

:loop
if %curr_schema%==END goto endloop
if %count% GEQ 1000 goto endloop
exp PARFILE=%backup_root_dir%\%curr_schema%.par
   "C:\program files\7-zip\7z" a -t7z %dest%\%curr_schema%_%curdate%.7z %dest%\%curr_schema%_%curdate%.dmp      >> %logfile%
goto loop
:endloop
echo done!How does the variable %count% get incremented? And does either of the paths you supply to 7-zip contain spaces?

I do the increment by
set /a count=%count%+1

All paths I supply to 7-zip contain no space.I think it would be beneficial to everyone if we could SEE each batch file in its entirety and see how the Tasks are scheduled in Task Scheduler. Quote from: Squashman on December 08, 2011, 05:25:17 AM

I think it would be beneficial to everyone if we could see each batch file in its entirety and see how the Tasks are scheduled in Task Scheduler.

+1
674.

Solve : Meaning of "echo."?

Answer»

What is the meaning of "echo."?  I cannot find this ANYWHERE.  I know it does not print the ".".

In general, is there a place where the functions of non-alphabetical characters  are listed?  For example "", ">" (used in redirection), etc.

I have a copy of Peter Norton's DOS 5 Guide.  It has a lot of information, but not on any DOS commands after 1991.  Any good recent book on DOS?  This site is very good, but I have trouble searching through it.

Tomecho. is for inserting BLANK lines, mainly for formatting purposes or ENHANCING readability.http://www.robvanderwoude.com/bht.php#StripThanks dbam and Squashman for the answer and information about ROB Vanderwoude's WEB site.

Tom

675.

Solve : Need a DOS vesion that orks with NTFS formatted disks.?

Answer»

Very unhappy with the version of DOS that comes with Windows XP Pro.  I am tired of getting messages telling me I cannot do what I want to do.  An example is deleting a file that was left by an old program.  MS TELLS me that XP and XP DOS are not allowed to do it.

Is there a DOS version available (does not NEED to be free) that works with NTFS formatted disks and does not listen to Microsoft?

I have MS DOS 6.2, but as I remember it does not read NTFS formatted disks.

Tom
Quote from: tomkaz on December 03, 2011, 01:27:14 PM

Is there a DOS version available (does not need to be free) that works with NTFS formatted disks and does not listen to Microsoft?

Think about this.

"Is there a DOS (IMPLYING MS_DOS [Microsoft_Disk Operating SYSTEM]) version that works with NTFS (Microsoft developed file system) and does not listen to Microsoft?"

Ummm... No.

Try Linix.

On to the deeper issue, what error messages are you getting? If it's an old file that isn't used by any program at the time and you have administrative privileges to the computer, there should be no reason you can't delete it. You may have a virus.NTFS4DOSSorry for the delay in returning.

Thanks for the replies.  I'll get NFTS4DOS.

Tom
676.

Solve : does closing cmd window terminate the command running??

Answer»

does closing the cmd window currently running a DEL /f/s/q filepath
terminate the deletion process


i had it running by accident and needed to stop, in my PANIC i closed the cmd window
did that stop it?

also i disconnected myself from that drive
and shut down.

i know i lost some FILES because it was running very fast
but did i stop it when i closed it?When cmd.exe stops, so do any internal commands, and del is internal. You could have used CTRL + C.
thank you for responding , yes i forgot about cntr + c , i didnt keep my cool .

well thats a load off, i know it deleted some files but a few is better then the TB of data Quote from: InternJ on December 13, 2011, 03:51:34 PM

well thats a load off, i know it deleted some files but a few is better then the TB of data

Surely you know how to find how much data and how many files are left?


677.

Solve : create null file's?

Answer»

hi

I have a quasion if possible help me. thanks
i need a batch file so

1: i have a file in folder  F:\modern and the file name is  modern.iwi (base file)
2: and so another file with name.txt in F:\Name folder (this txt file inclod 500 name's each name per line )

so i want a batch for this:

create a 500 file's (as the name.txt file have 500 name's) by using the modern.iwi and Name.txt files...
my means copy the modern.iwi with a new name is in the name.txt file in F:\new folder

thanks very much...
Put this batch file in the same folder as your Name.txt file and run it.
CODE: [Select]for /f "tokens=*" %%A in (name.txt) do copy "f:\modern\modern.iwi" "F:\New Folder\%%~A"its nice man very thank you 

so is it possible Instead of name.txt use the name of file's from F:\Ramin folder (with out name.txt)!? Quote from: raminr63 on December 14, 2011, 02:57:55 PM

its nice man very thank you 

so is it possible Instead of name.txt use the name of file's from F:\Ramin folder (with out name.txt)!?

so instead of (name.txt), try this ('dir /b f:\ramin'), let me know if that works Quote from: skorpio07 on December 14, 2011, 03:49:19 PM

so instead of (name.txt), try this ('dir /b f:\ramin'), let me know if that works
When I do use the dir command I always try and do a pushd to set the working directory FIRST and I usually make sure I exclude listing directories.

But it would probably be better to ue the for /d option.i am noob 

can you give me a complate cod for (( so instead of (name.txt), try this ('dir /b f:\ramin'), let me know if that works ))such as

Quote
for /f "tokens=*" %%A in (name.txt) do copy "f:\modern\modern.iwi" "F:\New Folder\%%~A"

so thanks

and
/ Squashman thank's for help Code: [Select]for /f "tokens=*" %%A in ('dir /b f:\ramin') do copy "f:\modern\modern.iwi" "F:\New Folder\%%~nA"
Squashman's pushd reference is good, though unnecessary in this instance I believe (though not a bad habit to start if you are planning on getting into programming.) I don't understand the point behind using the /d switch over the /f switch though. Please explain./Raven19528
Thanks its working good
I know it's more but i have just 1 question again

when the source [ ('dir /b f:\ramin') ] have sub-folders i must create sub-folders manually in [ "F:\New Folder\%%~nA" ] with out it, its not worked so is it possible the sub-folders create automatically (forced) with out me ?!! 

and it just only copy the file names from [ ('dir /b f:\ramin') ] and the file format from [ f:\modern\modern.iwi ] not copied ?!! so the copied files have no formats ?! Quote from: Raven19528 on December 14, 2011, 05:25:44 PM
I don't understand the point behind using the /d switch over the /f switch though. Please explain.

It's not "instead" of the /f switch.

FOR can use wildcards like this FOR %%A in (*) which will find files, FOR /D %%A in (*) will find directories. SEE the FOR help.
Quote from: raminr63 on December 14, 2011, 09:34:46 PM
I know it's more but i have just 1 question again

when the source [ ('dir /b f:\ramin') ] have sub-folders i must create sub-folders manually in [ "F:\New Folder\%%~nA" ] with out it, its not worked so is it possible the sub-folders create automatically (forced) with out me ?!! 

and it just only copy the file names from [ ('dir /b f:\ramin') ] and the file format from [ f:\modern\modern.iwi ] not copied ?!! so the copied files have no formats ?!

?! and waitting lol Quote from: raminr63 on December 15, 2011, 02:09:09 AM
?! and waitting lol

Goodbye... un-notifying...
Quote from: Salmon Trout on December 15, 2011, 12:27:50 AM
FOR can use wildcards like this FOR %%A in (*) which will find files, FOR /D %%A in (*) will find directories. See the FOR help.

So if I get this right, I could use 'FOR /F /D %%A in (*)' and find both files and directories in a particular location? Would this find the files and folders within the SUBDIRECTORIES? I would think not because that would be what the /R switch is for, but I'm not certain.

Quote from: raminr63 on December 15, 2011, 02:09:09 AM
?! and waitting lol

Comments like this (as shown) are not appreciated. Understand that we do not work on this forum, but that we volunteer our time and knowledge as we can. This is a really fast way to make sure that your posts are ignored by those who can provide you help. And the  at the end does not make up for the blatent impatientness of the post.

It's my belief that this is a situation where Squashman's suggestion of using pushd will be needed to help get everything done the right way. I haven't taken the time to try to test anything on this, but perhaps if you can show some patience, the SPIRIT of the holiday season will be enough that you do receive some help on the topic.

Again, we work here for free. Please keep that in mind when requesting help. Quote from: Raven19528 on December 16, 2011, 11:25:57 AM
So if I get this right, I could use 'FOR /F /D %%A in (*)' and find both files and directories in a particular location? Would this find the files and folders within the subdirectories? I would think not because that would be what the /R switch is for, but I'm not certain.

The FOR help, accessed by typing FOR /? at the prompt describes the syntax very clearly.

678.

Solve : How do delimit an environment variable?

Answer»

search around for this but couldn't find anything that would work.

i have an environ var called %testfile% that has a value of "sp.cmd"

i need to use the first part of the filename so i tried this which worked.

set temp=%testfile:~0,2%

however, that only works on filesnames with 2 characters, it needs to be more flexible than that.

the question is how can i run a token or delim to capture either the  length of the filename (or the name itself) or have it omit the ".cmd" extension part.

can anyone help out here?Try this:

Code: [Select]
for /f "tokens=1 delims=." %%1 in ("%testfile%") do (
    set filenam=%%1
)

echo %filenam%
right on!

and now i learned something new with both the FOR and the tokens (was close but really not so close, lol   )

thanks very much for the fast reply...

might have one or two more questions up my sleeve, hopefully they are harder than this one (smiles)I wouldn't make a habit of using numbers for the FOR loop variable especially if you have batch files that use cmd line input or you are calling another label or batch file. Quote from: Squashman

I wouldn't make a habit of using numbers for the FOR loop variable especially if you have batch files that use cmd line input or you are calling another label or batch file.

I've been using numerals (and most PRINTABLE ASCII special characters in the range of decimal 33 thru' 254) as For loop variables in batch scripting for some time and never ever had a problem which can be associated with their use which I realize is undocumented.   Can you provide an example of a numeric For loop variable which causes a problem in a batch script please, typos excluded?

Thanks. Code: [Select]for /f "delims=" %%1 in ("%testfile%") do set filenam=%%~n1


Salmon

I tried the following from the DOS prompt.. (after setting testfile=sp.cmd)

for /f "delims=" %a in ("%testfile%") do echo %a~n1   
which returned:
sp.cmd~n1

so i tried this:
for /f "delims=." %a in ("%testfile%") do echo %a~n1 
which returned:
sp~n1

so i tried this:
for /f "delims=." %a in ("%testfile%") do echo %a:~n1
which returned:
sp:~n1

what am i doing wrong? Quote from: skorpio07 on December 13, 2011, 07:44:23 AM
what am i doing wrong?
Your syntax is off, and it SEEMS you are misinterpreting how the for statement is working. For a quick explanation, your %a is the token that you are setting so the ~n1 is not actually doing anything. If you are looking to grab the name of a file (which is what I am assuming you are wanting using the ~n parsing syntax) then that needs to be set before the variable. Example: for variable %a, to grab the name you would need to use %~na. This is why the help text suggests to use capital letters, as it helps to distinguish parsing syntax from the variable. I.e. %~nA for a %A variable.

For what you are trying to accomplish, using the for "delims=." %a in ("%testfile%") do echo %a should get you what you are looking for. The only issue you would end up running into is there is a "." in the file name. If you are looking to grab the name of the file however, you can also try using for /f "delims=" %a in ("%testfile%") do echo %~na and you should end up with identical results, only this one should ALLOW for additional "."s to be in the filename. Remember that when using these in a batch file, you need to double up the percent signs. %a=%%a and so forth.

Squashman, T.C.'s method of using ASCII 33-254 will work in most applications. What I have found the most annoying part about all of it is trying to figure out which ASCII character comes next, which is why I continue to use the letter variables. I still remember my alphabet from school most days. thanks raven
 
i should have posted that i had already gotten the right solution (there is obviously more than one) with this:
 
for /f "tokens=1 delims=." %%a in ("%testfile%") do (set temptst=%%a)     --running inside a batch file--
 
but nice to know that this works as well:
 
for /f "delims=." %%a in ("%testfile%") do (set temptst=%%a)
 
and
 
for /f "delims=" %%a in ("%testfile%") do (set tempst=%%~na)
 
and im sure there are other ways as well, my response to salmon was that i was trying addtional ways of getting the filename so i tried his method to see if it would work (my syntax was off, i got it now!)
 
and thanks again to TC, i now know better how to extract tokens...and on that note, one question with regards to tokens:
what is the difference between:
tokens=1-5 and tokens=0,2  (the question is what is the difference between the dash and the comma)
 
where would i find the microsoft answer to that as well.
 
thanks again
 
 
 
  Quote from: skorpio07 on December 13, 2011, 10:30:59 AM
what is the difference between:
tokens=1-5 and tokens=0,2  (the question is what is the difference between the dash and the comma)

You can't have a token 0 (zero), they start at 1 (the first).

The difference is that "tokens 1-5" selects tokens 1 to 5 and "tokens=1,5" selects  tokens 1 and 5.

I can think of at least 4 ways to get familar with how they work:

(1) Study the FOR documentation which you can see by opening a command window and typing FOR /? at the prompt. Most commands have help you can see by this method.

(2) Study the Microsoft Command-Line Reference A=Z at

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

(3) Just Google for stuff about batch command syntax, there are zillions of pages out there.

(4) Most fun, I think, and a good idea in many ways, do some experiments at the command prompt. You won't break your computer as long as you don't FOOL around with DEL where you have precious files.

Remember that you use one percent sign at the prompt where you would use two in a batch script, so (for example) you would use %A %B etc at the prompt and %%A %%B etc in a batch file.

You may as well precede the echo command with an symbol to avoid seeing it on the screen.

Code: [Select]
C:\>for /f "tokens=1-5" %A in ("ant bee cat dog egg fire goes hat ink jet kit") do echo %A %B
ant bee

C:\>for /f "tokens=1,5" %A in ("ant bee cat dog egg fire goes hat ink jet kit") do echo %A %B
ant egg

C:\>for /f "tokens=1,2,6-7" %A in ("ant bee cat dog egg fire goes hat ink jet kit") do echo %A %B %C %D
ant bee fire goes

C:\>for /f "tokens=1,2,6,8-9" %A in ("ant bee cat dog egg fire goes hat ink jet kit") do echo %A %B %C %D %E
ant bee fire hat ink

C:\>for /f "tokens=1,9 delims=," %A in ("ant,bee,cat,dog,egg,fire,goes,hat,ink,jet,kit") do echo %A %B
ant ink

C:\>for /f "tokens=11 delims=," %A in ("ant,bee,cat,dog,egg,fire,goes,hat,ink,jet,kit") do echo %A
kit






Salmon Trout's way is by far the most bullet proof.  If someone puts a period in their file name besides the extension then you are going to start getting undesirable results.

So if your file name is My.File.Name.txt, you are not going to get what you want for your output if you are using the delimiters option.  By using the MODIFIERS like Salmon Trout did, you will always get the extension removed from the end.

I do realize that you can use a number in a FOR LOOP but it is just really bad habit to get into.  Just like Salmon Trout warns us for using Double Colons for comments.  That too is probably bad coding practice and I am guilty of it but I just like the way it looks.  When you write batch files  that are hundreds of lines long that use command line input and are calling out to other batch files and other labels you can easily get Mixed up on When you are suppose to be using %%1 versus %1 in your coding.  Over the years I can't recall a programming language that used numbers as the FOR Loop variable.  My experience is limited to Fortran, Pascal, Basic and shell scripting like BASH, Power Shell and Batch. 

Just my two cents.many thanks squashman,
 
yes, i agree that upon consideration, ST's method is better, as i won't know for sure that there is only 1 period in the filename.
 
and i don't use ::, just rem's
 

 I see that Salmon Trout already beat me too it, but here is what I was working on while he was quicker on the DRAW this time.

The tokens within a for statement are not well explained in the help text. I too had some questions on them and CH helped steer me in the right direction, so hopefully I can utilize what I was taught and pass it along.

The particular statements within the quotes in the for command help to determine how the input is parsed and assigned. The best way to see this would be to use some examples. For all of these examples, we are going to have a variable called testset.

Code: [Select]set testset=one two three four five six seven
Now you already know that the delims= statement allows you to set what the delimiters are. The default delimiters are the space and carriage returns. So for the following for statement, the additional text would be what variables are equal to.

Code: [Select]for /f %a in ("%testset%") do (
  echo %A = %a
  echo %B = %b
  echo %C = %c
  echo %D = %d
  echo %E = %e
  echo %F = %f
  echo %G = %g
)

>%A = one
>%B = two
>%C = three
>%D = four
>%E = five
>%F = six
>%G = seven
The %a in this case is the explicit token, the one that you explicitly define. The tokens that follow it are the implicit tokens that the for command implicitly defines and assigns. Nothing groudbreaking yet, but we need some ground work to break. With "tokens=", you are able to define which "tokens" are actually assigned data. It gets a little hard to explain, but perhaps is easier to show.

Code: [Select]for /f "tokens=1,2" %a in ("%testset%") do echo %a %b

>one two
To specifically answer your question, the comma seperates the tokens while the dash signifies a range. Try to follow how this next one works.

Code: [Select]for /f "tokens=2,4-6" %a in ("%testset%") do echo %a %b %c %d

>two four five six
Because in this setup, the first delimited token (one) is not designated as assignable, it is discarded and the second delimited token (two) which is designated as assignable is assigned to the first (explicit) token. In this construct, it's easier to think of two different sets of tokens being used (I wish I was creative enough right now to think of a different name to use for them, but I'm not.)

The only other caveat to add is the addition of the "*" at the end of the tokens statement. Using tokens=1* in the second code (for /f "tokens=1,2" %a in ("%testset%") do echo %a %b) will actually give you the output of one two three four five six seven because it takes the first delimited token and assigns it to %a, but the "*" tells it to take the rest of the line and assign it to %b.

Please let us know if you have any other questions on the for statement, and I'll try to locate the post that taught me about all of this. Quote from: Raven19528 on December 13, 2011, 12:08:16 PM
The default delimiters are the space and carriage returns.
From the help file.
Code: [Select]delims=xxx      - specifies a delimiter set.  This replaces the
                  default delimiter set of space and tab.Many many thanks for this education, you hit the nail on the head with the explanation. precisely what i was looking for with respect to tokens. and yes if you have that link, i will go and further my knowledgebase.
 
Quote from: Raven19528 on December 13, 2011, 12:08:16 PM
I see that Salmon Trout already beat me too it, but here is what I was working on while he was quicker on the draw this time.

The tokens within a for statement are not well explained in the help text. I too had some questions on them and CH helped steer me in the right direction, so hopefully I can utilize what I was taught and pass it along.

The only other caveat to add is the addition of the "*" at the end of the tokens statement. Using tokens=1* in the second code (for /f "tokens=1*" %a in ("%testset%") do echo %a %b) will actually give you the output of one two three four five six seven because it takes the first delimited token and assigns it to %a, but the "*" tells it to take the rest of the line and assign it to %b.

Please let us know if you have any other questions on the for statement, and I'll try to locate the post that taught me about all of this.
679.

Solve : how do i modify a windows 7 firewall????

Answer»

i would LIKE to make my own windows firewall but i would like to USE my EXISTING forewall program. please help
You cant, Windows firewall is not open source, but you can change the settings.

http://www.techtalkz.com/windows-7/515977-how-configure-windows-firewall-windows-7-a.html

680.

Solve : rename files ??

Answer»

I am trying this

for /l %%v in (1,1,59) do rename Track0%%v.mp3 - 7arab.com.mp3 Track0%%v.mp3

why does it SAY "The syntax of the command is incorrect" ?you need to put quotes around filenames that hold spaces :
Code: [SELECT]for /l %%v in (1,1,59) do rename "Track0%%v.mp3 - 7arab.com.mp3" "Track0%%v.mp3"
It worked...but the other problem is with special characters like "éàçè" when I am trying to CREATE a BATCH file...which EDITOR do i have to use to save it correctly ?any that can handle unicode, even Notepad will doIf memory serves me from a recent thread on another forum I post on, you may get undesirable results if you save your batch file as a unicode text file and try to run it.

681.

Solve : Add Domain users to multiple machines / Read info from text file?

Answer»

I am using the batch file below, to add 30 domain USERS to the administrators
group of 30 machines. I would really like it though if I could make the batch
file read from a text file that will list the domain user names and the machine
names, instead of having to add these names in the batch file manually.

Help?

Thanks

set machineuser=
set machinepass=
set domainfull=
set domainsmall=

set domainuser001=
set domainuser002=
set domainuser003=
set domainuser004=
set domainuser005=
set domainuser006=
set domainuser007=
set domainuser008=
set domainuser009=
set domainuser010=
set domainuser011=
set domainuser012=
set domainuser013=
set domainuser014=
set domainuser015=
set domainuser016=
set domainuser017=
set domainuser018=
set domainuser019=
set domainuser020=
set domainuser021=
set domainuser022=
set domainuser023=
set domainuser024=
set domainuser025=
set domainuser026=
set domainuser027=
set domainuser028=
set domainuser029=
set domainuser030=

set machinename001=
set machinename002=
set machinename003=
set machinename004=
set machinename005=
set machinename006=
set machinename007=
set machinename008=
set machinename009=
set machinename010=
set machinename011=
set machinename012=
set machinename013=
set machinename014=
set machinename015=
set machinename016=
set machinename017=
set machinename018=
set machinename019=
set machinename020=
set machinename021=
set machinename022=
set machinename023=
set machinename024=
set machinename025=
set machinename026=
set machinename027=
set machinename028=
set machinename029=
set machinename030=

psexec \\%machinename001%.%domainfull% -u %machineuser% -P %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser001%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser002%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser003%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser004%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser005%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser006%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser007%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser008%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser009%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser010%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser011%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser012%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser013%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser014%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser015%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser016%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser017%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser018%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser019%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser020%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser021%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser022%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser023%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser024%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser025%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser026%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser027%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser028%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser029%" /add
psexec \\%machinename001%.%domainfull% -u %machineuser% -p %machinepass% net
localgroup Administrators "%domainsmall%\%domainuser030%" /add
pause
Make two text FILES.  One with the Machine Name and one with the User Names.  Then you can use nested FOR LOOPS to parse the Machine Name Text file and User name text file.
Code: [Select]set machineuser=
set machinepass=
set domainfull=
set domainsmall=
FOR /f "TOKENS=*" %%M in (Machines.txt) do (
     FOR /f "tokens=* %%U in (usernames.txt) do (
          psexec \\%%M.%domainfull% -u %machineuser% -p %machinepass% net localgroup Administrators "%domainsmall%\%%U" /add
     )
)
       Thank you! I will try it today!

682.

Solve : if file exists in one folder but not in another folder, delete the file?

Answer»

I need to be able walk thru and read all the files in G:\folderA and all files in subfolders under folderA and determine if the file exists in C:\folderA. If the file cannot be found in G:\folderA, then deleted the file in C:\folderA.

ie
If G:\1-AlsWork\file1.ext exists in C:\AlsWork ?      then next test,  if no, delete the file in G:\1-AlsWork\file1.ext
then move to the next file in G:\1-AlsWork and do the same test ...

also
If G:\1-AlsWork\subfolder1\somefile.ext exists in C:\AlsWork\subfolder1    then next test, if no, delete the file in G:\1-AlsWork\subfolder1\somefile.ext

Hope this explaination is clear ENOUGH for you to understand

Thanks in advance
cyberal Quote from: cyberal on December 22, 2011, 12:24:00 PM

I need to be able walk thru and read all the files in G:\folderA and all files in subfolders under folderA and determine if the file exists in C:\folderA. If the file cannot be found in G:\folderA, then deleted the file in C:\folderA.
I think you got that LAST sentence backwards.
If the file cannot be found in C:\folderA, then delete the file in G:\folderA.You are absolutely correct. My bad.
CyberalEasy enough to do with a Batch file.  Leaving work now.  Might get back online later tonight.Squashman,
No problem at all. I'll check later or tomorrow.
Thanks
CyberalThis turns out to be a simple one liner.
Code: [Select]FOR /R "G:\FolderA\" %%I in (*) DO IF NOT EXIST "C:%%~pnxI" DEL "%%~I"Squashman
Wow, this worked perfectly! Thanks so much.
Another quick question
I thought you could do multiple actions as long as you begin with '(' and end with ')'.  As shown below ....
Am I out in left field on this? I am on Windows 7 if that MAKES a difference

FOR /R "G:\testBUdir\" %%I in (*) DO (
IF NOT EXIST "C:%%~pnxI"
del %%~I
echo c:\%%~pnxI has been deleted
echo something again
)

Quote from: cyberal on December 23, 2011, 10:01:46 AM
Am I out in left field on this?

No, you are absolutely correct. You just need to make sure of your parentheses construction and that it follows all the proper syntax. For instance, what you have shown here will not work, because you did not "open" the IF NOT EXIST statement. It should be as follows:

Code: [Select]FOR /R "G:\testBUdir\" %%I in (*) DO (
  IF NOT EXIST "C:%%~pnxI" (
    del %%~I
    echo c:\%%~pnxI has been deleted
    echo something again
  )
)
I use the spacing for my own sanity, as it allows me to see exactly which parentheses CONSTRUCTS are being opened and closed, but you can use different or no spacing if you like.  
Works perfectly now!
Thanks for all your help and have a great holiday
cyberalYou are deleting from the G: DRIVE not from the C: drive so your echo statement should just be.
echo %%I has been deleted Quote from: Raven19528 on December 23, 2011, 10:38:04 AM
I use the spacing for my own sanity, as it allows me to see exactly which parentheses constructs are being opened and closed, but you can use different or no spacing if you like.
Same here but I like to use TABS.Truely appreciate all the help !
Thanks again and have a great holiday .... 
cyberal
683.

Solve : Mysterious Batch Error?

Answer»

I'm working on a batch file game (a sort of quiz).
The way it works is that there is a file called FACTS.txt which contains each item in the quiz in 6-line "blocks." Each "block" uses the following STRUCTURE:

  • Question
  • Choice a
  • Choice b
  • Choice c
  • Answer
  • Explanation

What I'm doing at the moment is the part that reads the first four lines of the file.
I'm using 'functions' (info at HTTP://ss64.com/nt/syntax-functions.html) and I have a function to read the first four lines. Here it is:
Code: [Select]:getquestion
setlocal EnableDelayedExpansion>>OUTPUT.txt
setlocal>>OUTPUT.txt
set number=%1%>>OUTPUT.txt
set /a startline=%number%*6>>OUTPUT.txt
set /a endline=%startline%+3>>OUTPUT.txt
set i=%startline%>>OUTPUT.txt
for /f "eol=¬" "skip=%startline%" %%a (FACTS.txt) DO (
set /a i+=1>>OUTPUT.txt>>OUTPUT.txt
echo %%a>>OUTPUT.txt
if %i%==%endline% do endlocal>>OUTPUT.txt
goto eof>>OUTPUT.txt
)
endlocal>>OUTPUT.txt
setlocal DisableDelayedExpansion>>OUTPUT.txt
goto :eof>>OUTPUT.txt
As you can see, I've been trying to figure out what the problem is by putting >>OUTPUT.txt at the end of each line to try to figure out what the problem is.
I run the batch, but the moment that function is called, it just closes.
I look in OUTPUT.txt. Nothing at all.

Can anybody track down the problem?

By the way, the line of code that calls the function is:
Code: [Select]call :getquestion %level%>>OUTPUT.txtYou would be better off having each question in your FACTS.txt file on a single line.  A heck of a lot easier to parse with a batch file that way.

Question, Choice A, Choice B, Choice C, Answer, Explanation.


Why do you have that GOTO EOF in your FOR LOOP.  That will immediately break the FOR LOOP after it parse the first line of the FACTS.txt file.  I believe the line should be GOTO :EOFIs the variable NUMBER the Question Number you are trying to pull from the Fact.txt file.  If so, your math logic is screwed up with that.  If you are passing the question number to the function you would need to multiply and then subtract to get the first line of the question.

Question 2 should be lines 7 to 12 of your text file.  But using your logic the startline would be 12 and the endline would be 15.
So to get your startline you should be doing this:
set /a startline=(%number%*6)-5In this line, where is the value of %1% coming from?
Quote
set number=%1%>>OUTPUT.txt
Quote from: Salmon TROUT on December 22, 2011, 10:01:22 AM
In this line, where is the value of %1% coming from?
I am assuming he is not showing us the entire batch file.  I am just assuming he is calling the function above and passing the question number with the CALL.Just remember that assuming makes an *censored* out of u and some guy named MING... Quote from: Squashman on December 22, 2011, 10:03:32 AM
I am just assuming he is calling the function above and passing the question number with the CALL.

If that is so, maybe he thinks that %1% is going to hold the passed parameter?

Quote from: BC_Programmer on December 22, 2011, 10:12:43 AM
Just remember that assuming makes an *censored* out of u and some guy named Ming...

I know that guy...he was in my Darts League...Ok. I suggest making a new output.txt file.




684.

Solve : Long Delays ... SLEEP or Better Method??

Answer»

I was wondering if SLEEP is the best method for a 10 minute delay or if there is anything else out there that works better for longer than what sleep was really created for delays in batch files for say 10, 15, 30 minutes etc?

I have a batch that executes 6 processes using START for each process to execute. On step 3 I have to wait 10 minutes for the program in Step 2 to be at the correct rested state to take step 4's process. If Step 4 executes too soon, it will likely corrupt the SQL database in Step 2 for our Cheftec Software.

I cant think of any other fix to this other than CREATING a LONG delay so that I am 99.9% confident that Step 2 is done and resting, so that I can process the additional batched SQL instructions.

All suggestions welcome. Just thinking that there might be a better means than using SLEEP which I think was designed for shorter delays like 30 sec etc.Well, Windows Vista and Above have the TIMEOUT command but you also need to understand two others things about batch.

Batch files do sequential processing.  That means it does not move onto the next command until the previous command has COMPLETED.   The only exception to that is if you launch another process with the START command.  But if you use the START command you can also use the WAIT switch to keep it from moving on to the next process until the current one has completed.  You also don't need to use the START command at all to launch another process. 

So here are some batch file examples:

If I want to launch Notepad and then launch calculator after notepad is closed, I could do two ways.

If you put this code into a batch file, Calculator will not launch until Notepad has closed.
Code: [Select]"%windir%\system32\notepad.exe"
"%windir%\system32\calc.exe"You can also do it like this as well.
Code: [Select]start "" /wait "%windir%\system32\notepad.exe"
start "" /wait "%windir%\system32\calc.exe"Same affect just DIFFERENT code.  The next process will not start until the previous process has completed. Quote from: nixie on DECEMBER 23, 2011, 09:46:11 AM

I was wondering if SLEEP is the best method for a 10 minute delay or if there is anything else out there that works better for longer than what sleep was really created for delays in batch files for say 10, 15, 30 minutes etc?

Why do you think that whichever version of sleep.exe you have was "created for" certain lengths of delay? It waits for the number of milliseconds or seconds (according to version) that you tell it to wait. It doesn't care if it is 30 seconds or 300 or 3000.
685.

Solve : FFmpeg converting to flv but with 0 file size?

Answer»

I'm having problems regarding conversion of video to FLV format. Below is my command

for conversion, but it seems to CONVERT the video to flv but the FILE size remains 0

KB, what could be the problem, please suggest.

My command:

$command =$ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . "

-f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path

. " -U stdin " . $destFile;

Please Help me ASAP. It's urgent

Thanks in advance

Regards
HemYou'll (possibly) get a quicker response if you post this in a different forum.. This is the Web Design forum.I'm disabling your other account and deleting all of the DUPLICATE posts. Please stay with one account and one post per problem. I'm also moving this to a more appropriate forum. Thank YO

686.

Solve : Ghost Floppy Batch Formula Needed?

Answer»
                                                     December 31, 2011

Dear Forum,

   First, Happy New Year to y'all!!!!!

   What I need help on is a batch file that I can put on a floppy that can

execute a Ghost.exe DOS file that is on the G:\ Drive.

   A little background:

1. I've been using Ghost since version 5 back in 1995.

2. I've always used a Ghost boot floppy with an Autoexec.bat file

to do my bidding.

3. When Ghost 2003 came out, I could not use it with an Autoexec.bat

file because  I did not want to "Mark" my HDD, just too "Big Brotherish"

for me.

4. I then got a hold of Ghost Corporate v7.5 and THAT worked great with

my Ghost floppy sets to:

Make to HDD
Make to CD
Make to HDD And CD
CRC Check HDD Image
CRC Check CD Image
Restore From HDD
Restore From CD

   Whatever I wanted to do, I just popped in the appropriate floppy and

turned my computer on and Ghost did its thing.

   The above worked with my Windows 98SE box, but my new Windows 7

box doesn't "play nice" with Ghost Corporate v7.5 but is OK with

Ghost v11.5.  BUT, v11.5 is 2262 KB's so I'm FORCED to go the

"Bootable CD" or "Bootable USB" Thumb Drive route.

I just want to keep it via floppies!

   This is how I'm presently set up on my 98SE box for making

an image file of C:, putting it on my HDD and then CRC checking the

image:


echo off
GhostCE.exe -clone,mode=pdump,src=1:1,dst=G:\01_Ghost\Newest.gho -z3 -fx -sure
GhostCE.exe -chkimg,G:\01_Ghost\Newest.gho -sure


   Soooo, what I want to do is put the Ghost v11.5 DOS exe in

a folder on the  G:\ Drive and have the boot floppy run an Autoexec.bat

file to go to it and do what I want it to do, be it Make to HDD or CRC

Check CD Image, etc...

   The folder I made is G:\!-Ghost and I named the Ghost file

Ghost115.exe.

   Can anyone come up with a batch file to give me joy?

   Thanks in advance.


Bug_zsSolved!!!
Trial and error got me the answer that worked perfectly on my

Windows 7 box from a boot floppy:

echo off
G:
CD \!-Ghost
Autoexec.batSpoke too soon.  For some reason I now GET the proverbial "Bad command or file name".

I even tried going with...

echo off
G:
CD \!-Ghost
Ghost115.exe

NO joy!

HELP!!!!!!

Bug_zsWhen you boot with the floppy to a DOS prompt, is the G: drive visible? And is the !-Ghost folder visible? And the Ghost115.exe file?
Try this:

Code: [Select]echo off
cd /d G:\^!-Ghost (Not sure if the cd /d will work, I recall something about limiting the use of switches in boot sequences)
Ghost115.exe

The ^ "escapes" the "!" and makes it so the batch program SEES it as a character instead of the start of a variable, which is what it is currently seeing and likely the reason you get the "Bad command or file name". The cd /d will work in cmd prompt in Windows, but I am uncertain of it's availability with the process you are describing. If it does not work, you original two line approach should still work for it.

For future reference, it is usually a good idea to limit special character usage in folder names you are wanting to use batch files with and on and in.I have no idea why he gave his directories names using non-standard characters...his batch may work but he's asking it to do something it will not.
Ghost recognises all command functions ...always has...but not if there written outside the lines.
Also curios is why there are no Path statements or variables... Quote from: Raven19528 on January 04, 2012, 11:35:56 AM
The ^ "escapes" the "!" and makes it so the batch program sees it as a character instead of the start of a variable, which is what it is currently seeing and likely the reason you get the "Bad command or file name".

It can't see it as the start of a variable. MS-DOS does not use ! as a variable delimiter. He mentions autoexec.bat, which means he is using real MS-DOS, not Windows NT family cmd (often wrongly and confusingly called "DOS"). !-GHOST is a legal folder name in MS-DOS.

Quote
The cd /d will work in cmd prompt in Windows

It won't work in MS-DOS, whose version of the CD command lacks the /D switch.




Quote from: Salmon Trout on January 04, 2012, 11:58:10 AM
It can't see it as the start of a variable. MS-DOS does not use ! as a variable delimiter. He mentions autoexec.bat, which means he is using real MS-DOS, not Windows NT family cmd (often wrongly and confusingly called "DOS"). !-GHOST is a legal folder name in MS-DOS.
Yeah I know there are a lot of differences between DOS and cmd, I just have no idea what all of the differences are. Perhaps then the reason he is getting the bad command error message is due to the fact that he has the "\" preceding the folder he is searching for. Though I do believe patio's question about the lack of path statements and variables should also be addressed prior to troubleshooting. No sense in troubleshooting a product that won't do what he wants when it is working properly. Quote from: Raven19528 on January 04, 2012, 12:08:38 PM
Perhaps then the reason he is getting the bad command error message is due to the fact that he has the "\" preceding the folder he is searching for.

That should work just fine.







I wonder if MS-DOS can even see the G: partition.
Quote from: Salmon Trout on January 04, 2012, 12:35:58 PM
I wonder if MS-DOS can even see the G: partition.

That may be the issue. I wonder if the G: is being mounted prior to this running. The OP may need to put mount.exe on the boot disk and mount the G: drive prior to running this particular command sequence in the batch file. Quote from: Raven19528 on January 04, 2012, 12:53:53 PM
That may be the issue. I wonder if the G: is being mounted prior to this running. The OP may need to put mount.exe on the boot disk and mount the G: drive prior to running this particular command sequence in the batch file.

It might be an NTFS partition, or a non-AHCI SATA drive.
I suspect G: is an optical drive...which means his batch isn't even close to working...                                                     January 4, 2012

Dear Forum,

   First, thank you for your extensive replies.

A bit of background and mini-update...

1 TB HDD with the following

C: 75 Gigs NTFS   Windows 7 64 Bit

D: 25 Gigs NTFS   Program Files

E: 15 Gigs NTFS

F: 600 Gigs Fat32

G: 30 Gigs Fat32  Ghost Images

H: to M: various sizes all Fat32.

Z: is my DVD Burner (1st thing I always do on an install is set CD\DVD to Z)

   I built a "Standard Ghost Bootable CD/DVD--on Steroids" from NightOwl

at the Radified Ghost board:

http://nightowl.radified.com/bootcd/bootcdintro.html

   I added the ahci.sys file, for Ghost to see SATA CD\DVD DRIVES from:

http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=us&prodTypeId=12454&prodSeriesId=1844973&swItem=wk-61401-1&prodNameId=1844975&swEnvOID=2096&swLang=13&taskId=135&mode=4&idx=0

and added this line in the config.sys file:

device=ahci.sys /d:nightowl

   I added an Autoexec. bat file with this in it:


echo off
Ghost115.exe -clone,mode=pdump,src=1:1,dst=1:5\01_Ghost\Newest.gho -z3 -fx -sure
Ghost115.exe -chkimg,1:5\01_Ghost\Newest.gho -sure

and booting from the DVD in the BIOS, Ghost made an image of my C: drive, CRC checked

(or Verified) it and put it into my G:'s 01_Ghost folder.

   So, at least half of the problem is solved, but getting a FLOPPY to trigger

the "MakeHDD.bat" is still in need of solving.

   Tried:

echo off
CD /D G:\^!-Ghost
Ghost115.exe

Got "Bad command or file name"


>It might be an NTFS partition, or a non-AHCI SATA drive.

As you can see from above, G: is Fat32 and my SATA is set to AHCI


>I suspect G: is an optical drive

As you can see from above, Z is my DVD burner


Bug_zsPossibly the OP thinks that drive letters which are assigned in Windows are known about, and used by, MS-DOS booted from a floppy disk?
Again, I'll suggest that you do a little research and take a look at mount.exe. This is going to be needed if you are wanting to designate drive letters on an empty HD.

For Vista and 7, mountvol.exe was introduced. You can take a look at some of the documentation on it here. It is very similar to mount.exe, so take your pick as to which you would like to use, though mountvol does provide some additional functionality.

Utilize either of these utilities to mount the drives that you are referencing later in your boot process. You will need to conduct the research to find what some standard mount points are on HDDs. Also, as a REMINDER, the command prompt that you are using on your Win 7 is very different from the MS-DOS that is being run during an OS install. Keep this in mind as you continue this adventure.
687.

Solve : Extract first letter from file names, and move files in to folder...?

Answer»

Hello all.

First of all, I wish you all a great 2012!

Second, my question / problem:

I have ~1500 text files CONTAINING lyrics, and they're ORGANISED in folders following the artist name. E.g.: \Rush\Rush - Tom Sawyer.txt


I want to re-organise the files, so that they match the same scheme used by Evil Lyrics, which is by artist's first letter: \R\Rush - Tom Sawyer.txt.

So, what I need to do is:

  • Extract the first letter of the file name
  • Move the file to a path which consists of a base-path + first letter

To extract the first letter of a variable is pretty simple:

Code: [Select]set str=1234
set str=%str:~0,1%
echo %str%

In the example above, first str is set to "1234", and then set to the first character, resulting in "1".

So I thought I could use the above technique and the FOR command. However, I just can't extract the first letter from file names within the FOR command.

For instance, in the code below I attempt to, for each TXT file in the folder:

  • reduce the file to just the file name (by using %%~n to remove the path)
  • set variable STR with the file name
  • echo the reduced file name
  • echo the variable

Code: [Select]cls
echo off
set /p str=""

for %%f in (*.txt) DO (

set str=%%~nf
echo this is the filename: %%~nf
echo this is the variable: %str%
pause

)

exit


But what actually happens is that the result of line (3) is OK, changing for each file, while variable STR echoed in line (4) remains fixed with a value that was set at some point.

My conclusion is that variable STR never is set with the file name. Or maybe it is, but only once.

I looked in to expanding the variable by using "!" (e.g.: !str!), but I couldn't get that to work.


Once I do get to assign the file name to a variable, then I can extract the first letter (as DESCRIBED, with %str:~0,1%) and proceed with my plan.

Any ideas on how I can achieve my objectives, and why I can't set the variable with a file name?

Thanks a lot,

Michael

You need to enable delayed expansion. This allows you to use the exclamations around your variable names.
echo off & setlocal enabledelayedexpansion Quote from: Squashman on December 31, 2011, 11:46:16 PM
You need to enable delayed expansion. This allows you to use the exclamations around your variable names.
echo off & setlocal enabledelayedexpansion

A-ha.... SOMETHING NEW I learned. I wasn't aware that it had to be explicitly enabled.

I'm not home right now but will work on this ASAP.

Thanks again,

Michael
688.

Solve : Batch file to copy & paste text?

Answer»

Hello All,

In the process of learning on how to create batch files. I'm trying to figure out on how to copy from the blank space to the end of the row, then replace it with a 2 at the end of the LINE. The FIRST line is what I currently have but trying to get to the end result of the 2nd line. I HOPE this is detail enough to get some help on this issue.

 99940                                            E1          -0001.30                                                           
 99940                                            E1          -0001.30                                                           2

All the help is very much appreciated.

Thanks
meveNot sure what you want here.
I need the batch file to copy from the 0 to the end of the 1st line
then paste that same line but put the 2 at the end of that same line.

The biggest thing is I need to have a 2 at the end of line 1. Quote from: matteve on December 30, 2011, 11:59:31 AM

I need the batch file to copy from the 0 to the end of the 1st line

What 0? I can see five zeroes.

The second line is the same as the first line except there are a bunch of spaces and then a 2.

What do you mean "paste" it?

99940                                            E1          -0001.30                                                           # to
99940                                            E1          -0001.30                                                           2

right now I need a batch file to input the # 2 the very last position on this line.

so, this is what the line is right now
 99940                                            E1          -0001.30                                                           

I need to have the 2 to be put the very end of that line, so the line will look like
99940                                            E1          -0001.30999999999999999999999999999992

my thought process was, copy the position after the last 0 to the end of the line.
then paste the spaces to where the 9's are with the 2 the very end.

i'm sorry for confusing everyone on this.. :-(that will not work the way that i want it to.

I have the lines that I'm looking for but I need to have the 2 in position #118 in the text file.

in the posting above, it's creating additional spaces and that will not be in the proper format.

any idea's on how I can insert the 2 in position #118 of a text file ?What are all those 9s for?

Anyhow, the short answer is that you can't directly insert a character into a text file using a simple script. What you can do is read in the original text file, and add the new character to the end of each line, and write the lines out to a new file, which you can then rename to replace the original file.

Anyhow, I wouldn't use batch for this, I'd use Visual Basic Script.


Quote from: Salmon Trout on December 30, 2011, 12:40:49 PM
Anyhow, I wouldn't use batch for this, I'd use Visual Basic Script.

I can post a script if you want.
Well it would be easy enough to remove the existing spaces at the end of the line and then repad the line with a bunch of spaces and substring that variable to a length of 117 and then put the number at the end. Quote from: Squashman on December 31, 2011, 07:13:21 AM
Well it would be easy enough to remove the existing spaces at the end of the line and then repad the line with a bunch of spaces and substring that variable to a length of 117 and then put the number at the end.

As posted, each line has TRAILING spaces. I don't know if they exist in the files the OP wishes to process? OP please clarify. If trailing spaces need removing prior to processing, the rtrim function can be used.

Also I noted that some of the example lines posted above have one leading space, and some do not.

And a hash/pound sign seems to have crept in at position 118. Again, OP please clarify.

And all those 9s have not been explained.

Anyhow a simple VBScript like the one below should do the needful.

Code: [Select]Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ReadFile  = objFSO.OpenTextFile   ("input.txt",  ForReading)
Set Writefile = objFSO.CreateTextFile ("output.txt", ForWriting)
Do While Not ReadFile.AtEndOfStream
    ReadLine  = Readfile.readline
    WriteLine = ReadLine & Space(117 - LEN(ReadLine)) & "2"
    wscript.echo "Read line:  " & ReadLine
    wscript.echo "Write line: " & WriteLine
    Writefile.writeline WriteLine
Loop
Readfile.Close
Writefile.Close

689.

Solve : make multiple folders with files from a list file?

Answer»

I have a text file exported from the movie collectorz program and I want to add my DVD collection to xbmc through stub files. I found this code and modified it to give me the files.


Code: [Select]for /f "tokens=*" %%l in (aaa.txt) do echo %%l > "%%l.dvd.DISC"
 now I'm realizing I want to create a directory named from the list and place the created file into that directory. also I want to add the xml into the file -

Code: [Select]<discstub>
  <message>%moviename% is located in the DVD rack</message>
</discstub>




where "moviename" is taken from the aaa.txt file this is way beyond my tiny brains ability so I need help....LMAO

the text file looks like this...

The Adjustment Bureau (2010)
Alien (1979)
Aliens (1986)
Alien³ (1992)
Alien:_Resurrection (1997)
Alien Vs. Predator (2004)
Aliens Vs Predator - Requiem (2007)
Apollo 18 (2011)
Avatar (Extended_Cut) (2010)
Back To The Future (1985)
Back To The Future II (1989)
Back To The Future III (1990)


and I want to end up with...


a Dir named "The Adjustment Bureau (2010)" with a file named "The Adjustment Bureau (2010).DVD.Disc" in it and the file to contain the xml code from above with "The Adjustment Bureau (2010)" as the moviename.


I have spent hours trying different things and all have failed (and failed well I might add...LOL) I have almost 3,000 DVDS and would hate to have to do this by hand. and I'm sure others could use something similar

is a bat file the best thing to use? would vbs be better? anyone know of a program that will do this? any help or thoughts welcome.Hi Bill...OK I got a working set of scripts. the first one makes the files and the second one creates a folder from the filename and moves the file into it.

Im running into one problem, some of the movies contain an ":" which screws that filename up. I've tried putting a ^ in front of the colon in the text file but this don't help. is there a way to replace it or parse it or clean it in the script?If you are not using the Script that was provided to you on the other forum (DosTips.com) you posted this question on please post the code you are using.

ThanksA colon is not allowed in the name of a file or folder on Windows.  So whether or not a batch file can read it, for this purpose it's irrelevant.  You'll need to think of different names! Quote from: Squashman on January 04, 2012, 09:20:02 AM

If you are not using the Script that was provided to you on the other forum (DosTips.com) you posted this question on please post the code you are using.

Thanks


Ok it's complicated just because I was in charge of it.... this is my test text file I PUT a bunch of goofy stuff in it to see if it would fly. everything but the colon goes through. I only make the files with a .dvd extension here cause it was messing me up to have both EXTENSIONS (dvd.disc)


Code: [Select](500) Days Of Summer!;2009
6th Day, The;2000
10,000 Bc;2008
11:14;2005
2010: The Year We Make Contact;1984
Brüno;2009
Disney Surf's Up;2007
Dolan's & Cadillac;2009

This script takes the names and outputs the files into a subfolder named files.... this is the 30th or 50th thing I tried Im not sure why it works but it does...LOL with the EXCEPTION of the two names with colons.

Code: [Select]set dir=C:\temp\test\files\
set ext=dvd
for /f "tokens=1,2 delims=;" %%a IN (haa.txt) do >"%dir%\%%~a (%%b).%ext%" (
echo.^<discstub^>
echo.^<message^>%%~a is located in the DVD rack^</message^>
echo.^</discstub^>
)

This file is in the files folder it takes the files appends the .disc ext and moves it into the folder it has just created.  Im praying that when I do the whole list of 3000 it don't go bananas

Code: [Select]echo off
for %%a in (*.*) do (
md "%%~na" 2>nul
ren *.dvd *.dvd.disc
move "%%a.disc" "%%~na"
)
pause


I'm sure there are better ways to do this and if I spent my time learning to write code instead of chasing women drinking beer and watching movies I'd have more time to watch movies ...



**edit**
well there are other things that mess it up like the u with two dots above it (WITCH I cant even find on the keyboard..LOL) the ? mark also messes it up and my copy of alien3 the 3 is in subscript that also don't make it through the ringer. but for those three files I can make corrections

I suppose I can just do a search and replace in the text file and get rid of all the miscellaneous crap.


**EDIT** I just ran the file through a search and replace program and removed all the illegal charters so all is good. Quote from: Veltas on January 04, 2012, 09:30:49 AM
A colon is not allowed in the name of a file or folder on Windows.  So whether or not a batch file can read it, for this purpose it's irrelevant.  You'll need to think of different names!

Yeah I understand this fact, I was looking for a way to remove them in the batch file on the fly.
690.

Solve : need help about archiving batch?

Answer»

i have an idea so i wanna ASK is it possible i work with scanning pictures and i archive them in server in folder skenirani and then sub folders with name of media ex: r:/clipping_skenirani/globus or r:/clipping_skenirani/vest  and there are .jpg files i want to archive in r:/bekap but not all pictures inside the media folders . ex: vest got pictures from 2 mount like 01_11_2011_vest.jpg and 01_12_2011_vest.jpg so basically i want to create batch file that will find and move to r:/bekap all the files containing mount  ex: 01_11_2011_vest.jpg but not to move the files with 01_12_2011_vest.jpg and then to zip them in bekap folder bekap.zip. i try this way but something goes wrong it don't search in sub folders

echo off
Set FindStrArgs= /R:\Clipping_Skenirani_Napisi\ ".jpg"
COPY R:\Clipping_Skenirani_Napisi\"*_11_2011_*"  R:\bekap
"C:\Program Files\7-Zip\7z.exe" a -tzip "R:\bekap\lala.zip" "R:\bekap\"
Look at xcopy.can u make this thing work or give example
echo off
Set FindStrArgs= /R:\Clipping_Skenirani_Napisi\ ".jpg"
COPY R:\Clipping_Skenirani_Napisi\BIZNIS\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\DNEVEN_FOKUS\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\DNEVEN_KAPITAL\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\DNEVNIK\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\ereporter\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\FAKTI\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\FOKUS\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\FORUM\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\forum.com.mk\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\GLOBUS\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\idividi.com.mk\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\info.com.mk\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\inpress.com.mk\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\kajgana.com.mk\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\KAPITAL\"*_01_2012_*"  R:\bekap
COPY R:\Clipping_Skenirani_Napisi\kirilica_portal\"*_01_2012_*"  R:\bekap
"C:\Program Files\7-Zip\7z.exe" a -tzip "R:\bekap\lala.zip" "R:\bekap\"

how to avoid all this subfolders COPY R:\Clipping_Skenirani_Napisi\* and how to make it to enter what string to search "*_01_2012_*" Quote from: Squashman on January 02, 2012, 07:03:49 PM

Look at xcopy.

sismis: have you tried this? xcopy /? has ALL the answers you need.i have tried xcopy but still copies all sub directories in the skenirani directory instead only the files. i will continue using my old way using start find files and folder searching the skenirani with paramters *.jpg then select all cut paste in backup and zip them
Quote from: sismis on January 04, 2012, 05:19:05 AM
i have tried xcopy but still copies all sub directories in the skenirani directory instead only the files. i will continue using my old way using start find files and folder searching the skenirani with paramters *.jpg then select all cut paste in backup and zip them

Right. My mistake. You keep doing it that way. Maybe one day you will actually read the basic help given by the /? switch and DISCOVER the /S switch, but until then let's pretend there isn't a way to do this.



ok Quote from: BC_Programmer on January 04, 2012, 05:28:36 AM
Maybe one day you will actually read the basic help given by the /? switch and discover the /S switch, but until then let's pretend there isn't a way to do this.

I wish I had thought of saying that.
Code: [Select]echo off
cd /d r:\Clipping_Skenirani_Napisi

echo Enter Search String
set /p search=?

for /r %%A in (*%search%*) do (copy %%A r:\bekap)

"C:\Program Files\7-Zip\7z.exe" a -tzip "R:\bekap\%search%lala.zip" "R:\bekap\"
It's a shame none of the built-in command-line utilities have the basic ability to copy a folder and file spec and all it's subdirectories and files. Would really be nice if we could change that ENTIRE script to far fewer LINES, if only XCOPY had a switch that could be used to indicate it should copy the files in the folder as well as recursively copy files and subdirectories in each of it's subdirectories. Oh well. I guess it's just another example of the type of low-quality software that microsoft releases. Just like how Word doesn't have basic mail-merge functionality or how Excel can't even do formulas, I tried, I put "5+5" in the formula box and it just says 5+5! That's false advertising right there. No of course I didn't read the manual.

I think the issue was that the OP didn't want any of the subdirectories in the folder being copied to, just a long list of files. Anyway, s/he has the answer they are looking for, in multiple paths of execution, so hopefully we can just call this one solved.

On another note, I can't even get Excel to recognize 1+1. It just keeps saying 1+1. Must be some really dumb people working at Microsoft to not know what 1+1 is. It keeps trying to tell me the "=" goes at the beginning. Every 1st grader knows the "=" goes at the end. Come on, that's just basic.  Quote from: Raven19528 on January 04, 2012, 12:43:46 PM
I think the issue was that the OP didn't want any of the subdirectories in the folder being copied to, just a long list of files.


Xcopy would do exactly what they needed. If used properly. And if it had the fictitious switches, such as /S.
691.

Solve : Batch to add/delete based of *.>users?

Answer»

Can you assisted with commands or examples to get me STARTED? I needed to create a batch file to run based on a list of WINDOWS profile usernames to include the default profile. This batch file will be running in SCCM package.

I will be working on Windows XP and 7 but I may want to separate and create two batch files for each OS to simplify the process.

1.) I need to create the list.
dir c:\users\*.>users.txt
dir c:\”Documents and Settings\*.>users.txt”

2.) Delete a file from all Windows 7 profiles based on the list.

>>C:\Users\%username%\FAVORITES\

3.) Then add a file to all Windows 7 and XP profiles based on the list.
Win7
>>C:\Users\%username%\Favorites
>>C:\Users\%username%\Desktop
WinXP
>>C:\Documents and Settings\%username%\Desktop
>>C:\Documents and Settings\%username%\Favorites

I think this will work regardless of XP or 7.
Code: [Select]echo off
for /f "tokens=*" %%I in ("%USERPROFILE%") do set pPath=%%~dpI
pushd "%pPath%"
for /f "tokens=*" %%A in ('dir /ad /A-S /b') do (
DEL "%%~fA\favorites\somefile.txt"
)
POPDThanks for the post that did it for me! Maybe someone else can use this also.

echo off
:FIND VERSION
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto WindowsXP
ver | findstr /i "6\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto WINDOWS7

:WindowsXP
for /f "tokens=*" %%I in ("%USERPROFILE%") do set pPath=%%~dpI
pushd "%pPath%"

for /f "tokens=*" %%A in ('dir /ad /A-S /b') do (
   )

echo copy to folder...

for /f "tokens=*" %%A in ('dir /ad /A-S /b') do (
   copy "c:\pass\pass_Self-Service-4.7.url" "%%~fA\favorites\"
)

echo copy for desktop
copy "c:\pass\pass_Self-Service-4.7.url" c:\documents and settings\all users\desktop

:Windows7
for /f "tokens=*" %%I in ("%USERPROFILE%") do set pPath=%%~dpI
pushd "%pPath%"

for /f "tokens=*" %%A in ('dir /ad /A-S /b') do (
   DEL "%%~fA\favorites\PB_Sites\PASS Self-Service.url"
)

echo copy to folder...

for /f "tokens=*" %%A in ('dir /ad /A-S /b') do (
   copy "c:\pass\pass_Self-Service-4.7.url" "%%~fA\favorites\PB_Sites\"
)

echo copy for desktop
copy "c:\pass\pass_Self-Service-4.7.url" c:\users\public\desktop

692.

Solve : Create batch for making dirs with spaces?

Answer»

till now I've this
for /F  %%i in (c:\tempdos\klantenlijst.txt) do md %%i

putting the %%i in between "" doesn't work...

SOMEBODY knows how to do this?

klantenlijst.txt
-------------------
jef jansen
paul geerts
mady bogaerts
for /F  "tokens=*" %%i in (c:\tempdos\klantenlijst.txt) do md "%%i"Or Code: [Select]for /F  "delims=" %%i in (c:\tempdos\klantenlijst.txt) do md "%%i"And if you need to understand why it is because by default the data that is passed in a FOR loop is delimited by a SPACE and TAB.  So since your DIRECTORY NAMES have SPACES the loop variable was only being assigned the first token.

693.

Solve : batch string help?

Answer»

So I was trying to do the following:

set /p t=""
if %t%==joe goto num1
if %t%==two WORDS goto num2


But when I would input the text "two words", it would complain about:

words==joe was unexpected at this time

I thought it was a issue with the space of two words, but I cant seem to fix it. any help?The problem ARISES because of the space in "two words". You need to quote the variables and test text like below. In fact it is a good idea to always use quotes. Otherwise for EXAMPLE you would ALSO get an error if you just hit Enter at the set /p line and input an empty string.

if "%t%"=="joe" goto num1
if "%t%"=="two words" goto num2

oooooh!
You got to put quotes around the %t% too!

Ah thats why I was messing up. I tried to make it a string by putting quotes on the "two words" but that DIDNT work Quote from: 036483 on January 08, 2012, 02:21:36 AM

oooooh!
You got to put quotes around the %t% too!

Ah thats why I was messing up. I tried to make it a string by putting quotes on the "two words" but that didnt work

String comparison in Windows command language (batch) is very simple. Everything is evaluated, so the quotes are part of the string and they have to be on both sides of the == section of the statement.

You don't have to use quotes, although many people do, you can use just about any non-special character or characters (so not <>|% etc).


C:\>set var=egg

C:\>if (%var%)==(egg) echo yes
yes

C:\>if [%var%]==[egg] echo yes
yes

C:\>if {%var%}=={egg} echo yes
yes

C:\>if .%var%.==.egg. echo yes
yes

C:\>if $%var%$==$egg$ echo yes
yes

C:\>if abc%var%def==abceggdef echo yes
yes




694.

Solve : Chained ifs within a for statement.?

Answer»

I am attempting to store a list of drives which possess a TEST directory in their root folder within a pseudo-array. For the purpose of this example, I would then want them read back.

Code: [Select]Set foldercounter=0
For /F %%a in ('Fsutil Fsinfo Drives') do ( Set d=%%a
call If "%%d:~1%%"==":\" call If exist %%d%%TEST (call set folder_%%foldercounter%%=%%d%%TEST & set /a foldercounter+=1)
)
if %foldercounter%==0 goto end
set foldercounter2=0
:loop
set foldermalformedname=folder_%foldercounter2%
call echo/%%%foldermalformedname%%%
If not %foldercounter%==%foldercounter2% set/a foldercounter2+=1 & goto loop
:end
Let's say I have  have three drives: C:\, D:\, F:\ and I:\.  Only I:\ has a TEST folder in its root directory. I would expect the output:

Code: [Select]I:\TEST
Currently, I'm unable to find a way to chain my if statements without causing errors (the above code throws errors, despite many MODIFICATION attempts). Also, how would I then be able to include drives that had, for example, a folder entitled MISC in their root directory? Let's say, continuing from the above example, that both I:\ and F:\ had a MISC directory in them. How could I produce the output below?

Code: [Select]F:\MISC
I:\TEST
I:\MISC
I'm now aware that I should have chosen Powershell or similar for the job and I've already been reprimanded for it:

Quote from: Salmon Trout on January 05, 2012, 01:12:16 PM

Question: If you feel the need to laboriously create pseudo-arrays, and you find batch syntax "cumbersome", why not use a language with proper arrays and cool looking code, like VBScript or, better, Powershell?

This is the last bit of scripting needed now, though, and I'd really rather not learn a new language and then rewrite over 200 lines of script (some of it pretty convoluted) just to avoid ugly code. Quote from: Sirim on January 07, 2012, 12:05:30 PM
Let's say I have  have three drives: C:\, D:\, F:\ and I:\.

I can count, honest. I added a fourth drive in when I wanted a second example, but forgot to replace the 'three' with 'four'.

echo off
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
   if exist "%%A:\" (
      if exist %%A:\Test echo %%A:\Test EXISTS
      if exist %%A:\Info echo %%A:\Info exists
      )
   )



   The pseudo-array CREATION was required; the echoing it out was just for the example. Working code below:

Code: [Select]echo off
Set foldercounter=0
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    if exist "%%A:\" (
      if exist %%A:\Misc call Set folder_%%foldercounter%%=%%A:\Misc & Set/a foldercounter+=1
      if exist %%A:\Test call Set folder_%%foldercounter%%=%%A:\Test & Set/a foldercounter+=1
  )
   )
if %foldercounter%==0 goto end
set foldercounter2=0
:loop
set foldermalformedname=folder_%foldercounter2%
call echo/%%%foldermalformedname%%%
set/a foldercounter2+=1
If not %foldercounter%==%foldercounter2% goto loop
:end
695.

Solve : FreeDOS to Linux boot with a custom restore CD?

Answer»

I have a arcade game. It is called Deal or No Deal and it gives out tickets when you win.  It is made by a company called ICE Game.  The motherboard went bad for second time and I can't find the same model as a replacement. ICE wants almost $1000.00 for a replacement computer.  This is a common problem with their gear and I think it goes back to the bad Capacitors that plagued many computers. 

I want to MODIFY the restore process so I can use a different motherboard.  Right now it fails when attempting to install a different motherboard when trying to install Nvidia drivers, which the new motherboard doesn't use.   I need some help with understanding the boot process and changing the drivers. 

The restore CD first builds a DOS partition and installs FreeDOS then installs Linux and then the game is installed on that.  After that it boots up in Linux and runs the game.

I have been looking at the files and I can't quite figure out or follow the process.

For example: In the ROOT directory on the restore CD there are about ten files.  One of them is a AUTORUN.INF  Is that the first thing that is looked at after the CDROM starts the boot process?  In that file is this:

icon=\FREEDOS\FREEDOS.ICO,0
label=FreeDOS Beta 9
shell\DOCFDInfo=View &FreeDOS Information Sheet
shell\DOCFDInfo\command=write \FREEDOS\DOCS\INFO.TXT
shell\DOCInstReadme=View Read&Me
shell\DOCInstReadme\command=write \FREEDOS\DOCS\README.TXT
shell\DOCInstall=&View Installation Document
shell\DOCInstall\command=write \FREEDOS\DOCS\INSTALL3.TXT
shell\DOCPrograms=View Included Programs &Details (Name, License, URL)
shell\DOCPrograms\command=write \FREEDOS\DOCS\PROGRAMS.TXT
shell\MakeBoot=Create Generic 1.44MB &Bootdisk for use with FreeDOS CD
shell\MakeBoot\command=FREEDOS\SETUP\BATCH\BOOTDISK.BAT


Is the next thing that takes place is the BOOTDISK.BAT file being run?  Here is what is in that.
echo off
cls
rem Check for memdisk existence, errorlevel 1=found ; 0=notfound
set dest=A:
if "%OS%"=="Windows_NT" goto begin
if not exist a:\freedos\ifmemdsk.com goto begin
a:\freedos\ifmemdsk.com
if errorlevel 3 goto begin
if errorlevel 1 set dest=B:
goto begin

:begin
title FreeDOS Bootdisk Builder
cls
echo Welcome to the bootdisk builder. this will create a bootdisk for you.
echo.
if not "%OS%"=="Windows_NT" goto begin2
echo Please insert a (non)empty formatted diskette in diskdrive and press a key to continue
goto emptydsk
:begin2
if not "%cdrom%"=="" CDD %cdrom%
cls
if "%dest%"=="B:" echo Please insert a (non)empty formatted diskette in your diskette drive.
if "%dest%"=="A:" echo please remove bootdisk and insert a (non)empty formatted diskette in your diskette drive
goto emptydsk

:emptydsk
pause Press a key to continue or Control-C to abort.
rem show files, trying to detect kernels.
attrib -r -h -s %dest%\*.*
cls
rem kernel files and cdromdrivers (as long as atapicdd.sys isn't performing good/stable enough)
for %%x in ( %dest%\io.sys %dest%\msdos.sys %dest%\oakcdrom.sys ) do if exist %%x attrib +r %%x
for %%x in ( %dest%\*.* ) do del %%x
rem all files in root removed, except for kernel files.
goto docopy

:docopy
if "%dest%"=="A:" \freedos\3rdparty\extract -ox \isolinux\data\fdboot.img %dest% *.*
if "%dest%"=="B:" xcopy /s /y A:\*.* %dest%
rem files are now present on diskette!
rem setup stable cdromdriver, delete recreatable files
if exist %dest%\oakcdrom.sys copy /y %dest%\oakcdrom.sys %dest%\driver\vide-cdd.sys
if exist %dest%\metakern.sys del %dest%\metakern.sys
if exist %dest%\freedos\bootsect.bin del %dest%\freedos\bootsect.bin
set kernel=kernel.sys

rem Assuming non-freedos bootsector currently installed on diskette
if not exist %dest%\io.sys goto end
%dest%\freedos\copybs.com %dest% %dest%\freedos\bootsect.bin
if not exist %dest%\freedos\bootsect.bin goto end
if not exist %dest%\freedos\meta-all.bin goto end
if not exist %dest%\freedos\metaboot.bot goto end
copy /b %dest%\freedos\meta-all.bin + %dest%\freedos\metaboot.bot + %dest%\freedos\bootsect.bin %dest%\metakern.sys
if exist %dest%\metakern.sys set kernel=metakern.sys
echo SHELL=A:\COMMAND.COM A:\ /E:1024 /P=A:\FREEDOS\FDAUTO.BAT >> %dest%\config.sys
goto end

:end
echo Kernel file: %kernel%
%dest%\freedos\SYS %dest% %dest% BOOTONLY /K %kernel%
set kernel=
goto end2
:end2


This is where I get lost.  This is where I need some help on what it is doing and what takes place next.  And I guess I keep following this until I get to the point where it loads the config files for the drivers and then modify that to use different ones. 
This process is all automated.  Even though there are things that say "Insert floppy disc"etc.  all we normally do is put the CD in the computer and turn the computer on and in about ten minutes it restores all of the files and the game from then on boots and plays when the machine is turned on.

If someone things they can help me with this I can pay some money through paypal.  I am doing this trying to save some money but I know there isn't a easy answer and it might take many messages.  Or if someone can guide me through this on the forum that would be helpful.  If it wasn't a rush I would just STUDY this stuff and figure it out eventually but I have to get this back up and running. 

On the batch file listed above, this is the first part.
rem Check for memdisk existence, errorlevel 1=found ; 0=notfound 
set dest=A:
if "%OS%"=="Windows_NT" goto begin  and here, etc.
if not exist a:\freedos\ifmemdsk.com goto begin
a:\freedos\ifmemdsk.com
if errorlevel 3 goto begin
if errorlevel 1 set dest=B:
goto begin

Could someone explain how this part works?

Thanks for any help and if this is too much for this forum is there a place I can GO with this type of question?
Thank you
Russ
Quote from: uriahsky on January 04, 2012, 04:59:17 PM

On the batch file listed above, this is the first part.
rem Check for memdisk existence, errorlevel 1=found ; 0=notfound 
set dest=A:
if "%OS%"=="Windows_NT" goto begin  and here, etc.
if not exist a:\freedos\ifmemdsk.com goto begin
a:\freedos\ifmemdsk.com
if errorlevel 3 goto begin
if errorlevel 1 set dest=B:
goto begin


Could someone explain how this part works?

I can try to explain how this is working, but I don't know where to start on helping with your overall issue.

rem Check for memdisk existence, errorlevel 1=found ; 0=notfound -> This line is a remark, it does nothing in the program itself.
set dest=A: -> This is setting the 'dest' variable that is used later in the program.
if "%OS%"=="Windows_NT" goto begin -> The variable 'OS' holds the current operating system this batch file is run in. If it is a 'Windows_NT' operating system, then it simply jumps to the :begin label.
if not exist a:\freedos\ifmemdsk.com goto begin -> This tests to see if the file exists. If it does not exist, then it jumps to the :begin label.
a:\freedos\ifmemdsk.com -> This simply starts the identified process. It gives control to that process, and will not continue until the process closes.
if errorlevel 3 goto begin -> This tests the errorlevel, which is increased anytime a process has an unexpected output, and jumps to the :begin label if true. If the ifmemdsk.com process had three unexpected outputs, then the errorlevel would equal 3. (Errorlevel is something I'm not overly familiar with, and this is from my basic understanding on errorlevels.)
if errorlevel 1 set dest=B: -> Same as above, only testing for a different errorlevel and setting a different value for the 'dest' variable if true.
goto begin -> Jumps to the :begin label.

I hope that helps. If you have any questions on the explanations, please ask. Quote from: uriahsky on January 04, 2012, 04:59:17 PM
rem Check for memdisk existence, errorlevel 1=found ; 0=notfound
set dest=A:
if "%OS%"=="Windows_NT" goto begin  and here, etc.
if not exist a:\freedos\ifmemdsk.com goto begin
a:\freedos\ifmemdsk.com
if errorlevel 3 goto begin
if errorlevel 1 set dest=B:
goto begin

It seems to change the initial value of dest to SUIT the case.

If memdisk exists and %OS% doesn't expand to Windows_NT then dest = B:
Otherwise dest = A:So it is checking for memdisk and if it is found it sets the dest variable to B and if not to A?
Then the part where %os% ==windows nt.  Is it looking somewhere for "OS" to be set as "Windows NT" or something else?    Where is "OS" going to be set? 
But either way it is basically moving the program onto the "Begin"

But then in the begin part under
if "%dest%"=="B:" echo Please insert a (non)empty formatted diskette in your diskette drive.
if "%dest%"=="A:" echo please remove bootdisk and insert a (non)empty formatted diskette in your diskette drive
These things are being done automatically.  But how?  Did I miss a start up file? It is echoing a command for the user but I never do anything during the installs.

If a computer is booted with a CDROM is it the AUTORUN.INF file that is read or could it be any of these.
Boot.Catalog
Boot000.Catalog
DFSDOS.EXE
ISOLINUX.BIN
LVM.PD1
MAKEITSO.BAT
RESTORE.DFS
PART0IMZ
VSSVER.SCC

Those are the only other files in the directory. 
The MAKEITSO.BAT consists of
isolinux\buildcd\mkisofs -o ..\explet.iso -N -l -no-iso-translate -relaxed-filenames -R -r -boot-info-table -iso-level 3 -no-emul-boot -b isolinux.bin .\
But where is this getting called?

Thanks, I have learned a few things already.
Russ
Quote from: uriahsky on January 04, 2012, 07:16:21 PM
Then the part where %os% ==windows nt.  Is it looking somewhere for "OS" to be set as "Windows NT" or something else?    Where is "OS" going to be set? 

%OS% is an embedded variable. Certain variables are made available as soon as cmd prompt is started, and %OS% is one of them. %Windir% is another one that is available in cmd prompt, and holds the file location of the windows directory. So if you installed everything on your system with default settings, %windir% will be "c:\windows", but if you installed your Windows onto a D: drive, then %windir% would be "d:\windows." %OS% holds the operating system that is detected when cmd prompt is started. Which means if it detects that a "Windows_NT" operating system (which I believe is what any version after Win 98 will have), then it will jump to begin. The big caveat on all of this is that none of these variables will be available in MS-DOS, so what should happen is Code: [Select]if "%OS%"=="Windows_NT" goto begin will expand to Code: [Select]if ""=="Windows_NT" goto begin and the program will continue by looking for ifmemdsk.com in the a: drive. What it is essentially doing is making sure that you do not try to overwrite the disk that is running the startup program.Thank you, I had no idea about the embedded variables.  I have ran through this disk a number of times and I found a way to step through all of the .bat files.  It looks like the first part loads drivers for the the CD, and does a few other things then makes about five partitions and then puts linux into one of them and then that is where the Nvidia drivers come into things.  So, I may need to focus on the Linux part to figure out how to change the Nvidia driver.
696.

Solve : Batch File help for Beginner?

Answer»

Hi All,

i'm very new to batch FILES and appologees if this is very simple question.

i currently have over 100 avi files located on P:\films\films\ and would LIKE create a .nfo file for each, KEEPING the same file name i.e Star Wars Episode II - Attack Of The Clones.avi with Star Wars Episode II - Attack Of The Clones.nfo

Can some please advise what the cmd would be to complete this function?

Thank you in advance. For this job you will need the FOR command.
Code: [Select]FOR /?For more info.

To create an empty file the command:
Code: [Select]ECHO.>(filename)will suffice.

So, perhaps:
Code: [Select]ECHO OFF
P:
CD P:\films\films
FOR %%I IN (*.avi) DO ECHO.>%%~nI.nfo
edit:
Although, would be faster to just open Run and ENTER this:
Code: [Select]FOR %I IN (P:\films\films\*.avi) DO ECHO.>%~nI.nfoThank you Veltas - worked a treat!!!

697.

Solve : Tokens and Delims???

Answer»

I have been using BATCH FILES for a while now, but I have not learned what or how to use the tokens and delims and I have a feeling that they are very useful. Can SOMEBODY please FILL me in, thanks. Tokens are sections of a string, separated by delimiters.

If this is the FOR command

for /F "tokens=1,2,3 delims=," %%A in ("eggs,bacon,cheese") do echo %%A %%B %%C

%%A is eggs
%%B is bacon
%%C is cheese

Have you done this?

FOR /?



698.

Solve : Retrieving filepaths from a directory and performing analysis on them.?

Answer»

Hi all,

I am writing a batch file which needs to retrieve a list of files from a directory (including subdirectories) and then performs analysis on each path. Currently though, I am unable to get it working. Rather than post the entire batch file, I have created a well-commented sample showing the method I am currently working on. If there is a better way of doing this, I'd be very happy to hear of it.

Code: [Select]echo on
rem Make an example directory and populate it with 5 files.
set d=%homedrive%\ExampleTestDir
If not exist %d% md %d%
echo/File 1 contents.>%d%/file1.txt
echo/File 2 contents.>%d%/file2.txt
echo/File 3 contents.>%d%/file3.txt
echo/File 4 contents.>%d%/file4.txt
echo/File 5 contents.>%d%/file5.txt

rem Create a set of variables from file_0 to file_x , where x is the number of files in the directory and all its sub-directories.
rem These variables will each hold the file path of one of the files in the directory tree.
set filecounter=0
for /f "delims=" %%a in ('dir/b /s %d%') do (
call set file_%%filecounter%%=%%a
set/a filecounter+=1
)

rem Now attempt to echo the variable values (essentially performing a dir/b /s).
set counter2=0
:loop
set filenumber=file_%counter2%
rem In the LINE of code below, I use 2>nul to prevent the script from throwing 'The process tried to write to a nonexistent pipe.' errors seemingly at random.
rem I would like to know why it does this and find a way of avoiding it, if possible.
echo/2>nul | echo/%%%filenumber%%%
set/a counter2+=1
If %counter2% GEQ %filecounter% goto breakout
goto loop


rem Now the above works (albeit with the erratic error messages if 2>nul is not used), but I cannot set a vairable to be equal to the output of the echo command.
rem For example, replacing 'echo/2>nul | echo/%%%filenumber%%%' with 'echo/2>nul | echo/%%%filenumber%%% | set curfilename=' does not work.
rem The example loop below (currently ignored) does not behave as expected (by me, at least).
rem Curfilename is not assigned a value.
:unusuedloop
set filenumber=file_%counter2%
echo/2>nul | echo/%%%filenumber%%% | set curfilename=
echo/%curfilename%
set/a counter2+=1
If %counter2% GEQ %filecounter% goto breakout
goto unusedloop

:breakout
rem And tidy up afterwards.
rd/s /q %d%

To clarify, when I say it produces these errors seemingly at random, I mean that the output from the exact same batch script (with the 2>nul removed) can produce the following:

Code: [Select]C:\ExampleTestDir\file1.txt
The process tried to write to a nonexistent pipe.
C:\ExampleTestDir\file2.txt
C:\ExampleTestDir\file3.txt
C:\ExampleTestDir\file4.txt
C:\ExampleTestDir\file5.txt
The process tried to write to a nonexistent pipe.
and

Code: [Select]C:\ExampleTestDir\file1.txt
C:\ExampleTestDir\file2.txt
The process tried to write to a nonexistent pipe.
C:\ExampleTestDir\file3.txt
C:\ExampleTestDir\file4.txt
The process tried to write to a nonexistent pipe.
C:\ExampleTestDir\file5.txt
With no alternations whatsoever to the batch file between the attempts.

Also, on a related note, when extracting the filename from the path (although I usually need the path, sometimes I need the name), I am using the cumbersome line
Code: [Select]for /f "delims=" %%a in ("%source%") do set sourcefilename=%%~nxawhere source is a filepath to the file. Although this works well enough, I can't help but feel there's a neater way of doing it. Is there?

Any thoughts MUCH appreciated, be they on my (rather poor) coding or direct answers to the questions.
Why???!!! are you doing this?

echo/2>nul | echo/%%%filenumber%%%

When you can do this?

call echo %%%filenumber%%%

See? No pipe!

And... get the value into a variable:

for /f "delims=" %%A in ('call echo %%%filenumber%%%') do set curfilename=%%A

Or... much simpler:

call set curfilename=%%%filenumber%%%

Quote

Also, on a related note, when extracting the filename from the path (although I usually need the path, sometimes I need the name), I am using the cumbersome line

for /f "delims=" %%a in ("%source%") do set sourcefilename=%%~nxa

where source is a filepath to the file. Although this works well enough, I can't help but feel there's a neater way of doing it. Is there?

I don't know why you call that "cumbersome". It's a one line method of getting the name and extension. That's about as "neat" as NT batch scripts get.

Question: If you feel the need to laboriously create pseudo-arrays, and you find batch syntax "cumbersome", why not use a language with PROPER arrays and cool looking code, like VBScript or, better, Powershell?

What is your objective with that script?
THANKS very much,  Salmon Trout, that does the job wonderfully.

I'm using this strange method because I'm that bad at writing batch files. If there's a better way of doing what I'm trying to, I'm happy to hear it, as I indicated in my first post.

The reason I chose to use a normal MS DOS batch file is because I've used them before. Not a particularly good reason, admittedly.

Quote from: Salmon Trout on January 05, 2012, 01:12:16 PM
"with the 2>nul removed" - did you mean like this?

echo/ | echo/%%%filenumber%%%


Yes, exactly.

As for why I'm doing this, the script will feed an unknown number of files into an application (amongst other things). As I've stated, the code I wrote was just an example showing what I was trying to achieve, without my putting the FULL code in.
See above! I edited my post while you were answering.
Quote from: Sirim on January 05, 2012, 01:51:23 PM
The reason I chose to use a normal MS DOS batch file is because I've used them before. Not a particularly good reason, admittedly.

A very poor reason coming from an apparently intelligent person!

By the way, this is not "MS-DOS".
please read multiple edits to my reply no.1 above
Your updated solution also works perfectly and is neater, thanks.

When I said it was cumbersome, I was referring to the way in which I'm essentially using the for statement to convert a normal variable into the %%[letter] form, so that I can then extract the filename using %%~nx[letter].

I'm only creating a pseudo-array because I can't think of a simpler way of doing it. Again, I emphasize that I'm not skilled at working with these files.

Quote from: Salmon Trout on January 05, 2012, 01:55:18 PM
A very poor reason coming from an apparently intelligent person!

By the way, this is not "MS-DOS".


Sorry. You're completely right on both counts. Would cmd.exe batch files describe them well enough? Quote from: Sirim on January 05, 2012, 02:25:16 PM
When I said it was cumbersome, I was referring to the way in which I'm essentially using the for statement to convert a normal variable into the %%[letter] form, so that I can then extract the filename using %%~nx[letter].

The FOR command was designed for exactly that kind of task. If you check the help (type FOR /? at the prompt) you will see all the ~ variable modifiers. They also work with single percent parameters, %0 (special) and %1 to %9

Quote
Would cmd.exe batch files describe them well enough?

Yes, or "NT family command scripts". Your code is not "bad" at all, it is very intelligent.
699.

Solve : Beginner needs help, in renaming a lot of files.?

Answer»

Hello,

I could use some help.
I would like to rename a whole bunch of files.

Now they are named like:              A story about frogs - Mister Greenleg.epub
They should be renamed to:          Mister Greenleg - A story about frogs.epub

How do i do that with a bat file?

Thanks in Advance,
GreenlegThere's probably a 1 line line solution, but I can't find a way of trimming the whitespace WITHOUT a second line.

The below switches the two halves of the file name AROUND the hyphen (and does so for all files in the directory and its subdirectories). It will fail on any files that do not have a hyphen in their name, with error 'The syntax of the command is incorrect.', but will rename all other files before and after the hypenless file:

Code: [Select]For /f "tokens=1,2 delims=-" %%a in ('dir/b /s') do (set p2=%%~nb
call ren "%%~na - %%p2:~1%%%%~xb" "%%p2:~1%% - %%~na%%~xb")Hello Sirim,

Thank you for helping me out.
I tried the code you wrote, but it doenst work.
It reads EVERY file, bit says that it can't find the given file.

C:\Documents and Settings\Jan\Bureaublad\rename-ebooks>(
set p2= Nachtlamp
 call ren "rename - %p2:~1%" "%p2:~1% - rename"
)
Het systeem kan het opgegeven bestand niet vinden.


This is the message i get. (I'm using a dutch XP OS)
The directory where i run the bat file is "rename-ebooks"
The batfile itself is called "rename"
And this message come from the file  "Nachtlamp - Jack Vance.epub"
The last line in dutch says that the system can't find the file given.

Any idea what i'm doing wrong?

GREETINGS, GreenlegMy code wasn't expecting a hypen in the folder name. The below does (this ACTUALLY requires there to be exactly 1 hyphen in the folder path):

Code: [Select]For /f "tokens=2,3 delims=-" %%a in ('dir/b /s') do (set p2=%%~nb
call ren "%%~na - %%p2:~1%%%%~xb" "%%p2:~1%% - %%~na%%~xb")this one works.
Thanks for helping me out.
Saves me a lot of workYou're welcome, glad I could help.Here is a much longer piece of code that crops the name down to the text string and then sets them up the way you show. It is definitely more involved than the previously posted code, but it should provide also prevent some errors from occuring if different spaced names are encountered.

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=1,2,3 delims=-" %%A in ('dir /s /b') do (
  set oldfile=%%A-%%B-%%C
  set ext=%%C
  call :skimext
  set P1=%%B
  call :skimP1
  set P2=%%C
  call :skimP2
  set newfile=!P2! - !P1!!ext!
  echo ren !oldfile! !newfile!
  pause
)
goto :eof


:skimext
:extloop
echo %ext% | find "." >nul
if errorlevel 1 goto setext
set ext=%ext:~1%
goto extloop
:setext
set ext=.%ext%
goto :eof

:skimP1
:P1loop1
set P1LC=%P1:~-1%
if not "%P1LC%"==" " goto P1loop2
set P1=%P1:~0,-1%
goto P1loop1
:P1loop2
echo %P1% | find "\" >nul
if errorlevel 1 goto :eof
set P1=%P1:~1%
goto P1loop2

:skimP2
:P2loop1
set P2C1=%P2:~0,1%
if not "%P2C1%"==" " goto P2loop2
set P2=%P2:~1%
goto P2loop1
:P2loop2
echo %P2% | find "." >nul
if errorlevel 1 goto :eof
set P2=%P2:~0,-1%
goto P2loop2
Now this code may seem much longer and much more convoluted, but it should also accomplish what you are wanting to accomplish, with a little error compensation involved as well. When you are satisfied that the code is showing you the correct command that you are wanting to see (you should see the ren !oldfile! !newfile! expanded with correct names) then take the echo out of the second-to-last line and remove the pause on the last line and run the code.

700.

Solve : enter character recognized as character?

Answer»

Hello,

I am MAKING a vba project in which I take info from the vba FORM put it together in a command line and pass it in a dos command, this line creates an item in another tool.

I have an issue with a text field, in which you may enter data in a text format with enter and another line and enter, when I pass this into a dos command the enter sign will not be recognized as a character but as the command it self an enter which runs the dos command to early

I am now stuck, how can I modify the text what type of escape character should I introduce that will be seen in fact as an enter signShow some code.  The enter key is supposed to finish a user input.well

Execute DOS Command: im createissue --hostname=mks-psad-test --port=8002 --user=blabla --password=xxxxxx --type=issue --field=Summary="Summarize your requestdd" --field=Description="Describe your request
new
line
again one"
 --field="Issue Type=Change Request" --field="Project=/Tool_Support" --field="System Element"=89462 --field="Stakeholder Reference"=blabla

this is the dos command which after the first enter it deploys the dos and that enter is from the text field, is not an actual enter, how can I transform the text
Describe your request
new
line
again one

so that the enters are read as special character and not as an enter command?mibushk, I think we need to go over some basics.  I can't follw what you are doing.
We can deal with non-visible chars in a special way in low-level programs.  The end of line is done in perhaps four different ways on computer systems. But you normally do not have to remove or add it to any text you are nursing.

At the DOS command line {actually the Windows command line} items are separated by spaces. Different programs have different command line options.  When a program reprieves a  command line options it is not really the command interpreter that is doing the work. The command interpreter just gives it to the program. Of course, the command has to be on one line with no end of line until the end of line.

In VBA and other versions of MS basic there is a specific way to write a line of text WITHOUT en-of-line markers until the last item in the line. This is true of all modern computer languages. You do not have to remove or transform end-of-line chars. They are not sent unless you specified them in you write statement. But you do have to indicate how items are exasperated, unless the program does not require separation or delimiting of items.

Please, I am not trying to talk down to you. But it seems like you want to write code at a low-level when you don't have to.

Without knowing what program you use with VBA I have to just guess.
To write one line with a number of fields and then finish with a end of line, hound would do it like this:

Code: [Select]Write request$,  option$, daytime$, send$
WrinteLNThat is not real code, it shows items separated from northeaster and then an end of line given. In this dialectic the $ means i not a number, but a string. The commas may generate tabs or spaces. Again, that depends on the dialect. 

I hope this is of some help. Pardon my grammer. Quote from: Geek-9pm on January 23, 2012, 02:02:56 PM

Pardon my grammer.
Yeah, it was getting ROUGH near the end there.

Again, we don't know for sure the language, which makes it difficult to tailor the response to help you specifically. In VBScript, if you are wanting one line of code to display multiple lines of output, you can use the carriage RETURN to do so:
Code: [Select]wscript.echo "This is how" & VBCRLF & "you can get" & VBCRLF & "multiple lines of text" & VBCRLF & "with one line of code" which would display Code: [Select]This is how
you can get
multiple lines of text
with one line of code
Running this strictly from the command line though, I recommend trying this, though I have no idea whether or not it will work.
Code: [Select] im createissue --hostname=mks-psad-test --port=8002 --user=blabla --password=xxxxxx --type=issue --field=Summary="Summarize your requestdd" --field=Description="Describe your request" & VBCRLF & "new" & VBCRLF & "line" & VBCRLF & "again one" --field="Issue Type=Change Request" --field="Project=/Tool_Support" --field="System Element"=89462 --field="Stakeholder Reference"=blabla Quote from: Geek-9pm on January 23, 2012, 02:02:56 PM
I hope this is of some help. Pardon my grammer.

I will pardon your grammar but I refuse to pardon your spelling of grammar.  Quote from: mibushk on January 23, 2012, 03:47:58 AM
im createissue --hostname=mks-psad-test --port=8002 --user=blabla --password=xxxxxx --type=issue --field=Summary="Summarize your requestdd" --field=Description="Describe your request

This looks like MKS Integrity Manager which...

Quote
[...] provides a command line interface (CLI) to manage users, groups, and permissions; and issues. Unlike Source Integrity Enterprise Edition, the Integrity Manager CLI does not yet provide the same functionality as the graphical user interface (GUI) or Web interface, and only a few command line interface commands support GUI interaction. At this time, the command line interface provides basic Integrity Manager functionality. For complete functionality, use the graphical user interface or Web interface.

Quote
im createissue [--addAttachment=value] [--addRelationships=value]
[--type=value] [--field=value] [--hostname=server] [--port=number]
[--password=password] [--user=name] [(-?|--usage)]
[(-F file|--selectionFile=file)] [(-N|--no)] [(-Y|--yes)] [--[no]adorn]
[--[no]batch] [--cwd=directory] [--forceConfirm=[yes|no]]

Really you need to consult the MKS Integrity documentation and see if the app even supports embedded newlines in the relevant parameter string. If this is your job, to write front ends for MKS Integrity, how come you do not have access to all the relevant documentation?

Unless the Integrity app supports some kind of embeeded newline indicator, e.g. \n I can't see how you are going to do this.








Quote from: Geek-9pm on January 23, 2012, 02:02:56 PM
But you do have to indicate how items are exasperated

I have seldom read such profoundly wise advice.
Quote from: Salmon Trout on January 24, 2012, 01:13:40 PM
some kind of embeeded newline indicator

some kind of embedded newline indicator