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.

2151.

Solve : how to run an ftp script silently??

Answer» HI all, so I am trying to RUN a batch file to upload file via ftp using an ftp utility called cmdftp. It is almost the same as window's NATIVE ftp. I know how to run the batch file silently, but the batch file calls a text script that I don't know how to hide (so WHENEVER this file runs, the command line WINDOWS will pop up until it is finished)

the batch file is (you can actually replace cmdftp with ftp)
Code: [Select]cmdftp -s:ftpscript.txt -d:"Log.txt"
the script is

Code: [Select]open ftp.drivehq.com
USERNAME
xxxxxxxxx
cd test
delete orders.xml.bak
rename orders.xml orders.xml.bak
put c:\test\orders.xml
quit
I think i need to add something to the script file to make it run silently but I don't know what, echo off doesn't work. Any help is greatly appreciated!Did you try redirecting everything to NUL?

Code: [Select]cmdftp -s:ftpscript.txt > NUL 2>&1
2152.

Solve : Administrator privilege run code?

Answer»

Hi all,

I found code that can run any batch FILE as Administrator and after insert this code into my bat file works properly but SOMETIMES show this message "The system cannot find the drive specified.
                                                   Press any key to continue . . ."

but still my code works fine after pressing any key to continue

Here is Administrator code
Code: [Select]:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B

:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

How can I ignore this Error message and go on?Is there any one can solve this issue?First two steps in troubleshooting a batch file.
1) Don't use ECHO OFF
2) Run the batch file from the command prompt instead of with your mouse.

By using both of those TECHNIQUES you can see what line of code is causing the error message. And looking back you have been told this before in your previous threads.

As far as your code goes you should not use an Apostrophe to surround IF comparisons.  You should use double quotes as that protects against spaces and other special characters that may cause failures in the comparison.
Code: [Select]IF "%var%"=="string"Thanks Squashman for your reply
And I'll try to do your suggestion
Then feed back to you.Dear Squashman, I tried to do what I understand from your suggestion but the PROBLEM still exists "the same error message"
and here is the last code after replaced any single quote with double quotes and also I have tried to remove echo off and run it under CMD but I can't understand it where is the error?

Code: [Select]:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion

:checkPrivileges
NET FILE 1>NUL 2>NUL
if "%errorlevel%" == "0" ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if "%1"=="ELEV" (echo ELEV & shift /1 & goto gotPrivileges)
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B

:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if "%1"=="ELEV" (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)
Hi all,

Any reply to my question?
I still have the same issue, and GET this message "The system cannot find the drive specified"

Please help?

2153.

Solve : Square roots in a batch file??

Answer»

I'd like to start off saying I'm no expert in programming, so don't expect me to know exactly what you're talking about.  I'm trying to write a batch file that automatically solves quadratic equations, and I have most of it figured out.  I just can't figure out how to find the square root of a number.  It WOULD also be NICE if you could tell me how to graph something too.

Thanks,
JeffCheck out this page on Arithmetic Extraction of Square Roots

Quote

I'm trying to write a batch file that automatically solves quadratic equations, and I have most of it figured out

I, for one would truly love to see your code. hmm...that's pretty interesting.  Now I just have to figure out how to put that into a batch file 

I'll post the code once I have everything figured out...thanks for the helpCan anybody think of a way to put this into a batch file?  Quote from: juniorgiant8 on June 11, 2008, 02:05:45 PM
I'll post the code once I have everything figured out...thanks for the help

Quote from: Sidewinder on June 11, 2008, 01:58:32 PM
I, for one would truly love to see your code.

I would like to see it too. Show us what you've got so far, so we can understand where you are going with this. (It might help us to find the answer you need.)
dont batch files only work for cmd? how are you going to get cmd to solve your math problums?seriously, why should you use batch for such things as solving quadratic equations? Get a real programming language.! Since batch arithmetic only knows about integers, I think that finding square roots might be quite hard.

Here's what I have so far...
echo off

:input
echo what is A?
set /p A=
echo what is B?
set /p B=
echo what is C?
set /p C=
goto calculate

:calculate
set /a discrim=%B%*%B%-4*%A%*%C%
echo discriminant is %discrim%
goto positive

:positive
echo Is the discriminant positive?
set /p pos=
if %pos% equ y goto square
if %pos% lss y goto positive
if %pos% gtr y goto positive
if %pos% equ n goto imaginary
if %pos% lss n goto positive
if %pos% gtr n goto positive

:square
echo Is the discriminant a perfect square?
set /p sq=
if %sq% equ y goto graph
if %sq% lss y goto square
if %sq% gtr y goto square
if %sq% equ n goto quad
if %sq% lss n goto square
if %sq% gtr n goto square

:imaginary
echo Error...cannot be solved as roots are imaginary
goto input

:quad
set /a roots=

:graph



Also, I don't know any other programming languages yet I was just fooling around with batch files and came up with this idea...If you have any suggestions for a different programming language to use please tell me where a good guide is so I know how to use it. Code: [Select]if %pos% equ y goto square
I think you meant this

Code: [Select]if %pos% equ %y% goto square Quote
Can anybody think of a way to put this into a batch file?

I thought it might be interesting to follow the instructions from the link. This is actually easier to do with a pencil and paper than with batch language but if the ancient Greeks could do it, why not us? Except for perfect squares, square roots are irrational numbers and any mechanical method will only give close approximations.

Code: [Select]echo off
setlocal enabledelayedexpansion
set count=0
set /p dend=Enter Number:
set num=%dend%
for /l %%i in (%dend%, -1, 1) do (
set /a sqr=%%i*%%i
if !sqr! leq %dend% (
set digit=%%i.
  set root=%%i
goto out
)
)

:out
call set /a count=%%count%%+1
if %count% GTR 5 goto next
set /a dend=(%dend%-%sqr%)*100
set /a div=%root%*2
for /l %%i in (9,-1,0) do (
set /a sqr=%div%%%i*%%i
if !sqr! leq %dend% (
set root=%root%%%i
goto out
)
)

:next
set root=%root:~-5%
if %dend% neq 0 set digit=%digit%%root%
echo Square Root of %num% is %digit%

Precision is 5 decimals. The code can be tweaked if you require changes.

 

Note: This runs at glacial speed with large numbers.

Edit: I was typing this when you made your last post. Most script languages have a square root function which would put the above code to shame. Check out VBSCRIPT (installed with Windows), Python (requires download) or even the C language.

Good luck.



Quote from: Dias de verano on June 12, 2008, 01:17:15 PM
Code: [Select]if %pos% equ y goto square
I think you meant this

Code: [Select]if %pos% equ %y% goto square

No, I tried that in a program without using %y% and it worked just fine
y is supposed to mean yes. I guess I could add (y/n) to the question...Lol that looks really complicated Sidewinder.  I just tried it and it doesn't work...it just closes out after I enter the number.  I'll take a CLOSER look and try to figure out what is wrong.  Maybe I should look into another programming language I had to make a quick edit, but it only dealt with the format of the output line. I cannot duplicate your results. Did you cut and paste all the code? Posters in the past have had problems with copying code off the boards.

Quote
Lol that looks really complicated Sidewinder

That's why calculator were invented. yeah I couldn't get it to work... I think I copied the WHOLE thing
2154.

Solve : run program on a specific processor in a multi-core environment?

Answer»

Dear All

In either Windows or MSDOS, the execution of a program is arranged by the OS.
In a multi-core CPU which supports 2-4 cores for running programs, the execution of program
on which core is also arranged by the OS.

In Windows, I can CHECK the task manager and assign the core(s) on which a task (USUALL a .exe program) may run by changing the "CPU-association" (e.g., check box on CPU-0 or CPU-1).

In DOS prompt, how can I do the same thing? Is there a way to put a command or a parameter under DOS prompt or Windows' CMD so that the execution of a program is BOUND for a specific core?

Thanks
Command Prompt and not even DOS can do this, DOS was around during the 80's and the early 90's, a time when Mutil-Core proccessors were un-heard of. So no Command Prompt cant accomplish this task.

2155.

Solve : Gulp boy do I have a boo boo?

Answer»

While trying to USE my restore CD I accidentally hit the OPEN to the A:\ prompt.  How do I get back to the windows start screen.  As far as I KNOW I have not successfully rebooted the restore cd because of a Norton software GHOST that was running.   I am trying to go back to the windows start screen so that I can get rid of the Norton software and restore and reboot.   Is there hope that I can get this done?   If all you did was SWITCH into the command prompt, a simple reset should fix that just fine. Or you could type "exit" or "reboot" in the prompt.

2156.

Solve : Find and Replace & File In Use?

Answer»

Hello... Here is my problem and my SOLUTION which I am having some problems with in a batch file on WINDOWS 2000 and XP platforms.

Problem that I wrote the batch to fix: Users need to run software in local Admin mode such as Pagemaker etc, and as Admins the users tend to download and install junk like weather bug, Limewire, and Chat software like AIM etc since you can not designate Admin privileges for one piece of software and User Privileges for rest etc.

Solution: I wrote a batch that finds and replaces the EXE's for these programs on all systems on the network as a scheduled task and replaces the EXE with a same named EXE, but one that blats to the user and alerts me to an installation of unapproved softare.

Solution Problem: If the service is started such as AIM, the service has to be stopped VIA net stop, before the EXE can be replaced. Some programs even though you shut off the service, you will get an error during the file replacement stating that the file is in use by windows, but it is not a Windows System file, it is the programs EXE. With the service off, the EXE should be able to be overwritten with my EXE that the batch is programmed to replace, yet I get the error of "File in use by Windows" when trying to overwrite even when SERVICES are stopped for the program.

Does anyone have any suggestions on how you can stop Windows from grabbing the programs EXE as "in use" when the service is stopped??? Would like to do this without having to run a utility on the systems manually off of another bootable device like USB thumb DRIVE then alter etc.

Thanks,

Dave

2157.

Solve : Help echo. is not recognized?

Answer»

Dear All,

Could someone help me to make my cmd.exe recognized echo. again?

Before it worked fine in my XP, but after i try redirection command, like this 2>&echo.>>error.txt
it become error...
i can't USED echo. anymore...it said 'echo.' is not recognized as an external or internal command.

So help pls, anyone give solution to make it works again...

many thanks

rasWhere did you get this weird code from?

Code: [Select]2>&echo.>>error.txt
What is the 2>& supposed to do?

Code: [Select]C:\>2>&echo.>>error.txt
2>& was unexpected at this time.
try this

Code: [Select]echo.>>error.txt






thanks for reply...

yup i khow that's a weird code..because i just create it for my experiments...
here is the detail...
actually before, i used
xcopy %src% %dest% /d /y /i>>report.txt 2>error.txt

it worked ok, and than i tried
(echo. +++date create+++ date /t & time /t)>error.txt
xcopy %src% %dest% /d /y /i>>report.txt 2>error.txt

it became error: file can't create because already hold by other process...

And then i tried weird STUFF for error redirection....not only that may be i did something...

but after that i could not used echo. anymore but it work ok with echo only....event a simple code like: echo. HELLO word , but worked ok for: echo hello word
i think, i did something that change the cmd.exe...

i already tried to reboot my xp sp2...
still the same if i used echo. ...the same error arised...

thx again...did you know there is a difference between echo. and echo ?
yup.. with echo. we can send BLANK on our output device...ex:

echo.test
echo.
echo.oc

will give output like this:

test

oc

Not only that of course: it help us easy on typing code..like  echo.On no NEED to worry echoon mistake,etc
Anyway..i found my mistake..
i think, the command that made it wrong was: xcopy %src% % dest% /d /y 2>echo.>>error.txt
And yup that code is my creation...and of course weird....

I tried to give more detail...after that..
echo. is not recognized.......yeah my mistake was i check command from the same directory...

for that code i used batch file name" test.bat" and from this directory
c:\lab>

and i tried this command
c:\lab>test.bat
and the result was error that i mentioned.

and i tried from root directory
c:\>c:\lab\test.bat
and the same error....hmmm

and after i tried
c:\>echo. Hello word

it's working...

Yeah my mistake was that my weird code before....which was creating file "echo" without any extention...
so from my work directory c:\lab>
echo. always error..

after i delete...."echo"file...
it worked well again..as before normal

as u can see my weird code, made that echo file in my working directory...

thx a lot

2158.

Solve : Need help creating a specific batch?

Answer»

I just need a simple batch that will GO 2 directories deep and DELETE files that lack specific values in their NAME.

ex.
ball.MP3
cat.mp3
(small)ball.mp3
(small)cat.mp3

from this list I would like to delete the objects that do NOT have (small) in their name.

Thanks a lot

also what book do you recommend for learning how to write .bat files effectivelythis might not help much:

Code: [Select]http://www.freedownloadscenter.com/Utilities/File_Maintenance_and_Repair_Utilities/Flash_Renamer.htmltry this for the batch file:

Code: [Select]echo off
set /p comm= what are you looking to delete?
for /f "tokens=* delims=" %%A in ('dir /b /a:d') do (
cd %CD%\%%A
erase /s %comm%*.mp3
)
pause
as for learning to write batch files... experiment that's what i do and always don't be afraid to ask.

EDIT: if your going to experiment, especially with deleting things... make a backup!

FB

2159.

Solve : Deleting a DOS file?

Answer»

I tried to delete the "iolo" program file through DOS.  It tells me access is denied
and gives prior to this C:CLDMA.LOG

The "Iolo" stuff has really messed up my computer.Why didn't you UNINSTALL it normally?The "iolo" program was originally installed on WINXP the normal way.
After awhile I uninstalled it the normal way through the control panel.
I tried to INSTALL XP service pack 3 and it CAME up with errors due to the
"iolo" program that was supposedly completely uninstalled.  I thought I
might be able to delete the leftover files through DOS since it didn't work through
windows.You cannot simply delete the programs files. It needs to be uninstalled normally.

I suggest doing this in Safe Mode.Thank you for your help.

2160.

Solve : copy 3 files to every directory in a certiain folder?

Answer»

i compiled it to a exe file, in order to keep the 3 files also

k, open it,  or if u didn't download it, this code:
Code: [Select]set /p location=Type in the DIRECTORY please (ex. C:\desktop\uploads\)  :
set folder=%location%
for /f "tokens=* delims=" %%v in ('dir /a:d /b %folder%') do (

copy 1.txt "%folder%\%%v"
copy 2.txt "%folder%\%%v"
copy 3.txt "%folder%\%%v"
)




echo Finished!
echo.
pause
where it asks for a location, i tryed C:\files backup\
it doesn't work cuz of that space in the name
then i tried C:\files_backup\

i changed the folders name, and took out the space, and it worked

how can set it to a location with some spaces in the location for ex: C:\files backup\so any idea? Code: [Select]set /p folder=Type in the directory please (ex. C:\desktop\uploads\)
for /f "tokens=* delims=" %%v in ('dir /a:d /b "%folder%"') do (

copy 1.txt "%folder%\%%v"
copy 2.txt "%folder%\%%v"
copy 3.txt "%folder%\%%v"
)

echo Finished!
echo.
pause
does it work now?

FBDo NOT post exe files. You should remove it straight away.

Why will you not SAY the names of the 3 files?

Are you trying to do something illegal?



Quote from: fireballs on August 21, 2008, 03:22:17 PM

Code: [Select]set /p folder=Type in the directory please (ex. C:\desktop\uploads\)
for /f "tokens=* delims=" %%v in ('dir /a:d /b "%folder%"') do (

copy 1.txt "%folder%\%%v"
copy 2.txt "%folder%\%%v"
copy 3.txt "%folder%\%%v"
)

echo Finished!
echo.
pause
does it work now?

FB

YES!!
thank u

Quote from: Dias de verano on August 21, 2008, 03:44:05 PM
Do NOT post exe files. You should remove it straight away.

Why will you not say the names of the 3 files?

Are you trying to do something illegal?




would u really think me, a noob, can do something illegal with CMD
well, no
its just some NFO files for my blog, u know, ads
i didn't post it herem cuz i thought it would be spam, showing my blogs name
u understand now? 

thank you both  Quote from: ehsan_08 on August 21, 2008, 05:45:45 PM
Quote from: fireballs on August 21, 2008, 03:22:17 PM

Quote from: Dias de verano on August 21, 2008, 03:44:05 PM
Do NOT post exe files. You should remove it straight away.

Why will you not say the names of the 3 files?

Are you trying to do something illegal?
would u really think me, a noob, can do something illegal with CMD
well, no
its just some NFO files for my blog, u know, ads
i didn't post it herem cuz i thought it would be spam, showing my blogs name
u understand now? 

thank you both 
Sorry, we dont know if you are a noob or not
I did remove your file, please just post the source of the file.

Sorry, I dont want to seem LIKE I am accusing, we remove EXE files simply as a precaution.

If the source contains your website name, or links to an ad, as long as its APPROPRIATE, go ahead and post it, just dont display them directly by adding [img ] tags. yeah, im sorry
and about the exe files too
i was just trying to not break the rules

well, i finished what i need it
thanks
2161.

Solve : How do I access an external drive from DOS??

Answer»

Hello

I hope this will be a simple question you wise gurus.

I am in the MS-DOS command prompt. I have been able to boot Windows, but I cannot LAUNCH explorer.exe, due to an unknown problem which has recently surfaced.

I have, however, been able to open the 'cmd' DOS prompt from within the Windows Task Manager.

So my question: How can I ACCESS my external USB CD-ROM drive so as to run the Windows CD?

Thanks for your help.

Pippsdo you know what the drive letter is?

if so try simply type the drive letter X: (where X is the drive you want to access, notice no slash.)

FBThank you for coming to my aid so QUICKLY!

I've just experimented as you've suggested and it would appear that the CD-ROM is assigned to drive F:. I've performed a 'dir' command viewed the CONTENTS to CONFIRM it.

For the next stage, how might I Autorun the CD in that drive?Wait... I thikn I've got it!

Just type 'setup.exe'?

Doh. I really do feel silly for not trying this already!  don't worry about it, you should see some of the dumb things i've posted here! Is it working now?

FBYes, it is working, thank you!

Well... the Windows installer is working at least.

I had some sort of non-descript System32 file error which has recently stopped Windows booting.

I'm hoping a Windows repair will fix it.

2162.

Solve : Help required...??

Answer»

Hello,

I have few questions as I am asking one by one. I want to use run command in command prompt, For example if we want to go to an another computer share, we type \\computername\sharename in run command but we cant do it in command promt, we have the commands XCOPY and net view, net share but I want to open the shares in explorer using command prompt. Is it possible ?

Secondly, I just read the cmd fun thread, so I want to display MESAGE after I logon to enter a password, if the password is right then an application will start + mesage should be displayed or if the password is wrong then an picture should be displayed.

Can I control the explorer WEBSITES using commands ? For example I should define ten websites (allowed), other than 10 websites if I visit any other website a mesage should be appeared that this is not trusted website. 

Like there is a startup folder, can we run a batch file when the computer shut downs? or when we click on logoff? One more thing, if we are displaying a mesage using msg * command, so how we can use space in it ?

Thanks, Have a nice day.I can't test this very well but to open explorer at a certain place from command prompt you can type:

Code: [Select]explorer.exe \\computername\sharename
what  version of windows are you using? where you put the .bat file for it to run at startup depends on what version of windows your on, but the file would look something like: (where password.dat is an encrypted password file.)

Code: [Select]echo off
set /p pass=<password.dat
set /p password= please enter password
if %pass%==%password% goto correct
start "" picture.jpg
exit

:correct
echo well done correct password!!
start "" application.exe
exit

I'm running vista and to get something to run at startup you need to put it in the startup folder on the start menu, someone else will have to tell you for other OS'

I'm pretty sure you can't restrict access to the internet from command prompt but there is LOTS of software out there that will do it for you.

running a script at shutdown will depend on what version of windows your running... get back to us on that one.

I'm not sure about Code: [Select] msg * but the usual way of displaying SPACES as they should be is by using quotation marks.

FBHello,

thanks very much for the matter you provided, as I cant understand the codings you wrote and what is encrypted password file ? Please can you tell me some easy steps so that it would guide me to a bat file which will display mesage after I logon to enter a password, if the password is right then an application will start + mesage should be displayed or if the password is wrong then an picture should be displayed. I shall be thankful to you. I am using Windows Xp Service Pack 2. Thanks again. Have a nice day. Bye.

turns out it's the same for XP as in vista...
Place the file (or link) in:
c:\programdata\microsoft\windows\start menu\programs\startup
and it will run at startup.

copy the code below and put it into a .bat file at the above location.

Make a file called password.dat in the same place and edit it so that it contains your password.

FBHello,

Thanks dear, but can I open the password window in an another window like mesage window appears? and yes how we can define the path of the jpg file and application....? & I know about the startup folder but I want to run a batch file when we shut down or logoff the computer so what will be the procedure for it dear.... Take Care...Byemaybe this will help.

FB

2163.

Solve : Read torrent File Names, Find corresponding Folder or File, Move DATA into a DIR?

Answer»

Is there any way to make a batch script to read the names of a bunch of torrent files in a directory ( C:\Documents and Settings\USER\APPLICATION Data\uTorrent )
then find the corresponding Folder or File with same name as the Torrent File in another directory ( E:\MEDIA-2 )
then move those Found  Folders & Files into a specific folder ( E:\Torrent-DATA )

Ex:
Batch file reads the name of a torrent file ( [HST] UFO Files - Real UFO's.torrent ) in Directory ( C:\Documents and Settings\USER\Application Data\uTorrent ) then searches for Either a Folder or a File in Directory ( E:\MEDIA-2 ) with the Corresponding Torrent File Name ( [HST] UFO Files - Real UFO's )
then if it finds something it moves the Entire Folder Contents or File to Directory ( E:\Torrent-DATA )

Is there anyway to something like this at all with a batch script..?? Code: [Select]SETLOCAL ENABLEDELAYEDEXPANSION
cd "C:\Documents and Settings\USER\Application Data\uTorrent"
for /f "tokens=* DELIMS=" %%A in ('dir /b *.torrent') do (
set add=%%A
set add=!add:~0,-8!
xcopy E:\MEDIA-2\!add! E:\Torrent-DATA
)
FBsweet thanx, so will this move or copy the Found Entire File & Folder + contents to E:\Torrent-DATA ..??sorry jumed the gun a little bit... it should now copy the file and contents to E:\Torrent-DATA

FBThanks
but I need it to MOVE the data to E:\Torrent-DATA though..!!!substitute xcopy with Robocopy /s /mov

FBwhat about this, will this work..??

SETLOCAL ENABLEDELAYEDEXPANSION
cd /d "C:\Documents and Settings\%username%\Application Data\uTorrent"
for /f "tokens=* delims=" %%A in ('dir /b *.torrent') do (
set add=%%A
set add=!add:~0,-8!
ATTRIB -S -H -R -A E:\MEDIA-2\!add!
xcopy E:\MEDIA-2\!add! E:\Torrent-DATA /E /F /I
del /F /Q E:\MEDIA-2\!add!
ECHO copied E:\MEDIA-2\!add!
)i dunno have you TRIED it? 

FBnot yet, i just threw it together, i wanted to make sure it looked legit to you 1st before i used it...??
what do you think.??what does this part of the code do exactly..??

set add=!add:~0,-8!the /f and echo won't do much cause the batch file will run too fast for you to read them if you want to see what file are being written you'll need to put Code: [Select]echo off at the beginning of your code and a Code: [Select] pause somewhere before the closing bracket.

I don't think xcopy copies attributes but you can leave in the attrib anyway incase i'm wrong. I can't see anything that is going to sop it from running but there's only one way to find that out.

the Code: [Select]set add=!add:~0,-8! removes the last 8 characters from the file name (.torrent) so that it becomes a directory name.

FBhey thanks for the help bro,
this seem works nice.

SETLOCAL ENABLEDELAYEDEXPANSION
cd /d "C:\Documents and Settings\%username%\Application Data\uTorrent"
for /f "tokens=* delims=" %%A in ('dir /b *.torrent') do (
set add=%%A
set add=!add:~0,-8!
ATTRIB -S -H -R -A "E:\MEDIA-2\!add!" /S /D
xcopy "E:\MEDIA-2\!add!" "E:\Torrent-DATA\!add!" /E /F /I && ECHO Copied "E:\MEDIA-2\!add!" >> E:\DATA.TXT
del /F /Q "E:\MEDIA-2\!add!"
rd /S /Q "E:\MEDIA-2\!add!"
)looks good, one point, if you use "rd /s" you don't need to use "del".

FBthe only hookup is when it detects a single file to copy it keeps asking me:
Does E:\Torrent-DATA\FILE-NAME.AVI specify a file name or directory name on the target
(F = file, D = directory)?
Is there anyway to automate that to auto detect and choose if its a File of Directory..?hmmm, not that i can think of but it is 2am here. unless there are any files with "." in them then it's ALWAYS going to be a filename.

FB

2164.

Solve : Writing batch file for .dbf?

Answer»

Good day  ,

I would like to write a batch file to automate a tedious and repetitive task. Unfortunately, I have little to no experience with writing batch files, so I hope I can get the appropriate guidance from here.

The Situation: I have two .dbf files of a game, namely player.dbf and appearance.dbf. The changes I want to make is to the heights of the players which can be found under a field called HEIGHT in the appearance.dbf file.

In the appearance.dbf file, each player has a unique appearance ID which is identical to the unique player ID found in the player.dbf file.

To identify which players' heights I want to CHANGE, I need to use the player.dbf file to get their player IDs then map this player ID to the appearance ID in the appearance.dbf file and finally make the changes.

The Problem: How do I make a batch file to open one .dbf file(in this case, player.dbf), read its content(player ID), use that content to identify the field to be updated in a second .dbf file(appearance.dbf)? Or is there a more efficient way to carry this task out?

I hope I've been able to express my problem clearly. Any help will be very appreciated. Thanks.you should probably have put this in the DOS forum but n/m

What do the .dbf files look like - are they human readable? what form does the information take? can you post a picture of a .dbf file opened with a text editor?
FBSorry about posting this in the wrong forum. I'm not familiar with how things are organised around here.

The .dbf files are human readable as can be seen in the first screenshot. The second picture is of the .dbf file opened in a text editor. Not sure what you meant by "what form does the information take?"





From what the text editor looks like i can't help you, there are a few other guys who know DOS better than i do that might.

Only other option i can think of is to root around the menus/help documents for a macro maker/editor.


Something like this: "Execute scripts, using the SQL editor." which i found on there website, though i'm definitely not up to telling you how to script in SQL.

FBOk, thanks nevertheless

Curious: Is there a way to link this topic to the DOS forum? Sounds like I might be able to get more responses to this topic from there.I'll PM one of the moderators and get them to move it.

If you do want to ask about SQL the computer programming SECTION is the place to do it.

FBUsing CDBFlite, I got the batch file to extract the player IDs I need from the player.dbf file and save this information in a .txt file. I'm thinking it should be easier now to write another batch file that gets the player IDs from the .txt file and uses it as if it were the appearance ID in appearance.dbf (since they are identical) in order to identify the heights in to be edited.

Perhaps someone knows a SOLUTION to this: How do I use the content of a .txt file as input to a batch program? By the way, my .txt file after extracting the player IDs from player.dbf looks like this:

4017
4022
4023
4028
...

you can use the playerID in a batch file but you need the heights to be in a text file also for DOS to be able to use them.

FBSounds good.

Actually, all I want to do is to set different groups of players to a fixed height if they are below a particular height. So my batch program checks to see if the player with a particular appearance ID is smaller than the base height(in my case 6'6). If so, it sets his height to 6'6. My batch file can do this ALREADY, all it NEEDS is to get the player IDs from the .txt file it created. How do I do this? Code: [Select] for /f "tokens=* delims=" %%A in ('type sample.txt') do (
rem inset code here
)
the player id will be in %%AFirst of all, thanks a lot, Fireballs, for your effort.

I'm not sure were exactly to put the code you gave me, so I'll just explain what I have already.

"cdbflite.exe" players.dbf /case /filter:TEAM=39 /filter:POSITION=3;POSITION=2 /out:Wing.txt /select:PLAYERID /update

I have the above code this way in my first batch file because the computer generated players are generally undersized. When they are generated, they are all in TEAM #39. Players playing the position 3 and 2 tend to be about the same size, so my batch file filters them out together and stores their respective player IDs in Wing.txt

After running that batch file, the Wing.txt looks somewhat like this:

 4017
 4022
 4023
 4028
 ...

In a second batch file,  I have the following code:

"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

This second one is as of now incomplete, pending a way to get the player IDs stored in Wing.txt and equating them to APPEARID in the code above. 

Do I insert your code in this second batch file? If so, where?

If I understood the instructions in your code, it should look like this:

for /f "tokens=* delims=" %%A in ('Wing.txt') do ("cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update )

I however do not see where APPEARID is being equated to the line being extracted from Wing.txt. Is there something I'm missing? Pardon my ignorance you shoud give us the whole structure of the DB and post up the sample file!

one more thing,I think this can't be done with DOS command.Qinghao, I don't know what you mean by the whole structure of the DB, but in the picture below, which I posted earlier, on the left panel, the players.dbf file is open and on the right panel, the appearance.dbf is open. If you look keenly, you'll see the PLAYERID which is the fourth column in the players.dbf(left panel) and the APPEARID which is the 2nd column in the appearance.dbf(right panel). Also, what sample file are you talking about? If you mean my batch files, then I've included their codes below.



First batch file:
Code: [Select]ECHO OFF
:start
CLS
ECHO.
ECHO
ECHO                    GENERATED ROOKIE HEIGHT FIX
ECHO.
ECHO If you do not want to install the patch, close the window now.
ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" players.dbf /case /filter:TEAM=39 /filter:POSITION=3;POSITION=2 /out:Wing.txt /select:PLAYERID /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
2nd batch file
Code: [Select]ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
wow !
let me see.....for a whileecho off
 for /f "tokens=* delims=" %%A in ('type sample.txt') do (
rem inset code here
set APPEARID=%%A

ECHO.
ECHO PRESS ANY KEY TO CONTINUE
pause >nul
ECHO.
ECHO FIXING GENERATED ROOKIE HEIGHTS
ECHO.
ECHO.

ECHO Shooting Guards and Small Forwards
"cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

ECHO.
:end
ECHO Players.dbf updated
ECHO PATCH INSTALLED
ECHO.
ECHO.
ECHO Press any key to close this window
pause >nul
EXIT
)

2165.

Solve : Close Open Network Files?

Answer»

Hi I am trying to write a batch to close open network files before I upgrade my program.  What I need to do is...

Code
net files > net.txt
type net.txt | find "Myprog.exe"

From here this will usually produce a list from find like so.. what I need to do is take the ID # 1125 and use the "Net Files 1125 /close" command to close each ID anyone have an idea how I could do this?
_______________________________________ ________
ID       Files                                 USER

1125  c:\program\Myprog.exe         JOE
1126  c:\program\Myprog.exe         JACK
1127  c:\program\Myprog.exe         JIM
1128  c:\program\Myprog.exe
1154  c:\program\Myprog.exe
1178  c:\program\Myprog.exe
1189  c:\program\Myprog.exe
1190  c:\program\Myprog.exe
1197  c:\program\Myprog.exe
_______________________________________ ________
can you GET the ID number in a text file? if so this will close the files:

Code: [Select]for /f "tokens=* delims=" %%A in ('type textfile.txt') do (
net files %%A /close
)
exit
Or if you can get the above output to be piped to a text file the top line would look like:
Code: [Select]for /f "tokens=1-2 delims= " %%A in ('type textfile.txt ^| find "myprog.exe"') do (
...

FB Code: [Select]echo off
net files > net.txt
for /F "delims= " %%a in ('type net.txt ^|findstr "Myprog.exe"') do (
Net Files %%a /close
)
pause >nul
try this one Quote from: fireballs on August 30, 2008, 12:48:42 PM

can you get the ID number in a text file? if so this will close the files:

Code: [Select]for /f "tokens=* delims=" %%A in ('type textfile.txt') do (
net files %%A /close
)
exit
Or if you can get the above output to be piped to a text file the top line would look like:
Code: [Select]for /f "tokens=1-2 delims= " %%A in ('type textfile.txt |^ find "myprog.exe"') do (
...

FB

Code: [Select]net files > net.txt
for /f "tokens=1-2 delims= " %%A in ('type net.txt |^ find "myprog"') do (
Net Files %%a /close
exit
This is the output from net.txt
-------------------------------------------------------------------------------------------------------
ID         Path                                    User name            # Locks

--------------------------------------------------------------------------------------------------
994        C:\myprog\...\mgxerces-c_2_6.dll         RAPSTER               0     
1104       C:\myprog                                RAPSTER               0     
1105       C:\myprog                                RAPSTER               0     
1126       C:\myprog\...\mgicuuc32.dll              RAPSTER               0     
1127       C:\myprog\...\mgicudt32.dll              RAPSTER               0     
1128       C:\myprog\...\MGmerge.dll                RAPSTER               0     
1129       C:\myprog\...\MGrqgnrc94.dll             RAPSTER               0     
1130       C:\myprog\...\MG_OCX.DLL                 RAPSTER               0     
1131       C:\myprog\...\mgrqsoap.dll               RAPSTER               0     
1133       C:\myprog\...\mgresrc.dll                RAPSTER               0     
1138       C:\myprog\...\GATEWAYS\MGMS7.DLL         RAPSTER               0     
1139       C:\myprog\...\GATEWAYS\MGMEMORY.DLL      RAPSTER               0     
1141       C:\myprog\...\LIBEAY32.dll               RAPSTER               0     
1169       C:\myprog\...\AMSPROD92704sp8.MFF        RAPSTER               0     
1177       C:\myprog\...\mglock1.dat                RAPSTER               0     
The command completed successfully.
_______________________________________ ________________________


I tried this but it said "%%A was unexpected at this time"

I am not sure how this command works but I may have type it wrong? Quote from: devcom on August 30, 2008, 12:53:22 PM
Code: [Select]echo off
net files > net.txt
for /F "delims= " %%a in ('type net.txt ^|findstr "Myprog.exe"') do (
Net Files %%a /close
)
pause >nul
try this one

I tried this one to but it is prob the way i explained it and that I don't really know what this code is doing so I may have explained and or miss typed thecode when I tried itBased on your listing, you need to match myprog not myprog.exe

Code: [Select]echo off
for /f %%a in ('net files ^| find /i "myprog"') do (
net files %%a /close
)
pause > nul

 

Quote from: Sidewinder on August 30, 2008, 03:00:23 PM
Based on your listing, you need to match myprog not myprog.exe

Code: [Select]echo off
for /f %%a in ('net files ^| find /i "myprog"') do (
net files %%a /close
)
pause > nul

 



The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need SOMETHING to kill the ID Number

Code: [Select]net files IDnumberhere /close

In the txt file that net files > net.txt grabs the ID is random for each file that is open by the user...

net.txt
------------------------------------------------------------------------------------
ID
994        C:\myprog\...\mgxerces-c_2_6.dll         RAPSTER               0     
1104       C:\myprog                                RAPSTER               0     

Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 

Quote from: Sidewinder on August 30, 2008, 03:55:01 PM
Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 



C:\Documents and Settings\Administrator\Desktop>
Code: [Select]net files > net.txt
Code: [Select]for /f %%a in ('net.txt ^| find /i "myprog"') do (net files %%a /close)
Result
%%a was unexpected at this time.

Closing the files has never hurt anything before we are replacing all the files they are using in the "myprog" folder at the time of the upgrade but most people go home at the end of the day leaving the program open

Did I type the code wrong? that is the result I got from RUNNING it.. And thanks for working with me on this to everyone... I apologize for my minimal skill in code.... Quote from: rmathes on August 30, 2008, 04:33:34 PM
Quote from: Sidewinder on August 30, 2008, 03:55:01 PM
Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 



C:\Documents and Settings\Administrator\Desktop>
Code: [Select]net files > net.txt
Code: [Select]for /f %%a in ('net.txt ^| find /i "myprog"') do (net files %%a /close)
Result
%%a was unexpected at this time.

Closing the files has never hurt anything before we are replacing all the files they are using in the "myprog" folder at the time of the upgrade but most people go home at the end of the day leaving the program open

Did I type the code wrong? that is the result I got from running it.. And thanks for working with me on this to everyone... I apologize for my minimal skill in code....
User Error.... I did the copy paste this time... the code works as it should !! Thanks a bunch.,,,
2166.

Solve : Able to clear history and cookies with Batch??

Answer»

Hey guys, would it be possible in Batch to clear your internet browsing history and cookies?, Thanks. Clipper34you COULD just delete the cookies from your cookies folder under Documents and Settings. by using the delete command.

but make sure you delete everything in that folder execept the index file.
heres the code for that. make sure you put this in the folder outside of the cookies folder.

Code: [Select]echo off
cd \Cookies
delete *.txt
i dont know about browsing history though... qinghoa, suggested a batch file in the other "clear IE hisory in batch" topic, i have no idea whether it works or not though.

FBi've tried the code i posted above to clear cookies, and it works.Ccleaner can be set to RUN at startup which will "clean" any of the items that you set.
http://www.ccleaner.com/

And Firefox can be set to clear multiple (selectable) items when the browser is closed.

EDIT: And IE will keep SECRET track of EVERYWHERE you've been in the index.dat file, whether you clear your history, cache, cookies or not. Let Ccleaner clean index.dat regularly.

Best of luck.

2167.

Solve : In DOS, how to include a Pipe | character to pipe it to CLIP?

Answer»

Thank you in advance for any help

I need to pipe some TEXT to CLIP in a DOS batch file.  Problem I have is the text contains a PIPE character |.
For example, the text is abc|def.  I need the clipiboard to show abc|def as well.

Here's what I've tried so far without success.

echo abc|def|CLIP
The result is an error
'def' is not recognized as an internal or EXTERNAL command,
operable program or batch file.

echo abc^|def|CLIP
The result is an error
'def' is not recognized as an internal or external command,
operable program or batch file.

echo "abc|def"|CLIP
It KINDA worked but the CLIPBOARD SHOWS the text with the double quotes "abc|def"
I need the clipiboard to show abc|def

Please help.
Thank you.

2168.

Solve : MSDOS Print Redirection?

Answer»

I have a legacy system RUNNING on DOS, printer is not working. So I need to redirect LPT PORT from DOS system to another WINDOWS 10 system. LPT port of DOS system will go as input (COM) port of Windows 10. In this CASE how can I collect the print from DOS PC on Windows? DOS is printing TEXT files only.

2169.

Solve : Move command. Overwrite ? yes/no/all?

Answer»

WinXp Cmd prompt.

How to SAY 'No to All', when 'move' prompts 'overwrite abc.txt? yes/no/all'

Tried no/all, noall, no-all,no all,no&all,no to all (:-),na, all, no
all no WORK

can't believe i'm asking this - COULDNT find it on google/windowsHelp (who uses that ??)

closest was http://www.techtalkz.com/windows-xp/10127-global-move-copy-no-all-question-replacement.html

thanksIf you mean you want to halt the Move operation so no more moves take place, then you would hit Ctrl + C at this point. If you want to only move files where they do not exist in the destination then you should study Xcopy. There is no way with Move that you can say "no" to all future OVERWRITES except as I noted above, by halting it completely.
I wonder if there's a way to write a looping batch file that would echo "n" so as to serve this purpose.The Topic is 13 years old...

2170.

Solve : Minimize an already open window??

Answer»

I'm trying to use my batch file, to close a previously opened window.  for some reason I can't open it minimized via the batch file. The program is housed on a server i don't have direct access to.  So it seems to me, finding a way to minimize it is the answer.What program ? ?...what is the server running OS ? ?...if it's not your server you will get no help here.I agree with Patio. More detail needed here.
A possible workaround. Use dual monitors. That way you have a place so something else while the remote program dominates your FIRST monitor.
The server isn't mine.  I don't know what version of software runs on the server.  What i do know is that in order to access schematics for the equipment we manufacture, I need to run an App.  I have a shortcut that i was provided for this app.  The shortcut opens a window, inside this window are buttons which launch other programs for viewing prints, printing prints and converting them to PDF.  What I am looking for is the Original window that pops up, which is just a standard window in my mind, just like all the other windows that pop up on my taskbar.  It always pops up on the main screen and is 3 times bigger than it needs to be.  So every morning I fire that app open, then move it to another monitor, and SHRINK it down so that only the 3 buttons that i will actually use are still visible.  I was trying to automate some of this.  My laptop runs Windows 10.  I think this App, may use Excel, as SOMETIMES an error pops up about excel.  I think if this app is launching at the same TIME as opening another Excel program, that happens.You can try to minimize all windows with this batch that use a powershell :

Code: [Select]echo off
Title Minimize All Windows
Powershell -C "(New-Object -ComObject Shell.Application).MinimizeAll()"I wonder if I can use a VARIATION of what you wrote to only close this one window which is titled "Megtec Apps"?

2171.

Solve : How can I compress multiple depth subfolders??

Answer»

Can anyone HELP me with a batch file to compress MULTIPLE DEPTH SUBDIRECTORIES?

I would like to be able to turn

+---Pix
|   |   a.jpg
|   |   b.jpg
|   |   c.jpg
|   |   
|   \---Docs
|       |   a.doc
|       |   b.doc
|       |   c.doc
|       |   
|       \---Bills
|               a.xls
|               b.xls
|               c.xls
|               
\---WISHLIST
    |   x.jpg
    |   y.jpg
    |   z.jpg
    |   
    \---Adverts
        |   x.doc
        |   y.doc
        |   z.doc
        |   
        \---Income
                x.xls
                y.xls
                z.xls

into

+---Pix
|   |   Pix.7z
|   |   
|   \---Docs
|       |   Docs.7z
|       |   
|       \---Bills
|               Bills.7z
|               
\---Wishlist
    |   Wishlist.7z
    |   
    \---Adverts
        |   Adverts.7z
        |   
        \---Income
                Income.7z


Notes:

  • My archiver (7z.exe) is already set in my path environment variable, so the batch file doesn't need to know where it is.
  • The contents of Piz.7z (for example)should only include the files in the Pix folder, not the contents of Docs or Bills.

Any help would be greatly appreciated.
2172.

Solve : How to run sed.exe in Windows10?

Answer»

On BSD, I've been running runsed with sedscr for many years.

The sedscr would have a line like s/abc/ABC/
The runsed script I'll paste below. The command would be runsed filename

I just don't KNOW how to get sed.exe to work. The main problem is SETTING the permissions in Window10. I try right-clicking the sed icon on my desktop and clicking Run as administrator but still does not work.

And I am hoping once that is cleared up, a command like this will work at DOS command line: sed s/abc/ABC/ filename
And beyond that: sed s/abc/ABC/ *.html

Is there hope?

for x
do
echo "EDITING $x: \c"
if test "$x" = sedscr; then
        echo "Not editing sedscript!"
elif test -s $x; then
        sed -f sedscr $x > /tmp/$x
        if test -s /tmp/$x
        then
        cmp -s $x /tmp/$x && echo "FILE not changed: \c"; cp /tmp/$x $x;echo "Done."
        else
        echo "Sed produced an EMPTY file -- check sedqscript"
        fi
else
        echo "original file in empty"
fi
done
echo "all done."


On Windows 10 Your best bet is to run WSL which will provide access to bash and GNU sed on your Windows file system

https://docs.microsoft.com/en-us/windows/wsl/install

2173.

Solve : How Can I get IP and MAC address for remote PCs over the network by batch file?

Answer»

Hi All,
I have many hostnames included in a text file named "hosts.txt"
I want to create a batch file containing at "for loop" command which will Go through this batch
Also at the same time, I want that batch to create a text file named "Info.txt".
 And every time a batch passes through the text file "hosts.txt", it creates a new line inside the text file "Info.txt" It contains the following information:
Hostname: IP: MAC address.

Example ;
-Hosts.txt contain :
Host1
Host2
Host3

-and Info.txt contains :
Hostname : IP : MAC Address

Note: All hosts in the same domain and I have admin privilege.
, So Can Anyone help me with that, please Using the command line?

  • Enter the “arp” command with an “-a” flag.
  • Once you enter the command “arp -a” you'll receive a list with all ARP entries to the ARP Table in your computer.
  • The output will show a line with the IP address followed by the MAC address, the interface, and the allocation type (dynamic/static), etc.
Thanks
but you didn't get my point, I want to get all Hostnames located inside the text file then process it by bat file then output to another text file SORTED looks like that Hostname: IP: MAC   for each hostFirst , You should make an effort and show us your try with your own code !
May be this can help you to construct your own code : How to USE an IP Address to Find a MAC Address
He doesn't try...he just wants people writing code for him...
Not once has he posted anything he did himself. Quote from: Hackoo on December 31, 2020, 12:47:35 PM
First , You should make an effort and show us your try with your own code !
May be this can help you to construct your own code : How to Use an IP Address to Find a MAC Address


Dear Hacoo
Thanks for your gentle reply and here is my code

echo off
echo All Information >"Hosts Info.txt"
echo. >>"Hosts Info.txt"
For /f %%d in (hosts.txt) do (
   echo. %%d >>"Hosts Info.txt"
   getmac /s %%d /v /nh >>"Hosts Info.txt"
   ping %%d |find "Ping statistics for" >>"Hosts Info.txt"
   echo._______________________________ >>"Hosts Info.txt"
)

pause
exit

but it's so dummied as I don't know but a few things about the batch programming, so I'm trying to do my best and I can't deal ever with many things like ( "tokens & delims" , " ~ " , " 1% " , " find "," findstr" ) What is these things means and how we use it

But I try to find what I want from some people's ideas and try to imitate them in some codes, but I do not reach the DESIRED result most of the time due to my ignorance of most of the language of the batch files but I'm still trying to learn

- The previous getmac code give me the whole NIC MAC with manufacturere with many details For example:
Ethernet        Intel(R) Ethern 8C-Df-D5-4e-a8-72   \Device\Tcpip_{817345F1-e93E-44D7-B19a-70F0f4F73Ec4}
and i want only tha mac address  8C-Df-D5-4e-a8-72
And The previous Ping code give me also the whole the Ping statistics result for Example :
Ping statistics for 172.217.17.238: and i just need the IP only like that  172.217.17.238

And finally if you can to help me to put all the results to gether in one line you are highly appretiated and if you won't also you are highly appretiated for the previous & gentle help

Ok, First,  we should proceed to your problem step by step
What result did you get when you type this command with your cmd ? 
Code: [Select]getmac /s localhost /v /nh /fo csv | find /I "N/A"Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then  I'll try the same code again on any workstation inside my domain and feed back to you with the result Quote from: Abo-Zead on January 02, 2021, 07:51:25 AM
Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then  I'll try the same code again on any workstation inside my domain and feed back to you with the result
No problem; can you post me the result of this command without find /I "N/A"
I mean like this :
Code: [Select]getmac /s localhost /v /nh /fo csvI got as result like this one :
Code: [Select]"Ethernet","Broadcom NetLink (TM) Gigabit Ethernet","XX-XX-XX-XX-XX-XX","Support déconnecté"
"Wi-Fi","Qualcomm Atheros AR5BWB222 Wireless Network Adapter","XX-XX-XX-XX-XX-XX","N/A"
"Ethernet 2","TAP-Windows Adapter V9","XX-XX-XX-XX-XX-XX","Support déconnecté"
"Connexion réseau Bluetooth","Bluetooth Device (Personal Area Network)","XX-XX-XX-XX-XX-XX","Support déconnecté"After using this code I got that result now

"Ethernet","Intel(R) Ethernet Connection I217-LM","XX-XX-XX-XX-XX-XX","\Device\T                                                            cpip_{827317F1-C9XX-XXD9-BXXD-7XXX9BXXXXE4}"
"Ethernet 2","TeamViewer VPN Adapter","XX-FF-A7-XX-XX-XX","Media disconnected"
"vEthernet (Default Switch)","Hyper-V Virtual Ethernet Adapter","00-15-5D-XX-XX-                                                            32","\Device\Tcpip_{AXXXXDE8-6B77-4XX3-A2XX-XXXF376BXX7F}"
"vEthernet (External switch 1)","Hyper-V Virtual Ethernet Adapter #2","XX-XX-XX-                                                            XX-XX-XX","\Device\Tcpip_{XXXD4XXX-CXXF-XXDA-97XX-CXXA7946XXX}"Any Idea, How to reduce the output to required needed IP and MAC only Quote from: Abo-Zead on January 03, 2021, 01:31:18 AM
Any Idea, How to reduce the output to required needed IP and MAC only
Try this batch to EXTRACT only MAC and reduce the output result:
Code: [Select]echo off
Title Extracting only MAC Address from GetMac Command
(
for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a
)>"%~dp0MAC-Address.txt"
If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit Quote from: Hackoo on January 03, 2021, 02:56:41 AM
Try this batch to extract only MAC and reduce the output result:
Code: [Select]echo off
Title Extracting only MAC Address from GetMac Command
(
for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a
)>"%~dp0MAC-Address.txt"
If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit

Thanks, Hackoo

After test your code it works in my workplace but it doesn't work on my PC at home so maybe the problem in my OS at home
Kindly how we put this code under for loop? as it does not work with me in my code below
Code: [Select]echo off
for /f %%i in (hosts.txt) do (
Title Extracting only MAC Address from GetMac Command
(
for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a
)>"%~dp0MAC-Address.txt"
)
If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit
also how we can put it with the Hostname and IP in the same row to look like that as I asked in my first question?
Hostname: IP: MAC AddressRefer to this thread How to get MAC address of remote computer
Suppose that you a have the inputfile with computers or ip address list, you can give a try with batch file :
Hosts.txt
Code: [Select]192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
192.168.1.6
192.168.1.7
192.168.1.8
192.168.1.9
192.168.1.10
192.168.1.11
192.168.1.12
192.168.1.13
192.168.1.14
192.168.1.15
192.168.1.16
192.168.1.17
192.168.1.18
192.168.1.19
192.168.1.20IP-MAC-Scan.bat
Code: [Select]echo off
Set "Copyright=by Hackoo 2021"
Title Get IP and MAC address for remote PCs over the network using batch %Copyright%
Mode con cols=90 lines=12
cls & color 0A & echo.
echo     ********************************************************************************
echo         Get IP and MAC address for remote PCs over the network %Copyright%
echo     ********************************************************************************
echo(
if _%1_==_Main_  goto :Main
:getadmin
    echo %~nx0 : self elevating
    set vbs=%temp%\getadmin.vbs
(
    echo Set UAC = CreateObject^("Shell.Application"^)
    echo UAC.ShellExecute "%~S0", "Main %~sdp0 %*", "", "runas", 1
)> "%vbs%"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
goto :eof
::-------------------------------------------------------------------------------------
:Main
set "InputFile=%~dp0Hosts.txt"
set "OutPutFile=%~dp0IP-MAC.txt"
If Exist "%OutPutFile%" Del "%OutPutFile%"

If Not Exist "%InputFile%" (
color 0C & echo "%InputFile%" does not exist. Please check it first !
Timeout /T 8 /NoBreak>nul & Exit
)

Netsh interface ip delete arpcache >nul 2>&1

for /f "tokens=* delims=" %%H in ('Type "%InputFile%"') do (
Ping -n 1 %%H>nul
for /f "tokens=2" %%M in ('arp -a %%H ^| find "%%H"') do (
echo %%H : %%M
echo %%H : %%M>>"%OutPutFile%"
)
)
If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Timeout /T 1 /NoBreak>nul & Exit
::-------------------------------------------------------------------------------------Appreciate your effort Hackoo but after test this code in some workstation inside the domain it gives me this message

ARP: Bad argument: %hostname%
I don't know why?Hackoo
After a lot of searches, I found the below code
Code: [Select]
ECHO OFF
For /f %%a in (hosts.txt) do (
     ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do (
           nbtstat -a %%a | for /f "tokens=1-2 delims=^=" %%x in ('find "MAC Address"') do (
           echo [ %%a   :  %%k   :  %%y   ]>> Host_IP_MAC.txt
echo [ %%a   :  %%k   :  %%y   ]
           )
     )
)

and after testing I found it works only with all workstations working under WinXp only and the rest of the workstations working under Win7, 8, 8.1, and 10 doesn't work, so kindly help If you have an idea to fix this bug.I don't quite understand how you solved your problem? Like you, I have many different hostnames, but I do not know how to get information about all of them at once. Unfortunately, I do not understand the software part at all. This was done by my partner, who literally went on vacation two days ago. Therefore, I am literally at a dead end, I hope it will not be difficult for you to suggest a solution to my problem. I thought that I could somehow call all the hosts I needed using 192.168, but unfortunately I didn't succeed. So I stopped trying to do something by myself. Nowadays, literally any problem can be solved via the Internet, so I thought that my problem could also be solved.
2174.

Solve : Extracting string starting with and ending with specific strings?

Answer»

OK, this is totally over my head here. Never learned all this (for /f "tokens) stuff.

I have a LARGE text file that has many, many, many URLs embedded in it. Going through this and copying and pasting all these URLs would be quite painful, mentally and perhaps even physically, let alone very time consuming. In the end I'd like to have a new text document that lists all the URLs.

The string would start with (http) and end with ("), absent the parenthesis. Removing the (") from the result would be great but not critical.

Can anyone help me out?
I would appreciate it!

Brian
This can be done easily with a vbscript or a Powershell script that use Regex.
eeks! ...and I know even less about those languages.Can you give us a little example of the inputfile and what did you expected as result after extracting i mean the output !
We can write a script that can let the user drag and drop the inputfile over the batch script or the vbscript and get the result in another file !
So, I'm waiting from you what i've asked above !
+
A sample file:

"thumb_source_type":"screen","thumb_url":"","group_id":"2","screen_delay":0,"get_screen_method":"auto","need_sync_screen":0,"update_interval":"","thumb_width":728,"thumb_height":454.9101678183613,"position":6,"clicks":5,"deny":0,"screen_maked":1,"global_id":"vWNVsZDrcsdhsCGdFonDn5BkW9nRRJ","thumb_version":1,"id":14,"thumb":"filesystem:moz-extension://f65056c1-5c41-4f9e-b577-96f5fd992fb0/persistent/sd_previews/vWNVsZDrcssCGdFonDn55EBkW9nRRJ.png","rowid":14,"auto_title":"PortableApps.com - Portable software for USB, portable, and cloud drives","last_preview_update":1619905296092},{"url":"https://google.com/","title":"Unlock, speed up and easily transfer ","thumb_source_type":"screen","group_id":"2","get_screen_method":"auto","thumb":"filesystem:moz-extension://f65056c1-5c41-4f9e-b577-96f5fd992fb0/persistent/sd_previews/zN4KncDseuEPF65WBllpPVbEke9m1u.png","screen_delay":0,"position":5,"clicks":191,"deny":0,"screen_maked":1,"global_id":"zN4cDseuEPF65t6WBllpPVbEke9m1u","thumb_version":1,"id":16,"last_preview_update":1619905289896,"auto_title":"Unlock, speed up and easily transfer content from the cloud - Offcloud.com","thumb_width":728,"thumb_height":454.9101678183613,"thumb_url":"","need_sync_screen":0,"update_interval":"","rowid":16},{"url":"https://drive.google.com/drive/","title":"My Drive - Google

Sample Output file:
https://google.com/"
https://drive.google.com/drive/"

or

https://google.com/
https://drive.google.com/drive/

can't stop with (/) as some URLs have multiple .../text1/text2/ ie...subdirectories as well as different top-level-domainsYou can give a try for this batch file : Extracting_Links.bat
CODE: [Select]echo off
Mode 70,4 & color 0B
Title Extracting URLs links from InputFile by Drag and Drop
Set "InputFile=%1"
If [%InputFile%] EQU [] Call :Help
Set "Tmpvbs=%Tmp%\%~n0.vbs"
Set "OutPutFile=%~n1_Output.txt"
echo( & echo(   Please wait ... Extracting URLs and Links from "%~nx1"
Call :Extract "%InputFile%" "%OutPutFile%"
Start "" "%OutPutFile%" & exit
::--------------------------------------------------------------------------------------------------------------------
:Extract <InputData> <OutPutData>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,?^=%&amp;:/~\+#]*[\w\-\?^=%&amp;/~\+#])?"^)
echo WScript.StdOut.WriteLine Data
echo Function Extract(Data,Pattern^)
echo    Dim oRE,oMatches,Match,Line
echo    set oRE = New RegExp
echo    oRE.IgnoreCase = True
echo    oRE.Global = True
echo    oRE.Pattern = Pattern
echo    set oMatches = oRE.Execute(Data^)
echo    If not isEmpty(oMatches^) then
echo        For Each Match in oMatches 
echo            Line = Line ^& Match.Value ^& vbcrlf
echo        Next
echo        Extract = Line
echo    End if
echo End Function
)>"%Tmpvbs%"
cscript /nologo "%Tmpvbs%" < "%~1" > "%~2"
If EXIST "%Tmpvbs%" Del "%Tmpvbs%"
exit /b
::--------------------------------------------------------------------------------------------------------------------
:Help
Color 0C
echo(
echo(   You should drag and drop a file over,
echo(   this script "%~nx0" in order to extract URLs and Links
Timeout /T 10 /NoBreak>nul
Exit
::-------------------------------------------------------------------------------------------------------------------- I N S A N E !

This script would have taken me 10x longer to write than to manually extract all the websites.
Worked perfectly!

Thank You!
You don't know how much I appreciate your help.
Brian
 Putting this link to the O/P's other questions on the provided code here for posterity.

Inserting extracted code into new file surrounded by specific text

2175.

Solve : %~dp0 vs %cd%?

Answer»

Hello,

Just wondering what's the difference in using %~dp0 or %cd% to find the current directory, since I'm not SURE that either one will work in every case. Or do both work exactly the same?

Thanks.They are not equivalent.

%cd% is available either to a batch file or at the command prompt and expands to the drive letter and path of the current directory (which can change e.g. by using the CD command)

%~dp0 is only available within a batch file and expands to the drive letter and path in which that batch file is located (which cannot change). It is obtained from %0 which is the batch file's name.

An experiment like the following shows the difference

Here is D:\dirshow.bat:

Code: [Select]echo off
echo this is %%cd%%  %cd%
echo this is %%~dp0 %~dp0

Run it from C:\ and this is what you see

Code: [Select]C:\>D:\dirshow.bat
this is %cd%  C:\
this is %~dp0 D:\
There is one more important distinction to note.  Normally the command prompt, and therefore cmd files, don't support UNC paths.

However, using %~DP0 you can use relative paths to install software without mapping a drive.  The command below is what I use to install Adobe Design Premium and it works from any path, UNC, Flash drive, or mapped drive.

msiexec /i "%~dp0\DP 32bit Basic\Build\DP 32bit Basic.msi" /q

I use this by typing \\server\share\software\adobe CS5 into the start menu or run command (XP).  From there I can just double click a cmd file containing the command above.  It's been 4 years... Quote from: patio on March 23, 2012, 10:00:55 AM

It's been 4 years...

So what? I stumbled upon this thread today and found both replies useful. Quote from: mplichta on March 23, 2012, 09:59:01 AM
There is one more important distinction to note.  Normally the command prompt, and therefore cmd files, don't support UNC paths.

I don't think you are correct.

This should work just fine

Code: [Select]xcopy "\\server\share1\*.txt" "\\server\share2\"
and this too:

Code: [Select]pushd "\\server\share\software\adobe CS5"
msiexec "\DP 32bit Basic\Build\DP 32bit Basic.msi" /q
popd
More specifically, cmd.exe (including executed .bat files, .cmd files, etc.) does not support the current/working directory to be a UNC path. pushd gets around this by assigning and switching to a drive letter that is mapped to the target path, and most other programs (commandline or not) work PERFECTLY fine with a UNC path. Quote from: patio on March 23, 2012, 10:00:55 AM
It's been 4 years...
Quote from: patio on March 23, 2012, 10:00:55 AM
It's been 4 years...

I wonder if this topic will be dredged up again in 2016. Judging by it's history...i'd say that's a safe bet...

Seeya then...Not quite 2016 yet, but I found this very helpful. Quote from: patio on March 23, 2012, 10:00:55 AM
It's been 4 years...
Batch is slow...  Quote from: foxidrive on October 18, 2012, 09:23:30 AM
I wonder if this topic will be dredged up again in 2016.
Close enough.This thread helped me out with a batch script at the end of last year. Thank you so much! Quote from: foxidrive on October 18, 2012, 09:23:30 AM
I wonder if this topic will be dredged up again in 2016.

Sonofagun....you were correct.... LOL Like the Matrix Oracle ...would you like a cookie  It's had a good run - but I might be 6 foot under in 2020 I'm just here for 2017, don't mind me. Quote from: foxidrive on October 18, 2012, 09:23:30 AM
I wonder if this topic will be dredged up again in 2016.

Even after 4 years...... *** sigh *** Quote from: foxidrive on January 05, 2016, 03:01:11 AM
It's had a good run - but I might be 6 foot under in 2020
RIP my friend.As the former Dias de Verano, can I say (a little early) happy 10th anniversary to this thread!
Tell good 'ol Diaz i said Hi...... He says hola, mi amigo!  Quote from: Squashman on March 17, 2018, 10:03:07 PM
RIP my friend.
When did he pass away?
Thursday Nov 3rd 2016.

Don's Topic

Dostips Topic Quote from: Geek-9pm on March 18, 2018, 02:16:42 PM
When did he pass away?
Shortly before you said how sad it was.
 Foxidrive Quote
passed away on Thursday 3rd November 2016
My memory is fading.   
Could somebody put a note in his profile? Quote from: foxidrive on January 05, 2016, 03:01:11 AM
It's had a good run - but I might be 6 foot under in 2020
Not quite 2020, yet, but I registered in late 2019 just to say that this thread was useful to me. I was trying to understand what pushd "%~dp0" ment, I googled it, and now I understand it because of this thread. Only 14 days from 2020 lol!

thank you, contributors to this post, and a posthumous thank you and RIP to foxidriveRIP...
I have been around PCs all my life. I have been in IT for 20+ years and have never came across %~dp0 before. No idea why. I am glad I came across this post to better understand this hidden gem.

Thanks for the info everyone.

This thread helped me about two years ago (august 2018 WTD), but DUE to thread policy I head to wait until 2020 to reply

Thanks GUYS!! Quote from: patio on March 23, 2012, 10:00:55 AM
It's been 4 years...
It's been... another 4 years... 

I using a MiSTer FPGA to run a DOS core, and looking into batch scripting, but just cannot figure out how to get the path to the currently active directory.

I cannot get %~dp0 to work either... but trying to experiment some more. I am trying with FreeDOS, DOS 6.22 and DOS 7.1. But I guess I have to make sure I did try all of them.%~dp0 and things like %cd% are part of the NT Extensions that were added to the command prompt with Windows NT4.

the "cd" command by itself outputs the current directory, but I don't know a way you can get that into an environment variable without utilizing things like QBASIC.Somehow i knew in the back of my mind it would be Dias ressurecting this one...

Who is that masked man ? ? Quote from: rajubhaiya on September 17, 2020, 04:21:44 AM

guys help me out?

You are not the "former Dias de Verano".
Hey Mike, hope all is well. Good to see you back.We can forget about 2020 right Quote from: Caldor on August 05, 2020, 07:54:58 AM
It's been... another 4 years... 

I using a MiSTer FPGA to run a DOS core, and looking into batch scripting, but just cannot figure out how to get the path to the currently active directory.

I cannot get %~dp0 to work either... but trying to experiment some more. I am trying with FreeDOS, DOS 6.22 and DOS 7.1. But I guess I have to make sure I did try all of them.

Resurrection time!

Works with MS-DOS 7 and I have no reason to think it won't work with (say) 6.22

Code: [Select]echo off
>temp1.bat echo PROMPT SET _CD=$P
>temp2.bat command /c temp1.bat
call temp2.bat
del temp1.bat
del temp2.bat
echo currentDir=%_CD%


2176.

Solve : Batch file needed to wrap entire text column in double quotes?

Answer»
Just JOINED here to ask this ! I have a TEXT file that has multiple lines without any QUOTES. I NEED a batch file that will append a single double QUOTE at the beginning of the first line (not on a separate line by itself , it must be the first character on the first line) I need the same for the very last line position also. So to end up looking like

"One
Two
Three
Four
Five
Six
Seven"

...Therefore wrapping the entire column. I hope you guys can solve this for me as its been driving me nuts !

Thanks in advance !It is customary to post whatever code you have created so we can better see where you're going with this. In any case, my batch codes days are pretty much behind me, but I did come up with this:

Code: [Select]echo off
setlocal enabledelayedexpansion
set count=0
set ifile=g:\wfc\testlib\hope.txt
set ofile=c:\temp\hopeless.txt

for /f %%b in ('type !ifile! ^| find "" /v /c') do set ubound=%%b

for /f %%i in (!ifile!) do (
  set /a count=!count!+1
  if !count! EQU 1 ( echo ^"%%i >> !ofile!
  ) else if !count! EQU !ubound! ( echo %%i^" >> !ofile!
  ) else ( echo %%i >> !ofile! )
)

Change the ifile and ofile values in the set statements to match your environment.

Happy Coding
2177.

Solve : Can we display the content of a variable that itself is the content of another ??

Answer»

Hi all

How to display the content of a variable that is itself composed of a variable
for example, if we have a variable its name is Age and contain on VALUE 35 , so we can display its value by writing the below line in batch SCRIPTING.

Code: [Select]SET "Age=35"
echo %Age% and the result will be '35'

but if the name itself of that variable is inside another variable like the below line

Code: [Select]set "var=Age"
set "%Age%=35"
, so we can display the content of 'var' variable by the below line

Code: [Select]echo %var% and the result will be 'Age'
my QUESTION here is :
Can we display the content of 'Age' variable using 'var' variable?
And if we can How to do this step? Code: [Select]echo off
set "var=Age"
set "%var%=35"
call echo %%%var%%%
SETLOCAL ENABLEDELAYEDEXPANSION
echo !%var%!Thanks and Appreciate Squashman

2178.

Solve : Create strings using echo commands?

Answer»

So, I started messing around with a .bat file and started learning how to use variables, user input, show TEXT using the commands: echo,set,etc.
And I noticed I can create files with the command: echo > (File name) Which was really intresting but I ran into a problem.
When creating a file you can do: echo "Text in it" > (File name) and I tried putting a CPP script in it but it doesn't seem to work. Can anyone tell me why?

I tried putting it into a string:
Code: [Select]set Code=#include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,B;fin>>a>>b;fout<<a*b;I tried directly applying it:
Code: [Select]echo #include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b; > "%CPPFileName%"
Can anyone help me with this?
Heres the full code:
Code: [Select]echo off
echo In File name:
set /p File1Name=
echo 2 Variables:
set /p Variables=
echo %Variables% > "%File1Name%"
echo Out File name:
set /p File2Name=
echo 0 > "%File2Name%"
echo CPP File name:
set /p CPPFileName=
set Code=#include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b;
echo #include<fstream>usingnamespacestd;ifstreamfin("");ofstreamfout("");int main(){inta,b;fin>>a>>b;fout<<a*b; > "%CPPFileName%"
The obvious culprit should be the >.  This character is a special character to tell the script to redirect the output to the file. OTHERWISE KNOWN as Standard Output.  The < is also a special character as it is used for Standard Input.  Any special character that you need to use Literally, needs to be ESCAPED by the ^ character.
example
Code: [Select]echo #include^<fstream^>usingnamespacestd;ifstreamfin(""); >"%CPPFileName%"I tried but it still doesn't create my file...

Code: [Select]echo off
echo In File name:
set /p File1Name=
echo 2 Variables:
set /p Variables=
echo %Variables% > "%File1Name%"
echo Out File name:
set /p File2Name=
echo 0 > "%File2Name%"
echo CPP File name:
set /p CPPFileName=
echo #include^<fstream^>usingnamespacestd;ifstreamfin("%File1Name%");ofstreamfout("%File2Name%");int main(){inta,b;fin>>a>>b;fout<<a*b;} > "%CPPFileName%"
It worked omg.
Thank you very much!

2179.

Solve : String Spaces,New Lines and Inserting Text?

Answer»

So. I have a string that I create WITHIN a file and I want to put spaces,new LINES and add some input in the code but it doesn't work.

I tried putting Code: [Select]"" between the text as I saw online but it doesn't work. And the new lines I didn't found on the internet.
Im trying to create a file with this code in it and this is how I got it to EVEN create the file.
Code: [Select]set /p CPPFileName=
echo ^#include^<fstream^>usingnamespacestd^;ifstreamfin(^"^")^;ofstreafout(^"^")^;int main^(^)^{inta^,B^;fin^>^>a^>^>b^;fout^<^<a^*b^;^} > "%CPPFileName%"And this is the output
Code: [Select]#include<fstream>usingnamespacestd;ifstreamfin("");ofstreafout("");int main(){inta,b;fin>>a>>b;fout<<a*b;}
But I want this to be the output using Spaces And New lines
Code: [Select]#include<fstream>
usingnamespace std;
ifstream fin("");
ofstreaf out("");
int main()
{
int a,b;
fin>>a>>b;
fout<<a*b;
}
And also about Inserting text.
I have 2 Inputs and the name of the strings are Code: [Select]File1Name and Code: [Select]File2Name Is there a way I could add these strings in the code string I want to output?
Like Code: [Select]^#include^<fstream^>usingnamespacestd^;ifstreamfin(^"%File1Name%^")^;ofstreafout(^"%File2Name%^")^;int main^(^)^{inta^,b^;fin^>^>a^>^>b^;fout^<^<a^*b^;^}
If you could help me it would be awesome!Not sure why you have all that additional escaping. To resolve your initial problem you can do this.

Code: [Select]set /p CPPFileName=
(
echo #include^<fstream^>
echo usingnamespace std;
echo ifstream fin(""^);
echo ofstreaf out(""^);
echo int main(^)
echo {
echo int a,b;
echo fin^>^>a^>^>b;
echo fout^<^<a*b;
echo }
)> "%CPPFileName%"
I am not sure I am understanding your second issue.  I don't see any code where your are assigning any variables named File1Name or File2Name so I am not sure if you want the values of the variables or you literally want to output %File1Name%.Thanks again for the help!
I got it to work after playing with the strings for some more but thanks anyways

2180.

Solve : Run CMD Commands in Batch Files?

Answer»

How do I run multiple cmd commands in a batch file?

I tried this and it works
Code: [Select]cmd /k "cd C:\Users\TE IUBESC!!!MAMI\OneDrive\Desktop\Sheesh"But after that the program stops doing anything.
How can I add more commands after that?
LIKE run this command right after the previous command then close the window?There is no NEED to use CMD /K
Code: [Select]cd /D "C:\Users\TE IUBESC!!!MAMI\OneDrive\Desktop\Sheesh"
echo I am in this folder: %cd%
echo Let's start notepad
start "" "notepad.exe"This may help.
https://ss64.com/nt/cmd.html
Quote

/K     Run Command and then return to the CMD PROMPT.
          This is useful for testing, to EXAMINE VARIABLES
2181.

Solve : How to launch windows program in DOS at OS selection screen??

Answer» HELLO members,
How to launch windows program in DOS at OS selection screen during boot?
To share the concern better, I have made a video taken from SOMEONE's computer and WISH to setup same at mine. Kindly have a look at the following link:
https://youtu.be/YAO9OGsNBUw

Please guide, advance thanks!!They have a Dual boot between Windows XP and MS-DOS. For some reason the MS-DOS Boot.ini entry is called "MICROSOFT Windows".

I don't think you can run a Windows program from within Dos alone, but it appears that program in the video is some sort of Dos based program.  Why don't you try adding that command to Autoexec.bat and SEE if it will load that way?
2182.

Solve : Combining multiple filepaths into one line?

Answer»

I would like to streamline some of the functions I do constantly. One of which is copying the filepaths of multiple files and making one line of text for example:

If I select
file1.txt
file2.txt
file3.txt
and right-click while holding the SHIFT key I can "COPY as path."

I paste the group of paths into Notepad++ which gives me three different lines. My example is simplified; I have to deal with far more files in my workflow.

From there, I hit END, DELETE, SPACE after each file. It's good mental exercise I suppose, but it's tedious given how many times I have to do this in a day and surely there is a command script I COULD use where I can automate the process.

I have reverse-engineered some scripts some friends have used in the ballpark of what I'm trying to do, and surely it would be something along the lines of
cmd /v:on
set x=F:\path
for %f in (x) do (whatever)
but maybe it's something entirely different.

Any help would be greatly appreciated!Actually I discovered "macros" after posting. That streamlined one step of the process.

Would there be a way to copy and paste the last line?

For example I can now use a macro to turn
"file1.txt"
"file2.txt"
"file3.txt"
into
"file1.txt" "file2.txt" "file3.txt"

but I'd like it to be
"file1.txt" "file2.txt" "file3.txt" "file3.txt"Is it okay to use javascript ?  Please SAVE the code below to a file with extension html, eg, combine_lines.html, then open it with browser.  See attached image for the screen in browser.

Code: [Select]<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Combine lines</title>
</head>
<body>
    <p/>Input:
    <p/><textarea id="inputId" style="width:450px;height:150px;">
line1
line2
line3
    </textarea>
    <p/><button type="button" onclick="combine()">combine</button>
    <p/>Output:
    <p/><textarea readonly id="outputId" style="width:450px;height:150px;"></textarea>
    <p/>
    <script>
        function combine() {
            var indata = document.getElementById('inputId');
            var lines = indata.value.split('\n');
            var outdata = "";
            var line = "";
            for (var i=0; i < lines.length; i++) {
                lines[i].trim();
                if (lines[i].length > 0) {
                    line = lines[i];
                    outdata += line + " ";
                }
            }
            if (line.length > 0)
                outdata += line;
            document.getElementById('outputId').innerHTML = outdata;
        }
    </script>
</body>
</html>
I tried HTML and couldn't get it to work. But I am able to get part of what I want using a Notepad++ macro.Here is what I'm wanting to do:
1) use list geo to produce file1.gtf from file1.tif
2) use gdal_translate to produce file1_a.tif from file1.tif
3) use nconvert to modify file1_a.tif and not file1.tif
4) use geotifcp to put metadata from file1.gtf back in modified image (file1_a.tif) and overwrite file1.tif

Code: [Select]cmd /v:on
set tif=F:\path
for %f in ("%tif%\*_V.tif") do (
set filename=%~nf
listgeo -d "%f" > "%tif%\!filename!.gtf"
gdal_translate -B 1 -b 2 -b 3 -of GTiff -co INTERLEAVE=PIXEL "%f" "%tif%\!filename!_a.tif"
geotifcp -g "file1.gtf" "file1_a.tif" "file1.tif"
"F:\path\to\nconvert.exe" -overwrite -replace "file1_a.tif"
geotifcp -g "file1.gtf" "file1_a.tif" "file1.tif"
)
Is there a good way of doing this? I can do step one, but I don't know the commands to use one particular file and not the other.Curious why the meta data needs to be passed back into it?Removing metadata so it isn't stripped when I edit the imagery.

Through trial-and-error I figured out how to have the script run automatically through the step where nconvert edits the *_a.tif file, but the step where I re-insert the metadata has me stumped since I don't know how to run a command where I target the *.tif file but not the *_a.tif file. Probably very simple, but I haven't learned that one yet.Hi,

My DOS programming is rusty so it takes me sometimes to test.  You can try to save the code below to a .bat file and run it in DOS.

Since I don't have listgeo, gdal_translate, etc programs installed so I assume your commands are good.

Here is some notes:
o it seems variable cannot be set inside the for loop
o the for loop variable %f needs to specify as %%f in a .bat file
o For parsing DOS VARIABLES, run "hep for" to see available notes and examples.

Good luck.

Code: [Select]echo off
setlocal
set tif=F:\path
for %%f in (%tif%\*_V.tif) do (
  listgeo -d %%f > %tif%\%%~nf.gtf
  gdal_translate -b 1 -b 2 -b 3 -of GTiff -co INTERLEAVE=PIXEL %%f %tif%\%%~nf_a.tif
  geotifcp -g %tif%\%%~nf.gtf %tif%\%%~nf_a.tif %%f
  "F:\path\to\nconvert.exe" -overwrite -replace %tif%\%%~nf_a.tif
  geotifcp -g %tif%\%%~nf.gtf %tif%\%%~nf_a.tif %%f
)
endlocal

2183.

Solve : Equivalent of Unix eval in Windows?

Answer»

Hi,

I want to convert the following unix command line to windows command line:
eval `sb-config --env`

"sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.

So how can I execute the sb-config result in a windows batch script?

The only solution I COULD come up with is:
sb-config --env > sbenv.cmd
call sbenv.cmd
del sbenv.cmd

If anybody has any better suggestions plz let me know.

Thnx n Regards,
PreethYou can use the following:

del set.cmd & FOR /F %V in ('set') do echo SET %V >> set.cmdHi uhoraho,

Thanks for ur reply. I am a newbie to windows scripting. So can u please explain wht this line does?

Regards,
Preethif you...

1. type SET or set at the prompt

2. run the code changing it slightly like this

del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

(It is bad PRACTICE to have a command script with the same name as a built in command)

3. examine the contents of the new file myset.cmd (which is a script)

... you will see for yourself what it does - namely that FOR /F captures the output of the command 'set', line by line, into the loop metavariable %V, and the >> operator echoes these lines, (with the word SET and a space prepended), in append mode, to the named file myset.cmd.

Type FOR /? and SET /? at the prompt for more help.

Hi,

Thanx again...

What I wanted was execute the output of the command line "sb-config --env"

So where should I put this command in the following line:
del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd

Regards,
Preeth Quote from: preeth on December 15, 2009, 12:34:03 AM

Thanx again...

What I wanted was execute the output of the command line "sb-config --env"

So where should I put this command in the following line:
del myset.cmd & FOR /F %V in ('set') do echo SET %V >> myset.cmd


Have you typed FOR /? and read the help?
Yes I read the FOR help.

But I think you didnt get the real requirement.

When I did
del myset.cmd & FOR /F %i in ('sb-config --env') do echo SET %i >> myset.cmd
It was printing 2 lines of "SET set" into the myset.cmd file.

But this one:
del myset.cmd & FOR /F "tokens=1,2" %i in ('sb-config --env') do echo SET %i %j >> myset.cmd
It was printing the command output with a SET prepended to each line.

But I dont want to prefix anything to the output of the command. The command "sb-config --env" output following lines:
set STREAMBASE_HOME="D:\StreamBase\StreamBase.6.3"
set PATH="D:\StreamBase\StreamBase.6.3\bin";%PATH%
I just want to execute them.

I already know that I can do
sb-config --env > sbenv.cmd
call sbenv.cmd
del sbenv.cmd

Is there any better ways of doing this. ie. without creating an temp cmd file.

Thanks and Regards,
Preeth

I dont think it was appreciated that SET appeared in the output

Try this
FOR /F "tokens=1,2" %i in ('sb-config --env') do Call %i %j
I am getting confused myself. What is the result of including

sb-config --env

in a batch script?

or typing it at the prompt?

From the original post

Quote
"sb-config --env" returns the commands to set some environment variables. The result is having multiples lines of SET commands.
So you want to execute each line. What about this?
Code: [Select]For /f "delims=" %%A in ('sb-config --env') do call %%A
For /f "delims=" %%A in ('sb-config --env') do call %%A is working for me.

Thanks GPL and Salmon.
2184.

Solve : How to suppres "command" window flashing?

Answer»

Hi, there,
Does anybody knows how to suppress “command” window flashing on the SCREEN when a Windows program calls for a BATCH file from which another
Windows program is called right away.
Thanks
Vlad Quote from: sosnov on December 15, 2009, 06:15:47 PM

Hi, there,
Does anybody knows how to suppress “command” window flashing on the screen when a Windows program calls for a batch file from which another
Windows program is called right away.
Thanks
Vlad

Not sure I understand. You have a Windows program that calls a batch file which launches a Windows program? Why not eliminate the batch file and have the first Windows program directly launch the second Windows program? What programs are you using?

 sosnov,
Wlecome to CH.
Lots of people here are willing to help you with a problem.

We do not understand your  problem. A DOS screen can be MINIMIZED to the task bar. But making it not visible on the task bar is a poor idea for most cases.

However, if the task bar is annoying, or if it takes too much SPACE, you can hide it so that it shows only when the mouse is at the bottom of the screen. Or, it can be set so the any full screen application will cover it.

Is that what you want?
2185.

Solve : I want to create a batch script which can search for .jpg and .jpeg?

Answer»

I want to create a batch script which can search for .jpg and .jpeg

I am new to this script language, so don't no how to search, so I am posting this thread here.

Please can anyone tell me the batch script which can search all drives and folders and subfolders in a computer for .jpg and .jpeg, once found they must get copied.

Please help me with this, please give me the script code for this.type dir /? on your cmd.exe
C:\batch>type  akki.bat
Code: [Select]echo off
cd \
dir /s *.jpg

C:\batch>akki.bat 
05/27/2004  10:23 AM             7,897 SOL_CENT.JPG
               1 File(s)          7,897 bytes

 05/02/2009  07:51 AM             3,550 wsadvisor_logo_66x57.jpg
               1 File(s)          3,550 bytes

 
05/02/2009  07:51 AM             1,123 presto.jpg
               1 File(s)          1,123 bytes

 
05/02/2009  07:51 AM             3,346 vista_icon_logo.jpg
               1 File(s)          3,346 bytes

 
05/02/2009  07:51 AM             1,076 router_50x50.jpg
               1 File(s)          1,076 bytes

 
05/02/2009  07:51 AM             2,113 Drivers_50x50.jpg
               1 File(s)          2,113 bytes

  Quote

search for .jpg and .jpeg

Quote
once found they must get copied.

Well, assuming you read the question, your output "proves" that your code doesn't work  Here is what I got.

echo off
for /F %%a in ('mountvol ^| find ":\"') do (
dir %%a 1>nul 2>nul
if not ErrorLevel 1 (
copy %%a*.jpg
copy %%a*.jpeg
)
)

This script searches the physical drive but does not search into the folders and subfolders, so can anyone modify the script and give me a script which will fully search the physical drive including folders and subfolders.I want to help you, but in my own way.
For me to use your script would be a chore. My approach to this, and other jobs, is to consider the objective.
First Step: Objective:
Once the objective is know, it is time to create an abs tact idea or concept. Then create a method that is suitable.  The objective has to be reasonable.
The  provided a script does not indicate a  clearly stated objective.
Second Step: Method.
Batch MAY be a suitable method. A short, concise command is admirable, butcan be difficult to adapt. Breaking a hob into tasks can help.
Third Step: Use restraint.
The Operating system has some practical limits on what it can do at one time.In Batch there is a PROBLEM of DELAYED execution and extentions enbabled.  Also placing an unlimited number of files of unknown size into one directory may crash the system.
 
The FOR loop contains not only technical syntax problems but also weak logic. Do you understand the , TAKEN literally, your idea can make the Operating system unstable. It may even produce a fatal error.

And there's more... but I will let others say.OKay then can yoiu help me with a single drive. Lets take with D Drive, there are few pictures that I need to get copied, will you help me with this please.before running this snippet, make sureto change the destfolder.

Code: [Select]SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

for /f "tokens=*" %%P in ('dir %%a\*.jp*g /s /b') do copy %%P !destfolder!


)
only problem I can think of for the above is that *.jp*g can match jpog and jpag and so forth; but these extensions aren't common file types so likely won't be encountered. Also, since it will search ALL drives, the destination folder will inevitably be searched; I believe it will error at that point but the loop should simply report the error (file cannot be copied onto itself) and continue.

I'm also uncertain wether I need the EXCLAMATION marks or delayed expansion, since destfolder remains unchanged during the loop.
that din't worked. Quote from: akki15623 on December 16, 2009, 12:43:01 PM
that din't worked.
explain.

EDIT:

it was a simple typo that I changed in my copy but not in the copy I posted.

Code: [Select]
SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do copy "%%P" !destfolder!


)

there was a slash between the %%a and the *.jp*g, which is not necessary since mountvol includes the slash.


EDIT: Oh, and I forgot quotes. Quote from: BC_Programmer on December 16, 2009, 12:32:57 PM
only problem I can think of for the above is that *.jp*g can match jpog and jpag and so forth

Perhaps...

Code: [Select]('dir /s /b %%a*.jp*g ^| find ".jpg ^| find ".jpeg" /s /b')
Or explicitly test for the wanted extensions...

Code: [Select]set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

    for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do (

        if /i "%%~xP"==".jpg" copy "%%P" !destfolder!
        if /i "%%~xP"==".jpeg" copy "%%P" !destfolder!

    )

)




Quote
I'm also uncertain wether I need the exclamation marks or delayed expansion, since destfolder remains unchanged during the loop.

You don't.

Quote from: BC_Programmer on December 16, 2009, 12:43:17 PM
explain.

EDIT:

it was a simple typo that I changed in my copy but not in the copy I posted.

Code: [Select]
SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do copy "%%P" !destfolder!


)

there was a slash between the %%a and the *.jp*g, which is not necessary since mountvol includes the slash.


EDIT: Oh, and I forgot quotes.





Worked perfectly...... Thanks, thank you very much buddy...... Quote from: akki15623 on December 16, 2009, 01:24:03 AM
I want to create a batch script which can search for .jpg and .jpeg


C:\batch>type  bc1215.bat
Code: [Select]SETLOCAL EnableDelayedExpansion
set destfolder=E:\copiedjpegs
E:

dir /s /b *.jpg  >  jpgfiles.txt


for /f "tokens=*" %%P in (jpgfiles.txt ) do copy %%P !destfolder!


)
dir  E:\copiedjpegs\  |  more
OUTPUT:

C:\batch> bc1215.bat

 Directory of E:\copiedjpegs

12/16/2009  02:21 PM              .
12/16/2009  02:21 PM              ..
05/14/2005  03:44 PM         1,390,722 002.jpg
12/26/2002  11:26 AM            63,683 03.JPG
05/03/2006  01:05 PM         2,199,973 050206.jpg
02/03/2003  01:32 AM            20,443 1.jpg
02/03/2003  01:31 AM            11,601 10.jpg
02/03/2003  01:23 AM            11,178 11.jpg
02/03/2003  01:21 AM            16,492 12.jpg
11/02/2002  06:05 PM            84,884 14.jpg
12/29/2004  10:01 PM            10,039 1map.jpg
02/19/2006  01:02 PM         2,318,092 2-18-06.jpg
02/03/2003  01:10 AM            15,026 2.jpg
12/28/2004  10:57 AM            30,112 20_months.jpg
12/29/2004  10:01 PM             8,086 2map.jpg
02/03/2003  01:18 AM           199,266 3.jpg
12/28/2002  04:14 AM            30,008 4.jpg
11/12/1998  08:48 PM            62,325 457015.jpg
11/12/1998  08:50 PM            71,110 457030.jpg
11/12/1998  09:46 PM           104,355 487071.jpg
11/12/1998  09:46 PM            70,428 487072.jpg
02/03/2003  01:18 AM             5,437 5.jpg
11/12/1998  10:07 PM            57,326 577092.jpg
11/12/1998  07:52 PM            86,958 594008.jpg
12/29/2004  10:01 PM            10,039 5map.jpg
02/03/2003  01:16 AM             8,193 6.jpg
11/13/1998  02:45 AM            51,505 643047.jpg
11/13/1998  02:46 AM            55,217 643057.jpg
11/11/1998  10:25 PM           101,750 677023.jpg
11/12/1998  02:11 AM            82,308 682008.jpg
11/12/1998  02:25 AM            92,993 682097.jpg
04/28/2002  07:12 PM            25,813 7.jpg
03/29/2005  11:41 PM           104,563 70.jpg
11/12/1998  01:30 AM            31,173 719024.jpg
11/12/1998  01:32 AM            55,994 719038.jpg
11/12/1998  01:40 AM            63,905 719090.jpg
11/12/1998  01:41 AM            44,786 719098.jpg
11/12/1998  10:30 PM            75,614 762000.jpg
11/12/1998  10:39 PM            69,560 762055.jpg


C:\batch> Quote from: BC_Programmer on December 16, 2009, 12:43:17 PM
explain.

EDIT:

it was a simple typo that I changed in my copy but not in the copy I posted.

Code: [Select]
SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do copy "%%P" !destfolder!


)

there was a slash between the %%a and the *.jp*g, which is not necessary since mountvol includes the slash.


EDIT: Oh, and I forgot quotes.


Can you help me with one more thing.

I will send the above script to my girlfriend PC, is there a way that you can modify this so that it can send all the pics to my e-mail???um... no I don't think so.

you could zip them via the command-line but the attachment will be huge... and I don't know how to do SMTP/e-mail from batch.
2186.

Solve : need help: How to write a batch to combine more 100 text files to one text file??

Answer»

Quote from: HELPMEH on December 15, 2009, 06:58:16 PM

Hey bill, try reading next time.

I meant to say I could not get the following code to work on my machine:

echo off
for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

The solutions offered here on the Hope Board are not just for the Original poster.  Many readers can often use the information.

I wonder if Helpme can show us the output for:

echo off
for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

Must we offer a new "ENDNUMBER" each time we run the code?

I use XP.  Will the above code run for XP?

An example of the Output of all code offered will help the OP plus the readers.

Thank you Helpmeh  for your time and effort.


You replace ENDNUMBER with the number in the last file. The OP perfectly understood, and it seemed very obvious to replace it.
And no, I can not run it, as I am not on a computer. what bill (or joan or liz or mike or ??) meant is OP won't know the ENDNUMBER before hand unless he can find out from dir *.txt and change the code. Its probably BETTER not to use the for loop range + step method, but just use the output from dir file*.txt
Code: [Select]for .... (dir file*.txt) do (
  type .... >> output.txt
)
how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

replace the "set I=1" for the number the file sequence starts

Code: [Select]echo off
:recurse
set I=1

cd
FOR /f "tokens=*" %%P IN ('dir /A-d /B *.txt') do (call :showfiles "%%P")
echo.
echo Filecount: %I%

for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
:showfiles
echo %1
set /a I+=1
goto :eof Quote from: BatchFileBasics on December 15, 2009, 08:17:51 PM
how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

replace the "set I=1" for the number the file sequence starts

Code: [Select]echo off
:recurse
set I=1

cd
FOR /f "tokens=*" %%P IN ('dir /A-d /b *.txt') do (call :showfiles "%%P")
echo.
echo Filecount: %I%

for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
:showfiles
echo %1
set /a I+=1
goto :eof

why not just do dir file*txt ? there's no need to call another loop to count total files. Of course, unless there other files with names like filetest.txt , fileblahblah.txt and you want to isolate those that have numbers following "file", which you could do that with dir file*txt | findstr /I "file[0-9]*.txt" Quote from: BatchFileBasics on December 15, 2009, 08:17:51 PM
how about this? counts txt files. i found this code somewhere off the forums a while ago, it was in my batch bank

replace the "set I=1" for the number the file sequence starts

Code: [Select]echo off
:recurse
set I=1

cd
FOR /f "tokens=*" %%P IN ('dir /A-d /b *.txt') do (call :showfiles "%%P")
echo.
echo Filecount: %I%

for /l %%a in (0,1,%I%) do type file%%a.txt >> endresult.txt
:showfiles
echo %1
set /a I+=1
goto :eof


Where is Output? Quote from: billrich on December 15, 2009, 09:18:42 PM

Where is Output?
Why don't YOU run it and put out any output it MAKES, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record. Quote from: Helpmeh on December 16, 2009, 04:56:58 AM
Why don't YOU run it and put out any output it makes, instead of "Where is output?" over and over again. Sometimes you really sound like a broken record.

I don't think I WOULD have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned?
Quote from: Salmon Trout on December 16, 2009, 05:08:00 AM
I don't think I would have bought that record in the first place, let alone played it after it was broken. Anyhow, wasn't he banned? Why is he now unbanned?

New name...lowercase b is all it takes. Quote from: Helpmeh on December 16, 2009, 07:08:38 AM
New name...lowercase b is all it takes.

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

Show your code and show output and stop faking it. Quote from: billrich on December 16, 2009, 02:51:16 PM
-------------------------------------

Show your code and show output and stop faking it.
1. I've shown my code, heck, YOU've even used it in your posts.
2. As I've said before, I don't have access to a computer. I am on my iPod.
3. How am I faking? Read the OP's post. The code worked great for him. Quote from: Helpmeh on December 16, 2009, 05:53:32 PM
Read the OP's post. The code worked great for him.

The problem is on my end.  I could not get the code to work on my machine.
I thought I could look at your code and output  and figure what I was doing wrong.

echo off
for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

I might try again.
Quote from: billrich on December 16, 2009, 06:08:13 PM
The problem is on my end.  I could not get the code to work on my machine.
I thought I could look at your code and output  and figure what I was doing wrong.

echo off
for /l %%a in (0,1,ENDNUMBER) do type file%%a.txt >> endresult.txt

I might try again.

Did you change ENDNUMBER? You haven't posted anything but a copypasta of my code. Post the code in YOUR batch file. Quote from: billrich on December 15, 2009, 09:18:42 PM

Where is Output?

why do i need output?I think bill is just frustrated because the code doesn't work for him. That happens to the best of us. We get impatient and angry.
2187.

Solve : Up dating/up grading DOS?

Answer»

How do I know if I have the LATEST DOS program? How do I up date or up GRADE DOS?Where do  find a copy?1. How do I know if I have the latest DOS program?

You type VER at the PROMPT and then PRESS Enter. The latest version of standalone MS-DOS is version 6.22, released in 1994.

2. How do I up date or up grade DOS?

If you have the latest, there is no point.

3. Where do  find a copy?

Ebay possibly.

2188.

Solve : Xcopy /d check?

Answer»

Hi there
I have 2 servers A and B.
I have a batch file which will sync B with A.
There are 3 identical folders on A and B and they both are of huge size.
At the minute everytime we sync server B with A, we are copying the entire folder across from B to A. This is very time CONSUMING and i'm trying to reduce this

The copy command i have at the minute is as follows i.e.

xCopy /S \\%2\g$\Utility\Mgt \\%1\g$\Utility\Mgt >>"file.log"

I was thinking of modifying the xcopy command as follows( WOULD it WORK)

xCopy /S /d \\%2\g$\Utility\Mgt \\%1\g$\Utility\Mgt >>"file.log"

Please note i have added /d as an extra SWITCH and provided any date and time values. Coz i can;t check this script at the minute, will my above modified script COMPARE Mgt folders on both the servers and only copies those files which are mismatches. Is it also better to use a beyond compare tool or something like that to achieve my objective?. please advice

2189.

Solve : white spaces in path while using start command?

Answer»

his %TM% variable was set to a folder name.
therefore

Code: [Select]start "" "C:\fold1\fold2\%TM%"

is what he wants.
Here we go again...

Quote from: BC_Programmer link=topic=he never tried %TM%.
[/quote


start "" "C:\fold1\fold2\%TM%"


C:>start "" "C:batch\fold1\fold2\%TM%"
The SYSTEM cannot find the file
C:\fold1\fold2\C:\batch\fold1\fold2\.




C:\batch>type gpl2.bat
Code: [Select]echo off

set TM="C:\fold1\fold2\"

echo TM=%TM%

start "" "%TM%"
pause

start "" "C:\fold1\fold2\%TM%"


pause

start "%TM%"

pauseC:\batch>
refer to the ORIGINAL post. The assumption being made is that, although the great Billrich doesn't have this particular folder on his drive, the OP, who defined the criteria upon which everybody (aside from the great Billrich, of course) is making suggestions. the fact that the OP says:

Quote
set TM="Ticket Folder"

start C:\fold1\fold2\TM
cannot find TM

start C:\fold1\fold2\%TM
cannot find TM

start C:\fold1\fold2\%%TM
cannot find %TM

basically MEANS that these folders do not actually exist on their machine either, and rather they are providing this code as an example of what they need, which they expressed earlier.

There are in fact two issues the OP was having; one was the use of quotes around the folder name, which Salmon Trout explained requires a set of "" to define no title before the quotes around the actual folder name. The folder name itself, as presented by the OP above, is acquired by a path (not necessarily C:\fold1\fold2, but rather that is being used as an alias for the actual folder name and to indicate to those of us with cognitive capabilites that they intend to use this sort of command on folders in the heirarchy) which is built using the TM environment variable. the TM variable is, in his above example, being set to "Ticket Folder" this in and of itself presents another issue; the proper assignment should be, as Helpmeh, another PWWPA (Post Who Was Paying Attention) pointed out, without quotes. INSTEAD, the final command should be
Code: [Select]set TM=Ticket Folder
start "" "C:\fold1\fold2\%TM%"

Now, to clarify again; the folders will probably not exist on anybody elses machine, and in fact since they are simply abstractions of the actual problem and not true folder names on the OP's machine they probably don't exist there. This of course makes it difficult to locate such abstractions on ones PC, especially when you set the variable to the wrong value. But not to worry, the concept is simple to explain.

When the OP specified Fold1\fold2\ etc, they are not in fact, speaking of actual folders by this name, but rather they are explaining that they will work with multiple folder names- or more precisely, that the actual names of the folders aren't important. The important point is explained earlier in the post, which is that they are having issues with the start command and using quotes. The examples given also suggest that they have not yet had experience using Environment variables, which, unlike loop variables on the command line (one percent sign preceding) or loop variables in a batch file (two percent signs preceding) require a percent sign on either side of the variable name. Again, having the proper data in the variable is of the utmost importance, and setting it to some arbitrary value is hardly the best way to test the method, especially when the setting given my the OP clearly indicates it is used to specify a single folder name within a folder hierarchy.

Considering the length of this post, I can make the apt prediction that by ignoring much if it you'll be able to continue to post your illogic and additionally make comments about how unnecessary the girth of my post was. The fact is your understanding of the concepts involved is the issue, not the length of my post, and your complete avoidance of that issue is what prevents you from learning these new things as they are presented to you, a statement made on several occasions my multiple users.Paraphrasing slightly for the new folks: billrich is a twice banned very stupid troll who keeps coming back to ruin threads with his trash.
Quote from: Salmon Trout on December 08, 2009, 12:21:44 AM
Paraphrasing slightly for the new folks: billrich is a twice banned very stupid troll who keeps coming back to ruin threads with his trash.

Twice?! Quote from: Helpmeh on December 08, 2009, 03:13:02 PM
Twice?!

I though he must have been banned as JaneDoe or whatever he was calling himself. [Opens new tab) Joanlong I mean.
Quote from: Grimbear13 on December 07, 2009, 09:49:26 AM
I'm trying to make a startup process at work.  I need it to open several programs in a certain order.  The problem I keep running into is white spaces in the directories or the folders I need opened.

start C:\folder1\folder2\Folder To Be Opened


Grimbear,

How did you solve the problem of not finding the TM variable and/or folder?trollboy still doesn't get it.
Quote from: Salmon Trout on December 08, 2009, 03:16:54 PM
I though he must have been banned as JaneDoe or whatever he was calling himself. [Opens new tab) Joanlong I mean.


he was also banned as Miketaylor after he sent me a sick (very sick) PM

Where is Grimbear?



Grimbear,

How did you solve the problem of not finding the TM variable and/or folder?He's completely crazy.
Quote from: Grimbear13 on December 07, 2009, 09:49:26 AM
I need it to open several programs in a certain order.  The problem I keep running into is white spaces in the directories or the folders I need opened.

start C:\folder1\folder2\Folder To Be Opened


Grimbear,

I apologize that the thread was unable to remain on topic.

Good luck with your project Quote from: billrich on December 09, 2009, 09:57:37 AM
I apologize that the thread was unable to remain on topic.

Well, it was you, the banned loony, who helped drive it off topic, with your ridiculous posts, so maybe you should just STFU?

Why are you still here, by the way?
Sorry for not checking this one sooner.  This was something that wasn't critical for anything in particular so I actually forgot about it !  But now that I read it thank you so much for the support and I'm going to try some of the stuff that you all mentioned, namely the first set of quotes to declare title and then the full literal path.

The variable there was just an attempt to force the folder to open something with a white space because I was hoping that through a variable it would take the literal string.

Also i guess I should have mentioned what I was trying to do if I didn't this is a program to run at startup to open the 3 folders that I work out of at work, they need to be opened in sequence so I'm going to have to put a delay between each one because some open faster than OTHERS (they're on different drives).  It's a nominally simple task, but my unfamiliarity with batching complicates things  .  I'm hoping the start command is the proper command to have the folders opened.

Thanks again for all the replies
2190.

Solve : Regasm.exe from command line?

Answer»

Hi there

In my batch file i have the following code

%1 having a parameter as serverA

for %%x in (\\%1\c$\test1\entities\*.dll) do
\\%1\c$\WINDOWS\system32\regsvr32.exe /s %%x >>"file.log"

\\%1\c$\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe "\\%1\c$\test1\entities\function.dll" /codebase >>"file.log"

2 questions really

On the file.log i'm not getting any information displayed about those vb6.dlls that are registered. how do i go about getting this written

My second question is when i try to register function.dll which is a .NET dll using the regasm.exe i GET Flags="Unmanaged Code" error. Not sure whether this is a .NET error or a DOS SYNTAX error. can u please advice?

regards

Quote

for %%x in (\\%1\c$\test1\entities\*.dll) do
\\%1\c$\WINDOWS\system32\regsvr32.exe /s %%x >>"file.log"

ELIMINATE the /s switch. This will allow the message box text to presumably get redirected to the log file.

Quote
\\%1\c$\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe "\\%1\c$\test1\entities\function.dll" /codebase >>"file.log"

Check out this link where you can set the SecurityPermissionAttribute in the source code.

Good luck. Thanks for the response
That was very helpful of you Quote from: Sidewinder on December 16, 2009, 04:58:16 PM
Eliminate the /s switch. This will allow the message box text to presumably get redirected to the log file.

This response was in error. It's true the /s switch and redirection are mutually exclusive, however redirection only works for the STDOUT datastream which is generally found in DOS or NT command line programs. Regsvr32 is a Windows program that probably uses a Windows function to format it's output to a window.

Further testing showed that even errorlevels are always zero, whether the registration fails or succeeds. Consider trying one of the Windows Scrpt Languages where you can run regsvr32 externally from the script, wait on return,  and check the return code.

Sorry for any confusion.  regsvr32 shows it's output VIA Messagebox.

However, it does return an Exit code.

For example- I created the following script to check:

Code: [Select]echo off
regsvr32 /s C:\windows\system32\vbscript.dll
echo errorlevel is %ERRORLEVEL%
regsvr32 /s nonexistent.dll
echo errorlevel is %ERRORLEVEL%

when I run as a non-admin, I get:

Quote
errorlevel is 5
errorlevel is 3

5 is the windows error code for "permission denied" and 3 is the windows error code for "file not found". When I run as an administrator, I get:

Quote
errorlevel is 0
errorlevel is 3

so, regsvr32 returns an error level that is either 0 (for success) or a windows error code. Quote from: BC_Programmer on December 17, 2009, 03:14:04 PM
so, regsvr32 returns an error level that is either 0 (for success) or a windows error code.

It's a bit ODD. When I ran regsvr32 from the command line, then checked the return code, it always came up zero whether it was successful or not. When run from from a batch file, I got the same results as BC.

Oh well, at least the OP has a method to run his script.

2191.

Solve : Maintaining the file name in a piped find?

Answer»

That's not breaking it because that WORKS fine in the ORIGINAL one that I have.Alternative, using GNU awk.
Code: [Select]echo off
for %%I in (*.sql) do (
        gawk "/GRANT/&AMP;&/user_group/{print FILENAME\":\", $0}" %%I &GT; newfile.txt
)

2192.

Solve : Windows 7 won't recognize my old DOS programs?

Answer»

I SUPPOSE it was inevitable, but my new Windows 7 won't load Multimate or my Nutshell Database which I've used since the 80s. The error message suggests I contact the software manufacturer for a program compatible with 64 bits, but it's been out of business for twenty years. Does anyone have a suggestion?  ONE of the drawbacks to a 64 bit OS is it's inability to work and play well with some OLD apps. You can try running them in the various compatibility modes or a virtual machine, but in the end 64 bit is not as friendly as 32 bit. Quote from: Allan on December 17, 2009, 06:01:53 AM

One of the drawbacks to a 64 bit OS is it's inability to work and play well with some old apps. You can try running them in the various compatibility modes or a virtual machine, but in the end 64 bit is not as friendly as 32 bit.

Replace$(Quote,"friendly","Backward compatible",vbtextcompare)

Okay, this time you lost me. 

replace the word "friendly" with "backward compatible". Windows X64 isn't as backward compatible as the 32-bit versions. It only allows for running PROGRAMS that are a mere 15 years old or so.Wait. If you have a very old program you may not be concerned about speed.
So why not just run it in a vertebral machine?
Cant you do that will old DOS binaries?

EDIT; My Bad. I just read this the other day and forgot it.
Quote
Versions of Windows NT for 64-bit architectures (x64 and IA-64) do not include the NTVDM and are unable to run DOS or 16-bit Windows APPLICATIONS. This is because an x86-64 CPU in its full 64-bit mode cannot go to virtual mode without a hard reset. Virtual mode is not part of the x64 specification; the CPU needs to be running in x86 mode.
http://en.wikipedia.org/wiki/Virtual_DOS_machine
2193.

Solve : help - batch file to send automated email when windows service stops?

Answer»

The official recommendation for the Windows scripting engine is to use double slashes for switches intended to be read by the engine (cscript.exe or wscript.exe) and single slashes for options intended to be read by the script.

I am indebted to my friend Dias de Verano for this explanation of the reason.

Quote from: Dias de verano on September 27, 2008, 12:02:59 PM

The help visible when you type wscript /? (or more PROPERLY wscript //?) at the prompt shows 2 slashes for the switches available, although one will work in a simple case where the script itself is not supplied with any slashed parameters, as you have noticed.

The scripting host programs cscript.exe and wscript.exe are written to interpret doubly slashed command line switches as intended for themselves. The official advice from Microsoft is to use two slashes // for options specific to the scripting hosts cscript.exe and wscript.exe so that the hosts can distinguish between switches meant for them and those which may be meant for the scripts which they are running.

You may not have realised that, because the vbs file extension is associated (by Windows) with wscript.exe, the following have identical effect both at the command line and in a batch:

Code: [Select]wscript anyscript.vbs

anyscript.vbs
And so do these

Code: [Select]wscript //nologo anyscript.vbs

anyscript.vbs //nologo
So if anyscript had a parameter /goose EITHER of these following could be used. Without the double slash convention the second invocation format would be ambiguous: (as to which parameter was for cscript.exe and which one was for anyscript.vbs)

Code: [Select]wscript //nologo anyscript.vbs /goose

anyscript.vbs //nologo /goose
great salmon

I am impressed In addition to the above I point out that you can modify various script engine options:

you can set the default scripting engine to be either cscript or wscript

you can set the default logo behaviour to be //nologo or //logo

type either cscript //? or wscript //? at the prompt to see how.

Quote from: 29april on December 04, 2009, 02:52:03 PM
hi, I need to create a batch file that sends an email automatically when a windows service stops.

I could have the batch file run every 10 minutes to see if the service is active, but I have no idea how to give an if condition and then send an email. First of all is this possible? any suggestions would be great to know. Thanks.

Another way to approach this would be to monitor the service and send the email when the service status changes to STOPPED. Rather then manually run a batch file every 10 minutes or use the scheduler, this script will run in an infinite loop monitoring the service.

Code: [Select]strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("Select * From __InstanceModificationEvent " _
        & " Within 1 where TargetInstance ISA 'Win32_Service'")

Do While True
  Set objLatestProcess = colMonitoredProcesses.NextEvent
  If LCase(objLatestProcess.TargetInstance.NAME) = "" Then    'Name of service quoted; do not use display name
    If objLatestProcess.TargetInstance.State = "Stop pending" Then
    Call SendMail
    End if
    If objLatestProcess.TargetInstance.State = "Stopped" Then
    Call SendMail
    End if
  End if
Loop

Sub SendMail()
Set cdo = CreateObject("CDO.Message")
With cdo
.Subject = "Service Down" 'email subject line quoted
.From = "" 'your email address quoted
.To = "" 'recipient email address quoted
.TextBody = "" 'email body text quoted
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'your ISP SMTP server address
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
.Send
End With
Set cdo = Nothing
End Sub

FILL in the information where noted, save script with a VBS extension and run from the command prompt as cscript scriptname.vbs

Good luck.  Sidewinder, once the script discovers the service is in the stopped state,  will it keep sending emails every 10 minutes?
sidewinder

won't it require password for sending the mails

I mean if i add in the field From="[email protected]"

then will it send the email without the password here ?? Quote from: Salmon Trout on December 05, 2009, 08:47:22 AM
Sidewinder, once the script discovers the service is in the stopped state,  will it keep sending emails every 10 minutes?


No. The script only sends an email when an event changes the service state to stopped or stop pending. Apparently, services and processes act differently in that processes terminate and flush out of memory while services are forever and may simply stop running.

Quote from: Bukhari1986 on December 05, 2009, 09:09:36 AM
sidewinder

won't it require password for sending the mails

I mean if i add in the field From="[email protected]"

then will it send the email without the password here ??

Depends on the ISP. I got it to work as posted, but if a username and password are required (security breach)  there are CDO configuration items for just that purpose. The OP never even mentioned the service name and for all we know the email may be going through an internal network where username and password are not required.

 The link below is old material. It dates back to Windows 98.
OLEXP: How to Send Outlook Express Mail from a Command Line
I executed the below script but nothing happens.

If the service is stopped I get a dialog box with the wscript.echo command, if it is started, nothing happens. emails are not being sent out either (I am able to send independently from command prompt).

Is there a way I can spool on the entire script to a log file and find out what the issue is? do you guys see anything wrong with the below script? PLEASE let me know. Thanks for ur support.


strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &

"\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
    If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then
       WScript.Echo "Licensing Service is Stopped"
        Call SendMail
    End If
Next

Sub SendMail()
   Set cdo = CreateObject("CDO.Message")
   With cdo
      .Subject = "Service Down"         'email subject line quoted
      .From = "[email protected]"         'your email address quoted
      .To = "[email protected]"      'recipient email address quoted
      .TextBody = "Test"                           

   'email body text quoted
      

.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      

.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"   

      'localhost
      

.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      .Configuration.Fields.Update      
      .Send
   End With
   Set cdo = Nothing
End SubI couldn't see anything wrong, but I couldn't get it to run either, even with valid values. Question: why is the smtpserver set to localhost? Are you running your own mail server? or are you using an ISP?

Code: [Select]strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
    If objService.DisplayName = "Licensing Service" And objService.State = "Stopped" Then
       WScript.Echo "Licensing Service is Stopped"
        Call SendMail
    End If
Next

Sub SendMail()   
  Set CDO = CreateObject("CDO.Message")
  With cdo
.From = "[email protected]"
.To = "[email protected]"
.Subject = "Service Down"
.Textbody = "Test"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp mail server"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "userid"
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
' .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Configuration.Fields.Update
.Send
End With
End Sub

If using an ISP, check with them for the smtp server name and the port to use (this information is probably on their website). If you need to use authentication, uncomment the three configuration statements and fill in the values appropriately. Yeah, I know having the userid and password in the script is a security breach, but that is whole other subject.

Good luck.  or maybe there's something wrong with the schema site from M$.
2194.

Solve : Overwriting Folders?

Answer»

Hi there

I have a code in my batch file which renames a folder if it exists

ren "\\%1\g$\Utilities\Mgt\Archives\Mgt%Date:~-10,2%%Date:~-7,2%%Date:~-4,4%" "Mgt-1%Date:~-10,2%%Date:~-7,2%%Date:~-4,4%"

I have set -1 in front of timestamp condition which will rename my above folder. If these files are renamed more then once a day then i'm wondering is there a code or suggestion that i can get from here which would change the renaming condition probabably pass the renaming condition through an array

I'm a newbie here so please question me again if this question doesn't make sense. Quote from: captedgar on December 17, 2009, 08:17:31 AM

"I have a code in my batch file which renames a folder if it exists."

ren "\\%1\g$\Utilities\Mgt\Archives\Mgt%Date:~-10,2%%Date:~-7,2%%Date:~-4,4%" "Mgt-1%Date:~-10,2%%Date:~-7,2%%Date:~-4,4%"

It would be difficult to rename a folder when it does not exist. ( the worse problem is an error message. )  ( fix the rename folder and then worry about the no folder error message. )

The one line of code above to rename a folder does not provide enough information  for us to work with.

Where is the folder?  What is the CURRENT name of the folder?  Are the folders overwritten automatically?  Must you save the information in the current folder?  Would a backup utility work?  Or plain copy or xcopy? It might be easier to work with the files inside the folder?

Please provide all the code for the "rename the folder process"If you WANT to rename the folder on the second run (MGT exists) do you want to retain the existing MGT-1 folder?

One standard way that is often used to avoid name clashes is to USE the epoch number - the number of seconds since 00:00:00 Jan 1st 1970 ZULU, ignoring leap seconds, example: 1261089513 (2009-12-17 22:38:33Z) This is also called "Unix Time" The STREAMING videos on the RTVE (Spanish TV) video on demand website use this as a filename but modify this by adding milliseconds to the end. Example: 1258808030808.flv However YYYYMMDDhhmmss or some variant should work OK.
alternative: if you can download GNU win32 tools (coreutils) (see my sig), you can create timestamp with epoch using date command
Code: [Select]C:\test>gnu_date +%Y%m%d%H%M%s%N
2009121816011261123265179033100
then you can rename your files uniquely. see gnu_date --help for more info.You can do datestamp &AMP; epoch stuff in Visual Basic Script too. And get at it in a batch

Code: [Select]
echo off
echo wscript.echo DateDiff("s", "01/01/1970 00:00:00", Now())>Now2Epoch.vbs
echo wscript.echo DateAdd("s", wscript.arguments(0), "01/01/1970 00:00:00")>Epoch2Date.vbs

for /f "delims=" %%E in ('cscript //nologo Now2Epoch.vbs') do set NowEpoch=%%E
echo Epoch number now : %NowEpoch%

REM and back the other way...

for /f "delims=" %%D in ('cscript //nologo Epoch2date.vbs %NowEpoch%') do set EpochDateTime=%%D
echo Date and time    : %EpochDateTime%


Date & time format returned by Epoch2Date will be in your local format settings.

Code: [Select]Epoch number now : 1261126966
Date and time    : 18/12/2009 09:02:46Now that Dias de verano has posted, the solution for Overwriting Folders
is perfectly clear.

We can tell how pleased the OP is by the feedback from the original poster.

All new readers can quickly overwrite their old folders.

p.s.

Why would anyone not understand:

"for /f "delims=" %%D in ('cscript //nologo Epoch2date.vbs %NowEpoch%') do set EpochDateTime=%%D
echo Date and time    : %EpochDateTime%" Quote from: billrich on December 18, 2009, 07:17:26 AM
Why would anyone not understand:

"for /f "delims=" %%D in ('cscript //nologo Epoch2date.vbs %NowEpoch%') do set EpochDateTime=%%D
echo Date and time    : %EpochDateTime%"

Indeed. Why not? It is actually fairly obvious.
2195.

Solve : symbols?

Answer»

i wanna use ms-dos symbols like symbols to make a list i found a site for it if i try echo 210   it is 210 and not a piece of a list
\please helpYou need to write your question in better English so that we can understand what you are asking.

english is hard for me i'm japanese
but how to make a list in dos, each piece got a code like 210 until 1 to 300
if i type it the code fail and it is not a list but
120 120 120 120
200               200
200               200
200               200
134 134 134 134
still don't understand. Where do these numbers come from?
Quote from: pds on December 12, 2009, 08:35:19 AM

english is hard for me i'm japanese
but how to make a list in dos, each piece got a code like 210 until 1 to 300
if i type it the code fail and it is not a list but
120 120 120 120
200               200
200               200
200               200
134 134 134 134

I'm sorry for what Salmon said, we usually deal with people who speak English normally and are just too lazy to do it properly. I think you may be using Unicode, but the numbers won't do what you want in a batch file. Try this:

copy and PASTE (or insert) the desired symbols in Microsoft Word. When you select save as, choose to save it as a plain text format. Select the MS-DOS option when prompted and select ok. Open the file in Notepad and copy and paste the desired symbols into your batch file. he wants to know how to display the ASCII CHARACTER for a given character code; as far as I'm aware there is no way of doing this easily via batch.sorry i don't understandHere in the Western WORLD we do not use Unicode.
The symbols we can make from the keyboard are from 128 to 255.
Some examples:
128 = Ç
129 = ü
130 = é
144 = É
150 = û
165 = Ñ
170 = ¬
175 =»
221 =▌
222 = ▐
245 = ⌡
245 = ÷
 These were made with the alt key and the number pad. Quote from: Geek-9pm on December 12, 2009, 10:56:06 AM
Here in the Western World we do not use Unicode.
The symbols we can make from the keyboard are from 128 to 255.
Some examples:
128 = Ç
129 = ü
130 = é
144 = É
150 = û
165 = Ñ
170 = ¬
175 =»
221 =▌
222 = ▐
245 = ⌡
245 = ÷
 These were made with the alt key and the number pad.

Actually, all versions of windows NT (NT,XP,2000,Vista,7) are based on unicode. Windows has never used ASCII either; it's always (except maybe in versions before 3.0) been the ANSI character SET. the symbols aren't QUITE the same.

the command prompt however emulates the ASCII characters. Control+B gives friendly little smiley face. Quote from: BC_Programmer on December 12, 2009, 11:41:19 AM
Actually, all versions of windows NT (NT,XP,2000,Vista,7) are based on unicode. Windows has never used ASCII either; it's always (except maybe in versions before 3.0) been the ANSI character set. the symbols aren't quite the same.

the command prompt however emulates the ASCII characters. Control+B gives friendly little smiley face.

thanks this where i'm searching for little question if i press ctrl+a or c is that a dos symbol too?ok thanks by the way this is the program i use it is very hard on me, to understandhttp://www.petesqbsite.com/selections/express/issue21/freepascal.png Quote from: pds on December 13, 2009, 04:31:01 AM
ok thanks by the way this is the program i use it is very hard on me, to understandhttp://www.petesqbsite.com/selections/express/issue21/freepascal.png

hey pds you're japanese too and your link is't active :/
2196.

Solve : Need to load an old PC with MS-DOS with no cd drive.?

Answer»

I am trying to load an old!!!! LAPTOP that has no cd rom drive with just ms-dos. I have found several versions but they are all images for loading with a cd-rom. I can not figure out how to get it to install with just the floppies. I think I have all of the components but know how to put them on floppies to make it boot and install from just the floppies. Can anyone HELP? This is needed for an old program for a fire department to run an old radio system. Don't ask

Thanks for any help, very appreciated.A valid image of MSDOS 6.22 will have the 4 required zips to create the floppies needed...
Where did you DLoad from ? ?ya make a bootable floppy from winxp and use it ..
Another method is to remove the hard drive from the laptop and stick it into a desktop as a slave drive using the proper adapter. Then set up that drive with all the stuff on it. And, you will need to have a floppy disc  that has the system stuff on it. So once you get all back together you use the floppy to install the system files onto a hard drive.
Or you COULD use some variation of that. MS-DOS does not require lots of hardware drivers, so you could actually use a desktop machine and install the system on the  disc from the laptop. Once you have a FULL OPERATING MS-DOS system on your desktop, using the borrowed laptop drive, then the last thing is just to take that drive and put it back in the laptop and there you are.
Or some variation of that.

2197.

Solve : How to zip files in Batch...?

Answer»

Here is the script....


Code: [Select]SETLOCAL EnableDelayedExpansion
set destfolder=D:\copiedjpegs
for /F %%a in ('mountvol ^| find ":\"') do (

for /f "tokens=*" %%P in ('dir %%a*.jp*g /s /b') do copy "%%P" !desktop!


)

The JPEGs get pasted at Desktop one by one all which are found.

Can anyone tell me how to ZIP em all. http://www.winzip.com/index.htm

_______________________________



On the XP Pro OS  there is a built in compress ( zip )  procedure:

Start, Help and Support , index[ compress]

To create a zipped compressed folder
Open My Computer.
Double-click a drive or folder.
On the File menu, POINT to New, and then click Compressed (zipped) Folder.
Type a name for the new folder, and then press ENTER.
 Notes

To open My Computer, click Start, and then click My Computer.
You can also create a zipped compressed folder by right-clicking the desktop, pointing to New, and then clicking Compressed (zipped) Folder.
You can identify compressed folders by the zipper on the folder icon.
If you share compressed folders with users on other computer systems, you may want to limit the compressed folder names to eight characters with a .zip file name extension.
Related Topics


To add files to a zipped compressed folder
Open My Computer, and then locate the compressed folder.
Drag files to the compressed folder to compress them.
 Notes

To open My Computer, click Start, and then click My Computer.
Double-click programs and files in compressed folders to open them.
You can identify compressed folders by the zipper on the folder icon.
If a program requires dynamic-link library files or data files to run, those files must first be extracted. For more INFORMATION, click Related Topics.
Related Topics
this is a continuation of your previous post. you should continue from that post. Also, i have told you to download and use zip in that post, so if you are not that lazy, do that. Otherwise, if you have tools like winzip or winrar already installed, there are command line options you can also use. Check their documentation. Quote from: billrich on December 17, 2009, 07:53:51 PM

http://www.winzip.com/index.htm

_______________________________



On the XP Pro OS  there is a built in compress ( zip )  procedure:

Start, Help and Support , index[ compress]

To create a zipped compressed folder
Open My Computer.
Double-click a drive or folder.
On the File menu, point to New, and then click Compressed (zipped) Folder.
Type a name for the new folder, and then press ENTER.
 Notes

To open My Computer, click Start, and then click My Computer.
You can also create a zipped compressed folder by right-clicking the desktop, pointing to New, and then clicking Compressed (zipped) Folder.
You can identify compressed folders by the zipper on the folder icon.
If you share compressed folders with users on other computer systems, you may want to limit the compressed folder names to eight characters with a .zip file name extension.
Related Topics


To add files to a zipped compressed folder
Open My Computer, and then locate the compressed folder.
Drag files to the compressed folder to compress them.
 Notes

To open My Computer, click Start, and then click My Computer.
Double-click programs and files in compressed folders to open them.
You can identify compressed folders by the zipper on the folder icon.
If a program requires dynamic-link library files or data files to run, those files must first be extracted. For more information, click Related Topics.
Related Topics



Dear Billrich,

I know the procedure how to zip manually.

I clearly MENTIONED that I need the JPEgs to be zipped through Batch File automatically.

Please help me with what code should I use in batch file?? Quote from: ghostdog74 on December 17, 2009, 07:54:16 PM
Also, i have told you to download and use zip in that post, so if you are not that lazy, do that.

Dear Ghostdog74,

I am not lazy, I am posting this thread continously because, I don't no the procedure how to add in my batch file.

That's why I mentioned the code in my thread, to teach me where and what code should to be use in batch script.

I would really appreciate, if you add the zip command in my batch script and EXPLAIN me how it will work, so that I can learn something from you.

Thanks. Quote from: akki15623 on December 17, 2009, 10:21:22 PM
I am not lazy,
then tell us which zip utility have you decided to use and whether you have tried anything after reading their docs. Quote from: ghostdog74 on December 17, 2009, 11:34:33 PM
then tell us which zip utility have you decided to use and whether you have tried anything after reading their docs.


I have winzip, I installed that many months ago, I am trying to learn batch scripting since 2 days, I don't no how to use the command Quote from: ghostdog74 on December 17, 2009, 11:34:33 PM
whether you have tried anything after reading their docs.

I din't look at the docs, as I don't no what batch script is, so I din't took so care at it. I am now interested in batch script and need help in understanding.

Can you please explain me the zip command and tell me how to use that, when I need something to zip through batch script. Quote from: akki15623 on December 17, 2009, 07:42:51 PM

Can anyone tell me how to zip em all.

Download the Command-Line version of 7-Zip (http://www.7-zip.org/download.html)

Use the following command:

7za.exe -a -tzip bigfile.zip D:\copiedjpegs\*.jp*g

Explanation:
7za.exe = executable
-a = command to add files
-tzip =use the zip format
bigfile.zip = to this file (can exist, or it creates a new file
D:\copiedjpegs\*.jp*g = files to be zipped

and you don't need to copy them to the desktop first...
2198.

Solve : Do you know how DOS read a file??

Answer»

Can you EXPLAIN how DOS read a file?
WOULD you post some pictures to explain that?
Thank you.What do you mean?

I have a file that is created in MS-DOS.
How is the file read by MS-DOS? and how is is stored?
Thanks.Still don't know what you mean. You want to know how an operating system works?

Quote from: Dias de verano on January 24, 2009, 07:31:16 AM

Still don't know what you mean. You want to know how an operating system works?



That's what I think. How the '.bat' extension is reading your text, idk tbh.

BRIf I'm guessing right. He's wondering how a batch file is read. WELL, a batch file interpreter
(there are different ones in different systems) reads the commands. Then it executes those commands that it reads. If it finds an ERROR in those commands in THROWS out a message.
2199.

Solve : Batch 'For' Problem?

Answer»

Hi everyone,

I'm trying to do the following as I'm about to roll out a couple of different machines in my office. Each new machine will copy its appropriate drivers to a folder called c:\windows\support\drivers based on what's in it. That part already works.
Now there's a couple of folders in that Drivers folder. I'd like to expand the registry key at HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion called DevicePath to include all the folder contained in c:\windows\support\drivers. This should install all hardware by plug and play when the Sysprep machine image comes up.

I've got this so far:

dir /ad /b c:\windows\support\drivers > c:\windows\support\finishing\drivers.txt
set drvpath=%systemroot%\inf
setlocal ENABLEDELAYEDEXPANSION
   for /f "tokens=1" %%X in ( c:\windows\support\finishing\drivers.txt
            ) do (
               set drvpath=!drvpath!;c:\windows\support\%%x
               )
endlocal
reg add HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion /v DevicePath /t REG_EXPAND_SZ /d %drvpath% /f


But this doesn't do me any good as it sets the key to \inf. I'm stumped and can't work out what I'm doing wrong.
Any help greatly aprreciated.for the 'for' loop to read text from a file it needs to either use back quotes or translated into a COMMAND, comme sa:

Code: [Select]  for /f "tokens=1" %%x in ('type c:\windows\support\finishing\drivers.txt') do (
set drvpath=!drvpath!;c:\windows\support\%%x)
or

Code: [Select]  for /f "tokens=1 usebackq" %%x in (`c:\windows\support\finishing\drivers.txt`) do (
set drvpath=!drvpath!;c:\windows\support\%%x)
FBTried both, result is both times that DevicePath is set to \inf.

When I do the dir /ad /b I get a list of folders, each line one folder. Is it easier to replace the line breaks with semicolons?

Thanks for the quick reply btw.why are you using "tokens=1"?
I was under the assumption I had to state what I want taken / read from the .txt file. Wrong? Quote from: BamBam71 on January 24, 2009, 08:43:14 AM

I was under the assumption I had to state what I want taken / read from the .txt file. Wrong?

Depends. If you want the whole line, use "tokens="

Tried it, doesn't make a difference. Have you tried leaving echo on and watching to see how the variables expand?
here's the output:

dir /ad /b d:\*.*  1>d:\temp\test.txt

set drvpath=C:\Windows\inf

setlocal ENABLEDELAYEDEXPANSION

for /F "tokens=" %x in (d:\temp\test.txt) do (set drvpath=!drvpath!;c:\windows\s
upport\drivers\%x )

endlocal

del d:\temp\test.txt

set drvpath
drvpath=C:\Windows\inf

As you can see they don't expand at all 

I'm not bound to that way either. If one of you can point me in the right direction I'm just trying to accomplish this:
list of folders > registry key in the form of folder1;folder2;folder3 and so on.1. Move Setlocal Enabledelayedexpansion to before you set drvpath.
2. Remove Endlocal.
3. The "tokens=1" ensures that if a line in the text file has spaces, you will only capture up to the FIRST space.




THANKS A LOT FOR YOUR HELP!!!

This is how it works in the end:

setlocal ENABLEDELAYEDEXPANSION

dir /ad /b d:\vms > d:\temp\test.txt
set drvpath=%systemroot%\inf
for /f "tokens=*" %%x in ( d:\temp\test.txt
            ) do (
               set drvpath=!drvpath!;c:\windows\support\drivers\%%x
               )
set drvpath


Quote
set drvpath

this is more usual

Code: [Select]echo %drvpath%
But that's just a stylistic thing.

Glad it works.

By the way, you do know that you can avoid using a temp file?

Use for /f and enclose a command in single quotes, and the command output will be PARSED, line by line, as if it was in a file.

And put the loop on one line?

Code: [Select]setlocal enabledelayedexpansion
set drvpath=%systemroot%\inf
for /f "tokens=*" %%x in ('dir /ad /b d:\vms') do set drvpath=!drvpath!;c:\windows\support\drivers\%%x
echo drvpath=%drvpath%
2200.

Solve : Not Deleting BatchFile?

Answer»

How do I get the del command to work! .

Code: [Select]del /q "filename.bat"
I've tried that without quotes, and without the extension.The /q makes it quiet mode so it won't output anything to console. are you sure it's not WORKING?

if in DOUBT read the manual Code: [Select]del /?
FBHey? I'll just turn echo on and put that too /P so I can see the error....


EDIT: It still bombs out on me!if it bombs out open ANOTHER CMD then run the batch and when it bombs out the first CMD will catch the error. or at least that's the theory.

FBwait a second- are you trying to delete the batch file that the command is in?No, I've learned that before. I got it too work now... I had to manually put in the path though

but I used %homedrive%%homepath%\Desktop\"file.bat"

So I solved my own problem I guess.