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.

7951.

Solve : Unable to execute the Command?

Answer»

hi guys,
i have created a batch file which goes in this WAY
cd PROGRAM Files\Microsoft Visual Studio 10.0\VC
vcvarsall.bat
timeout 100
tf
pause

My problem is after vcvarsall.bat execution its not going to next command i,e tf command is not executing .
so can you guys please suggest me is the batch file creation is proper.i need to execute the tf commands after executing the vcvarsall.bat file from created batch fileuse the CALL keyword to launch batch files.

Code: [Select]cd "\Program Files\Microsoft Visual Studio 10.0\VC"
call vcvarsall.bat
timeout 100
tf
pause

thanks fox but i am facing 1 more problem now.
eventhough if i am using call keyword 'm unable to execute next command.
E:
cd Xilinx\14.6\ISE_DS
call settings32.bat
XMD
help running
cd C:/zynq_manufacturing_images
dow C:/zynq_manufacturing_images/fsbl_forced_jtag.elf
con
**this is the commands 'm written in batch file**
its working till call settings32.bat after that rest commands are not executing & even created batch file as stopped workingThere's a few mighty strange commands there.

But what you should do is put a pause command on the line above the XMD command and see if it executes and shows on the screen.

If it doesn't then something in the bat file is running and not returning to the cmd prompt. You need to find which command it is, or
show us and we can help.

i tried to put pause & its working till pause after that 'm unable to execute the rest of all commands:
E:
cd Xilinx\14.6\ISE_DS\EDK\bin\nt
pause
xmd.exe
pause
help running
cd C:/zynq_manufacturing_images
dow C:/zynq_manufacturing_images/fsbl_forced_jtag.elf
con
sleep 5
stop
dow -data devicetree.dtb 0x4A00000
dow -data devicetree_default.dtb 0x2A00000
dow -data uramdisk.image.gz 0x2000000
dow -data uImage 0x3000000
dow -data def_boot.bin 0x4300000
dow -data boot.bin 0x4200000
dow u-boot.elf
con
Pause

And i have attached image also how XMD command console looks like.
Please suggest me how to proceed as XMD console looks different

[recovering disk space, attachment deleted by admin]It looks like you are running a debugger and expect the batch file to enter commands into the debugger. It doesn't work the way you expect it to.

You need to read the debugger help to see how a script file can be used in the debugger.

Then a batch file can launch the debugger with a separate script file, if it supports that method of operation.It's actually looks like it's doing what it is supposed to do.

1.) Is there a scripting options for XMD?

2.) have you tried "start /wait xmd.exe" to force the execution of xmd before returning to the script?

7952.

Solve : Need help with variables...?

Answer»

I have an executable that returns the CURRENT date in yymmdd format. I have a need to automate the daily creation of a folder with this name, and move or copy files that are being overwritten nightly into this new folder. I thought if I ran this executable and redirected the output to a "date.dat" file, that I COULD use a batch file to type this value to a variable, then use a command like

md %1

to create the folder. Doesn't work, no matter how I try it. Any thoughts?Right idea, wrong variable name. Variables %1 thru %9 are INPUT variables to a process. Data returned by a process can be handled by a FOR statement.

Code: [Select]
for /f %%a in (date.dat) do (set yymmdd=%%a)
md %yymmdd%


You can use %yymmdd% anywhere you need to for your directory name.

The code only WORKS provided the date is the only data in the date.dat file. Type for /? at the command line for details on how to skip lines and otherwise process date.dat

Hope this helps. You most definitely do one thing at a time well. I also see more usage from this "for" command, and I THANK you very much

7953.

Solve : Batch Script Problem...?

Answer»

hi all,

i have recently been getting frustrated with this script that i am making as everything itry does not work,

BASICALLY the script asks the user how many drives does it want to set then asks them or the drives in question

CODE: [Select]:drives
echo How many drives do you want to set?
set /p drives=Drives:
set /a drives = %drives% +1
set /a a = 1
:set
set /p d%a% =Drive%a%:

set /a a = %a% + 1
if not %a% == %drives% goto set

echo Drives Set!
pause


i am having trouble echoing the d%a% value


any help will be GRATEFUL thank you !This is what I got. Is it supposed to do something else? I answered r, s, t as you can see...

Code: [Select]How many drives do you want to set?
Drives: 3
Drive1: r
Drive2: s
Drive3: t
Drives Set!
Press any key to CONTINUE . . .

as i said in my first post i want to echo the value of d%a%

al you have done is input 3 letters and there is no output, and before you say yes there is....there isnt.Oh I get it. You want something like an array.

Yes, i have read many batch file help websites but nothing makes any sense to me and nothing has worked so far, i would know how to do this in VB tho lol.

so yer im looking to create an array and then echo the array values.batch language does not have arrays.
ah right, is there any way i could do this then?vbscript would be easiest.
hmm but this is only a code snippet from my full program. was hoping i could solve this without having to change scripting type.You need call set and call echo.

Code: [Select]@echo off
set cnt=0
:loop
set /a cnt+=1
call set var%%cnt%%=value%cnt%
call echo %%value%%cnt%%%=%%var%cnt%%%
if %cnt% LSS 9 goto :loop ok thanks, but how would i alter this for user input?


edit - never mind ive figured it out

Code: [Select]@echo off
set cnt=0
:loop
set /a cnt+=1
call set /p var%%cnt%%=value%cnt%:
call echo %%var%cnt%%%
if %cnt% LSS 9 goto :loop
pause

7954.

Solve : It doesn't works as a windows service?

Answer»

hi,

i' m using this batch file to make files and folders backup:

BATCH 1

net use h: \\server\backup

:INICIO

REM COOP4

cd c:\windows\system32
xcopy instsrv.exe "h:\backup\COOP4\c\windows\system32\" /Y /I /k /D /H /C
xcopy srvany.exe "h:\backup\COOP4\c\windows\system32\" /Y /I /k /D /H /C
xcopy backup.bat "h:\backup\COOP4\c\windows\system32\" /Y /I /k /D /H /C
xcopy sleep.exe "h:\backup\COOP4\c\windows\system32\" /Y /I /k /D /H /C
xcopy backupstart.bat "h:\backup\COOP4\c\windows\system32\" /Y /I /k /D /H /C

cd C:\Documents and Settings\All Users\Documentos
xcopy *.* "h:\backup\COOP4\c\Documents and Settings\All Users\Documentos\" /Y /I /k /D /H /C /E

cd C:\Documents and Settings\Rui\Ambiente de trabalho
xcopy *.* "h:\backup\COOP4\c\Documents and Settings\Rui\Ambiente de trabalho\" /Y /I /k /D /H /C /E

cd C:\Documents and Settings\Rui\Favoritos
xcopy *.* "h:\backup\COOP4\c\Documents and Settings\Rui\Favoritos\" /Y /I /k /D /H /C /E

cd C:\Documents and Settings\Rui\Os meus documentos
xcopy *.* "h:\backup\COOP4\c\Documents and Settings\Rui\Os meus documentos\" /Y /I /k /D /H /C /E

sleep 30
goto INICIO


so far so good, everything works.

Now i'm creating a windows service able to run this batch.

The windows service works, but i have a problem when running the BATCH as a service: xcopy doesn't copy to or from MAPPED drives

i need some help here
A Windows service is automatically started when your system boots. It may be too early in the process to be mapping drives.

Any reason you cannot run your batch file from the task scheduler at startup? or even the start-up FOLDER? If you boot more than once a day, you can add code to your batch file to create a dummy file. If the dummy file exists with today's date, you know you backup has already run today and you can safely exit the batch file.

What did you use to create the service? These articles (here and here) may be of help.

Good luck. Quote from: Sidewinder on JANUARY 26, 2010, 08:03:13 AM

A Windows service is automatically started when your system boots. It may be too early in the process to be mapping drives.

Any reason you cannot run your batch file from the task scheduler at startup? or even the start-up folder? If you boot more than once a day, you can add code to your batch file to create a dummy file. If the dummy file exists with today's date, you know you backup has already run today and you can safely exit the batch file.

What did you use to create the service? These articles (here and here) may be of help.

Good luck.

Thank you for your help.

let me try to explain in my poor english.

the mapped drive is already there when service starts.

i use this to create the service:

net stop backup
instsrv BACKUP REMOVE
instsrv BACKUP c:\windows\system32\srvany.exe
Reg add HKLM\SYSTEM\CurrentControlSet\Services\BACKUP\Parameters /v Application /d c:\windows\system32\backup.bat
net start backup


First i stop it (if it's running)
then i remove it (if it exists)
then i create it and i start it

i made this batch because it is easier to create the service.

the real problem here is (the mapped drive is already there when it runs as a service):

local drive - running as a service - ok
local drive - not running as a service - ok
mapped drive - running as a service - NOT ok
mapped drive - not running as a service - ok

i hope you have any ideas
The service starts before any user is logged in which I think is the problem with mapped drives. All the files probably need to be local or use UNC paths.

Try using UNC paths....can't hurt.

Good luck. First off all, I don't know how to use UNC Paths.

Another way to put the problem (perhaps more easier to explain):

i have a mapped drive here called Z (it's already mapped... i'm able to access it, and so on, and so on)

in a comand line i wrote

z:

then

xcopy z:\server\*.* "H:\backup\PC_SERVER\E\server\" /Y /I /k /D /H /C /E

everything worked.


After this test i made a batch file with the two lines:(z: it's already mapped... i'm able to access it, and so on, and so on)


z:
xcopy z:\server\*.* "H:\backup\PC_SERVER\E\server\" /Y /I /k /D /H /C /E

i runned the batch file... everything's fine.


Then i put this batch as a service(z: it's already mapped... i'm able to access it, and so on, and so on)


nothing happened...

Why?
I noticed that running as a service, the batch file doesn't change to drive Z: (this only happen with mapped drives, with local drives it works fine) and if it doesn't change to z:, it is not able to xcopy z:\server and it stops



Quote
After this test i made a batch file with the two lines:(z: it's already mapped... i'm able to access it, and so on, and so on)


z:
xcopy z:\server\*.* "H:\backup\PC_SERVER\E\server\" /Y /I /k /D /H /C /E

i runned the batch file... everything's fine.

It probably works because you are signed into the machine. When the batch file is run as a service, there is no user.

Quote
First off all, I don't know how to use UNC Paths.

Sure you do. This is a UNC path: \\computername\sharename
When you mapped the drive you used a UNC path: net use h: \\server\backup

Why is it necessary to run a backup as a service? You can run the backup from the task scheduler (at startup) or even the startup folder found on the start menu. It would save yourself a lot of grief.
Quote from: Sidewinder on January 27, 2010, 06:16:02 AM
It probably works because you are signed into the machine. When the batch file is run as a service, there is no user.

Sure you do. This is a UNC path: \\computername\sharename
When you mapped the drive you used a UNC path: net use h: \\server\backup

Why is it necessary to run a backup as a service? You can run the backup from the task scheduler (at startup) or even the startup folder found on the start menu. It would save yourself a lot of grief.


I just don't want the black window appears on screen even if it's minimizedQuote
I just don't want the black window appears on screen even if it's minimized

So that is what this is all about.

Have you even tried to use the UNC paths? After using Google, I discovered this a common problem with mapped drives and the only realistic solution is the UNC method.

Another alternative is to write a script that runs in Windows (VBScript is installed on your machine and does not require the cmd processor.) The problem is the XCOPY switches which may be difficult to duplicate in VBScript.

Good luck.

using UNC path i have the same problem


our conversation pointed me to the security of a share folder... i BELIEVE the solution is to give the right access to the rigth users

NETWORK SERVICE???
NETWORK???
ALL??
SYSTEM??


and others. or perhaps i will need to create a user and give him the access through network....


i don't know... but right now it seems that the problem is the service has no access rigths in mapped drive...

i 'm going to study this... i will tell you my conclusions.

thanks for your help

After a search, my first idea was right... it was the access rights of users to mapped drives....

somewhere i read that a mapped drive to be accessed by a service, must be created by a service with administrator rights...

suddenly i remember that i have the user administrador with password (created when i installed windows).

so i changed my batch files:

batch1 (to create the and start the service)

net stop BACKUP
instsrv BACKUP remove
instsrv BACKUP c:\windows\system32\srvany.exe
Reg add HKLM\SYSTEM\CurrentControlSet\Services\BACKUP\Parameters /v Application /d C:\windows\system32\backup.bat
net start BACKUP


batch2 (to be used as the service named BACKUP)

net use z: \\server\www *********** /USER:server\administrator
:START
z:
cd\
xcopy *.* "h:\test\" /Y /I /E /k /D /H /C
goto START

where *********** is the password of administrator


Thank you so much.

Our conversation helped me a lot.

Any time you need something... i'm here ok?Thank you for getting back to us. It never hurts to learn something new.

I admit that if the UNC method didn't work (it didn't), my next suggestion would not have been to have the service have administrator rights.

Stick around. As on all forums there are many more questions than answers. We can use all the help we can get.

Good luck.
7955.

Solve : using pc's as terminals?

Answer»

:-/ i need to communicated with a calcom plotter and my terminal SCREEN is down. i used my pc as a terminal once some years ago and i have FORGOTTEN how
help pleaseWhat is the plotter connected to? A previous poster had some luck with a product called TN3270 in which a PC can be made to EMULATE a 3270 using TCP/IP. I have no FIRSTHAND knowledge of this product but you can GET details at:

http://www.sdisw.com/

Good luck.

7956.

Solve : batch to make folder based on input?

Answer»

Hey guyz im trying to make a batch that will create a folder based on user input

eg

@echo off

echo Enter folder name:
set /a %input%

md %input%


this doesnt work for me. looks LIKE stupid code but i havent used variables before in batch.

ThanksQuote from: Khasiar on January 24, 2010, 04:01:26 PM


@echo off

echo Enter folder name:
set /a %input%

md %input%


C:\batch>type Khasiar.bat

Code: [Select]@echo off

echo Enter folder name:
set /p var=

echo var %var%

md %var%

dir /ad kh*
Output:

C:\batch>Khasiar.bat
Enter folder name:
KHAS
var Khas
Volume in drive C has no label.
Volume SERIAL NUMBER is F4A3-D6B3

Directory of C:\batch

01/24/2010 05:25 PM Khas
0 File(s) 0 bytes
1 Dir(s) 303,069,970,432 bytes free
C:\batch>Quote from: Khasiar on January 24, 2010, 04:01:26 PM
Hey guys I'm trying to make a batch that will create a folder based on user input


Code: [Select]@echo off

echo Usage xxh.bat "folder name"

pause

md %1

dir /ad %1*

Output:

C:\batch>xxh.bat john

Usage xxh.bat "folder name"
Press any key to continue . . .
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

01/25/2010 12:30 PM john
0 File(s) 0 bytes
1 Dir(s) 303,028,146,176 bytes free
C:\batch>Code: [Select]@echo off

set /p fname =Folder Name:

md %fname%
7957.

Solve : Editing config.sys?

Answer»

I am trying to edit a config.sys FILE to allow booting only from CD-ROM. This is the file that I have, but I haven't found a good explaination of what to edit. It needs to be generic, if possible, so it will work on different systems.

DEVICE=HIMEM.SYS /testmem:off
FILES=30
BUFFERS=20

DEVICE=cd1.SYS /D:tomato

rem DEVICE=cd1.SYS /D:tomato /P:1f0,14
rem DEVICE=cd1.SYS /D:tomato /P:170,15
rem DEVICE=cd1.SYS /D:tomato /P:170,10
rem DEVICE=cd1.SYS /D:tomato /P:1e8,12
rem DEVICE=cd1.SYS /D:tomato /P:1e8,11
rem DEVICE=cd1.SYS /D:tomato /P:168,10
rem DEVICE=cd1.SYS /D:tomato /P:168,9

LASTDRIVE=Z


This is the autoexec.bat file. It should give the PATH to the setup.exe. autoexec.bat and the SETUP folder are in the same root folder.

@ECHO off

MSCDEX.EXE \SETUP\98SE\SETUP.EXE
Why not GET the pc/s to BOOT from cdrom in the bios setup!

7958.

Solve : MS DOS Computer?

Answer»

Hi,
As you might have already gathered, i am a FANATIC for old computers, especially ones to do with BBC Micro's or DOS. I wan't sure which category to put this in, (msdos or HARDWARE) but could anyone please give me the names of any MS DOS only computers that would still run the old DOS games you see FLOATING about on the web, (5.00 or higher) and be compatible with the floppy disc filing systems of today's MODERN computers... i need the actual name so I can search them on ebay....ThanksAmiga<pcdos\ crossdos /acorn/ibm/compaq/most you can use .......winpoet/......or emulators.........

7959.

Solve : Batch to read a text file line and save as a variable?

Answer»

Hi folks

I am an absolute novice at this, so please bare with me. I am trying to build a batch file that will read a line from a text file and save the text as a variable (say, "variable_name") that I can then use to open a file "variable_name".INP, create a folder called "variable_name", and run a series of other batch commands before looping back around and reading the next line of the text file and repeating the whole process.

This seems like a simple enough task but I am completely overwhelmed by the sea of information out there so any assistance would be very much appreciated.

I have found similar posts on this forum but am struggling to adapt them to my purpose so any suggestions are WELCOME,

Many thanksPerhaps outlining how I want to structure the .bat might make a reply easier and might help me more quickly learn this myself. This what I imagine the basic structure of the batch would be:

1) Open the text file
2) Read line 1
3) Set variable_name to whatever line 1 is
4) Open \path\variable_name.inp
5) Create folder \path\variable_name
5) Run .exe
6) Copy output files to \path\variable_name
7) Return to 2) and read line 2
Repeat until all lines are read

My apologies - I know this may seem lazy, but I would honestly post a first stab at this if I were able to get anything meaningful working, but right now I can't even figure out how read a line and set a variable to the value of a line :-(
It's ok. We just need some more information. Can you show us an example of a few lines of your file?Well, I've been bumbling around for the last few hours and seem to have stumbled BLINDLY upon some MEASURE of SUCCESS. Here is where I stand (please excuse the general inelegance and the especially horrific pathnames - I haven't been able to get variables for paths to work yet:

Code: [Select]FOR /F %%X IN (model_runs.txt) do (

copy "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\time.inps\%%X.inp" "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\"

erase "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\time.inp"

ren "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\%%X.inp" time.inp

mkdir "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Output\%%X"

cd "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\FTLOADDS\"

run2.bat

"C:\Program Files\Golden Software\Surfer 9\Scripter\Scripter.exe" "C:\Program Files\Golden Software\Surfer 9\Samples\Scripts\Stu_MultiContMaps.bas"

)
pause
Not too bad for an imbecile

7960.

Solve : Need help to script 'replace text as save file as'?

Answer»

Hi,

I am new to world of scripting, i need your expert help to execute a task for which i need a script.

Task:
I have a sample XML file, in which i need to replace a value (oldString) with (newString) and Save it as (filename).
I have excel SHEET with values (newString) & (filename).

I need to extract (newString) value from excelsheet, replace it in Sample XML file and Save it as (filename).
I need to do this for all values (in different rows) in excel sheet.

Please help me with Batch Script for same.
OS: Windows 7
CMD version: 6.1.7601If you show sample data then you stand a better chance of getting what you need.You cannot do this with only cmd. you will have to find some other external program to CALL to GET your newValues from the spreadsheet. If you post te xml file we MAY be able to help with that part.Thanks for showing your interest.

I am attaching files - SampleXML.txt & Source.txt

Task summary:
SampleXML.txt file has a value "oldString" which need to be replaced by value "newString" and this file need to be Saved as "filename.xml"

- SampleXML.txt file is used as REFERENCE having value "oldString"
- Source.txt is having 10 values of "newString" & "filename"

End result would be = there will be 10 files generated viz filename1.xml to filename10.xml

[recovering disk space, attachment deleted by admin]This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

It is a little more complicated because your source.txt has Unix line endings. If you use MSDOS files then it only needs the middle block of code.

Code: [Select]@echo off
:: convert hex 0d to hex 0d0a to give msdos line endings
type "Source.txt"|repl "\x0d" "\r\n" x >tmp.tmp

for /f "usebackq tokens=1,* delims=," %%a in ("tmp.tmp") do (
type "SampleXML.txt"|repl "oldString" "%%a" m >"%%b.xml"
)

del tmp.tmp

7961.

Solve : How to check the entered path is valid or not?

Answer»

Hi,

THANKS a lot. I have a Question.
I want to check the %1 argument is a valid path or not.

Let us assume my batch file NAME is " print. bat "
i am passing the first argument as C:\temp\data.txt.

d:\print c;\temp\data.txt

suppose if i gave the wrong path by giving " ; "
instead of " : " I have to convey it as wrong path.

HOW TO CHECK THE FIRST ARGUMENT IS A VALID PATH OR NOT?

Regards,
Arjun.
This may help you out:

Code: [Select]
@echo off
if not exist %1 goto error
print %1
goto end
:error
echo put your error message here
:end


Why bother? DOS will be more than happy to point out the error for you.

Hope this helps. HI,

Thanks for the reply. STILL i have some problem.
I want to create a Folder of given path as the %1 argument.

Ex: MD D:\temp

Suppose if i pass the wrong path by giving " ; " instead of " : " the MD creating with the name of only ' D '
not with ' D:\temp ' .

I dont want to create folder with a single letter. If we give wrong path i have to convey as its invalid path.

Can any one help me in this regard?

I want to check the given path is valid or not...how?


Regards,
Arjun.If you are typing the command at the command line, you'll just have to be more careful with your typing as there is no variable that you can intercept and process.

In a batch file, you could do this indirectly by parsing the path as if it were correct and then DISCOVERING it's not...

Code: [Select]
@echo off
for /f "tokens=1-2 delims=:" %%a in ("%1") do (
if .%%b==. goto error
md %1
goto end
)
:error
echo ERROR
:end


Please note that this solution is specific to the example you posted. Contrary to popular belief batch processing is not a programming language; in fact it's not even a good scripting language.

Check out the Script Center for a better set of tools.

Hope this helps.

7962.

Solve : Modify Registry entry with batch file?

Answer»

I am trying to fix a registry issue that was caused when my company upgraded from OFFICE 2003 to Office 2010. I have tried a few different things but have had no success. Heres the info:
Path: HKCR\applications\excel.exe\shell\open\command
Value: (Default)
RegKey: REG_SZ
Data: C:\Program Files\Microsoft Office\Office14\Excel.exe "%1"

I have tried the command below, and a couple variations, but it has not worked at all, Any help would be appreciated.

reg add HKCR\Applications\excel.exe\shell\open\command /ve /t REG_SZ /d "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE""1%" /f
Why would you need a batch file to do this ? ?This entry does not get upgraded when we did the upgrade. The path for excel.exe still point to the Office 11 folder, which no LONGER contains an excel.exe. I would like to create the batch file so that I dont have to manually change the 1 to a 4 for all users, already had to do that a handful of times The easiest way would be to create a reg file and then use a reg import command inside your batch file to make the changes. If you don't need the batch file for any other functions, then you can just create the reg file.

How to create reg file:

What you need to do is make the change on one system manually, then before you close the registry editor, right click on the folder that you are in (in your case I think it would be called command) and select export from the menu. Name the file what you like. In the same folder as that file, create your batch file and SIMPLY put...

@echo off
reg import [file name here].reg

Save that batch and now you can COPY, both it, and the reg file.It's a legit use for a batch file guys - this seems to work here.

Code: [Select]@echo off
reg add HKCR\Applications\excel.exe\shell\open\command /ve /t REG_SZ /d "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE \"%%1\"" /f

7963.

Solve : can i get a bat file to alert me if it fails??

Answer»

can i get a bat file to email me if it fails?

also, is there and easy way to schedule a bat file to run every night at a certain time?

Im trying to setup Jenkins, scheduler, here, but, its not going well. The commands im feeding it work in the cmd window, but, they dont work in Jenkins.


so im thinking, ok nevermind jenkins, why not just create a bat file.
the only prob with that is how to get it to kick off, and how to get it to alert users to success or failure of the build.

kind regards,
brian .Quote

can i get a bat file to email me if it fails?


Yes and No ... If it fails it can not report failure, so you need a 2nd PROCESS which could be a different batch file that performs a checkup on the batch that is to be monitored for failure and performs the e-mail through 3rd party software that allows for e-mail sent from COMMAND line.

I made a C++ program that checked a Routine1_log.txt file for the date. The batch process started at 12:15am and so if it completed successfully, (got to complete the entire instruction set of the batch file), at the end of this batch file I had a echo. %date%>Routine1_log.txt to pass the date to this log file. The C++ program I wrote would run at 4am and test to MAKE sure that todays date matched that of the Routine1_log.txt file. If it was a match then no e-mail alert. If there was a mismatch, then I would be sent an e-mail. I then was able to check my e-mail first thing in the morning and see what processes failed if any did. It was a very rare occurrance to have a batch malfunction or fail to complete, but it happened 2 times in 5 years.

Not to SIDETRACK, but I ended up creating a monitoring system that would give me a phone call and play prerecorded messages to myself as to the problems so I knew where the problem was and was able to get to the site and already know what I was up against before getting there. In addition to programs I wrote in C++, I used a cool software tool called Alert Ping Pro and bought a license of it. http://www.downloadsource.net/1844/AlertPingPro/ Figured I'd share this in case you need additional monitoring such as to make sure network attached devices are LIVE as well as I also had 4 other locations bridged to the central hub and I could tell when a site went offline from the central hub location.
Quote
also, is there and easy way to schedule a bat file to run every night at a certain time?
Yes IF Windows OS using Scheduled Task Manager to trigger execution of batch etc at a specific time.

Quote
Im trying to setup Jenkins, scheduler, here, but, its not going well. The commands im feeding it work in the cmd window, but, they dont work in Jenkins.

I have never used Jenkins, but I am assuming that your dealing with a common problem where you are trying to pass keystrokes to Jenkins that is running in a different window than that of the batch file. Easiest way to make this work is to use a keyboard/mouse macro creator such as jitbit and compile the routine to an exe form which can then be started from the batch file and copy/paste info or enter info into specific fields etc.Dave I know this a month or two later, but I just wanna say thanks for going to the trouble of writing your reply.
interesting reading, ill have to look more into each section.

regards,
redd . Hey, no problem ... usually when there is no response, we all figure that the request for help was resolved. Its all good!And not to worry about the time...it's nice enough you had the courtesy to return with a reply.
7964.

Solve : print sub-directorys?

Answer»

How can I PRINT the contents of a sub-directory. Or send them to a FILE that then can be printed. There used to be a LIST COMMAND that would work. Thanks NormaNot really sure what you need.

Print list of files in directory:
Code: [Select]
dir directoryname > prn

Print list of files in directory and sub-directories
Code: [Select]
dir /s /b directoryname > prn


If what you wanted was the contents of the individual files, get back to US.

7965.

Solve : How to verify if a certain program is installed, then make an alert.?

Answer»

I need a script that will verify if a program is installed, then create an alert that the program exists on the system. I would APPRECIATE any HELP I can get.Check that the program install folder exists, and whether the executable program file is present in that folder. Tailor as appropriate for 32-bit and 64-bit systems.


Which program are you testing for?

I had an issue at a prior job where users who needed elevated privileges were installing unapproved software such as AOL Chat etc. I made a batch instruction that searched systems on the NETWORK for violation files and it would overwrite the EXE of that software with a custom EXE that I created with C++ stating that

Code: [Select] This software is not approved for use on this computer

Please contact the network administrator if you have any questions
One person was extremely upset about this lack of chatting on the clock when they should be working on graphic design. But the computers belong to the company, not the employee!

It stopped the problems and it was amazing that certain individuals got more work done

* I was waiting for someone to catch on to this EXE swap and get smart to overwrite my custom EXE with the CORRECT EXE to make the software function again, but no one was capable there of figuring this out and defeating the unapproved software BAN. We had about 12 programs that were part of this ban that an EXE would get overwritten to disable them.

7966.

Solve : MSDOS Batch Files: Input Command?

Answer»

I'm SURE there is an INPUT type of command for MS-DOS Batch files where I can ask for keyboard input & await a response, and assign Errorlevels to the response.

Nowhere can I FIND any reference to this feature in the section on Batch File Commands.

Please help; I used it a long while ago, but now cannot find it nor even recall enough of it to make it work.

I've looked at CHOICE, but that's not it as I recall.

There was something else specific to to getting input(s)and assigning my own errorlevel(s) to them, then PERHAPS also using them as part of output (e.g. ECHO).

You are indeed RIGHT. There was a program named INPUT that would take prompted input and store it in the environment, not set an errorlevel. An alternative was Answer which did the same thing but ran in DOS and Win9x.

Answer wrote an environment variable named ANSWER. The reason I mention this is if you have multiple inputs, it becomes necessary to set your own variable NAMES to %answer% since the ANSWER variable was overwritten on each execution.

Check it out and beware of unexpected results on XP or Win2000 machines.

Good luck.

7967.

Solve : Occasional beep when XCOPY process is running, heard through Sound Card??

Answer»

I was replicating the data of one external hard drive to another by use of a simple xcopy F:\*.* E:\*.* /s/d/y instruction and in the meantime with the data transfer scrolling in the command shell I was on Facebook and also had World of Warcraft running, and I have the game sound set to about 50% so that if I am playing music it is louder than the game. During the XCOPY process transferring about 206GB of data I heard a BEEP which came not from the internal PC speaker, but instead it came from the 5.1 sound system that is connected to my computer.

I was like... hmm, that is weird I will check on the shell window and it was still chugging away making a mirror copy of the other external hard drive. Oh well back to gaming, and then about 45 min later BEEP again. Ok this is strange...hmm.. Ok lets start Speedfan and check temps in this system. Temps are good and the CPU is at 43C with everything multitasking, ok I will set the graph of the speedfan and go back to gaming.

Then once again about 20 minutes later a quick 1/2 second BEEP. Ok lets look back at the TEMP graph... well it held steady between 41C and 44C for CPU and all other temps are normal. TIME to exit speedfan and go back to gaming.

XCOPY process ended. Closed the shell window and no more random beeps.

Gamed for 2 days and multitasked with all sorts of stuff running and no beeps.

Last night I went to update the 2nd external hard drive with the 1st external and started the same xcopy routine, and about 10 minutes later BEEP. Hmm... ok interesting so the random BEEP is directly related to this xcopy transfer process, although I have never seen xcopy cause a BEEP when its just xcopy and a simple instruction.

I have also looked into the EVENT logs of the Windows system to see if there was anything going on and its clean.

Anyone have any suggestions on what is going on? I am running Windows 7 32-bit with 3GB RAM and AMD Athlon X2 4450B 2.3Ghz CPU, and I probably should be using robocopy, but I like xcopy.

Posted this here because it seems to be directly related to XCOPY running on this computer when copying data between these 2 external hard drives connected at USB 2.0.

If it were every file causing a beep it would be this, but its very random and infrequent, and the data tested afterwards is an exact copy in file & folder count as well as capacity, so its not like its making a beep to an error condition during the copy process: http://strangetalk.net/viewtopic.php?f=3&t=104507

*** One problem I did have before all of this was that I was going to create an exact copy of this external to my local C: drive in folder named C:\ExtBackup\ but after a short while I would see no activity on the external and go to check on the shell window and I would find "Insufficient Memory" error. Looking this up since I have plenty of RAM, I found out that it was caused by the destination path greater than 254 characters in length. So I changed the folder to C:\x\ and it was then shorter than 254 characters and the error message no longer popped up, so i have some data on this external that is of long destination paths.It seems Xcopy does give warning beeps. Could these be when it finds existing destination FILES?

It doesn't make any noise here:

Code: [Select]@echo off
md testabc
echo abc >testabc\test.tmp
copy testabc\test.tmp .
xcopy test.tmp testabc\
pause
del testabc\test.tmp
del test.tmp
rd testabc
You'd THINK that Googling for e.g. "Xcopy beep" or "Xcopy beeps when" would shed some light, but I couldn't find much. An OS/2 cmd script I found had this:


/* Check if filespec exists to avoid xcopy beeps */
IF \FileExist( FileName) THEN
LEAVE

also I believe there have been a number of Xcopy versions for Windows; I wonder if some beep and some don't?

It seems that Xcopy and Robocopy do sometimes beep and this has puzzled a number of people:

Quote

The beeps that are sometimes heard when robocopy is running seem to correspond to situations when a file that has a name that is too long or has characters that are not recognized by the operating system.

It has been suggested that the beep is just the operating system echoing a character that is represented by a sound, there will be many of these in a given file. This is more likely to be related to the file name as the contents of the file is not echoed during copy.

I have seen the above suggested as explanations for Xcopy beeps also.


Also since it is coming via the sound card it's a system sound and if Xcopy does beep whether you hear it or not depends on the sound scheme selected and volume setting.
Thanks everyone. And I too expected to find more on Google.

Some of the paths and files are long and so I guess it could be this:

Quote
The beeps that are sometimes heard when robocopy is running seem to correspond to situations when a file that has a name that is too long or has characters that are not recognized by the operating system.

It has been suggested that the beep is just the operating system echoing a character that is represented by a sound, there will be many of these in a given file. This is more likely to be related to the file name as the contents of the file is not echoed during copy.

Checking the external against the destination is an exact match, so its not an error condition that skips a file or path that is too long. I guess it just is what it is. Just this is the first time I have seen it happen, and the last thing I would have expected was it to be from xcopy process, but thats what it is.

I guess I will ignore the occasional beep

Thanks everyone Turn the sound down....
7968.

Solve : Basic Help with XP Command-line utilities?

Answer»

Quote from: Jayell

I stated at the time that I didn't want to get too far into this but here I am anyway.

Quote from: Jayell
I'd be a LIAR if I said I hadn't at least wondered about scripts.

Ha! ha! ha! ha!

HOOK LINE and sinker here. 1,750,000 Google hits. And that's just batch scripting, add another zillion for VB scripting, AWK GAWK etc...

Thanks, Dusty. That ought to keep me busy for awhile.
7969.

Solve : command to pause a batch file?

Answer»

hi, im writing a really simple autoexec.bat to go on a dos boot disk. I would like to KNOW if there is a command that when USED in a batch file; will WAIT until enter is pressed or space or something and then carry on, because you need to put in NTFSdos on disc after the dos boot disc to carry on properly booting.
thanksYou can use the PAUSE command. Your batch file will sit and wait until you hit a keyboard key.

Thanks, that sounds about right! And, if you don't want the "Press any key to continue . . ." displayed on your screen, you can type PAUSE > NULL and "Press any key to continue . . ." won't display on your screen. (In case you want to WRITE your own personal message.)

7970.

Solve : Lable help?

Answer»

Does anyone know how to make a GOTO LABLE comand work only once in a batch file.

Its like this:

p=c:\windows\system\
:start
del %p%bob.exe
p=c:\windows\system32\
goto start


Is there a way of making it go up to the start and when it READS down to 'goto start' and skip it. instead of me writing it out agein like this:

p=c:\windows\system\
del %p%bob.exe
p=c:\windows\system32\
del %p%bob.exe
Doesnt matter, i FOUND a way but its a bit complicated.

7971.

Solve : Re: ms dos?

Answer»

Um, I would love to help you, but you NEED to be more specific. Exactly, what do you need? Because, this is what I THINK you're SAYING:

"I need to know the history of what my COMPUTER's been doing because my friend wrecked it somehow, and I want to know what Tech Support will do to it."

Is this about right?

7972.

Solve : I need help with parameters?

Answer»

I am trying to correctly use the ATTRIB command in MS dos. I keep getting a message that says: "Parameter format not correct". I am trying to open a file that is locked, and ATTRIB seems to be the only method of opening it, but I cannot get it to WORK. Here is exactly what I TYPE:
>>attrib -r -a -h -s C:\Documents and Settings\Owner\My Documents\My Pictures [BRANDON] /s
that command should allow me to open the file, but it says my parameter is incorrect. Please tell me what I am doing wrong and tell me EXACTLY what I need to type instead, tell me what spaces I need and dont need, and such. PLEASE HELP!!!!The first four attributes are fine, but the path to the file is a mess. First of all who or what is a [Brandon]? Owner is a variable that should be SET equal to the login name of the user.

Only use the /s switch if you need to drill down the directory tree looking for matches.

If you would post a specific file name, perhaps someone could give you exactly what you need.

Hope this helps. "Brandon" is the file I need to open but is locked, hence the reason I am trying to perform ATTRIB prompt.Code: [Select]
attrib -r -a -h -s "C:\Documents and Settings\Owner\My Documents\My Pictures\Brandon"


If Brandon has no extension then the code is fine as written otherwise add it within the quotes. If Brandon has those [] around the name you will need to include them too.

If the word Owner is a literal value in the path then you're OK, otherwise replace it with a real value or use the %UserName% variable.

The /s switch is usually USED with wild cards to drill down the directory. If you don't need it leave it out.

Good luck.

7973.

Solve : Backup script help?

Answer» HELLO all,

I was wondering could I get help with my backup script.

I have got my XCOPY working well. Copies all the files from A to B and only copy's the new or updated files from there on (this backup runs every day).

However when I delete a file from A (or move it to another folder) when the script runs again it keeps the original file in B or even makes another copy of the file in B if it was moved ELSE where.

What I want to do is to check ALL files and folders in B to see if they exist in A. If they dont exist in A then delete them from B.

(basiclly B is a direct mirror copy of A).

How would I code it?

I know I could simply delete the B files and xcopy the files again from A but that means I will be copying every file again and some of my backups are very big. What I want to do is to keep my incrimental xcopy command and then to have a loop that checks all B files if they exist at A and to ether leave them alone or delete them from B.

What I have been trying to do is export a .txt file with all files / directories from B then input each line as a variable -> check veriable exists in A then to ether ignore or delete the file from B then to move to the NEXT line in the text file (therefore the next file in the directory) and save that as the variable and start the loop again until all files (lines) have been processed but so far I have had no luck.

Hopefully there is a easier way.

Thanks in advance!Quote from: jokenno14 on January 26, 2010, 04:33:15 PM
What I have been trying to do is export a .txt file with all files / directories from B then input each line as a variable

Compare file names and contents with the Comp command:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/comp.mspx?mfr=true


C:\batch>comp /?
Compares the contents of two files or sets of files.

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[liNE]]

data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/D Displays differences in decimal format.
/A Displays differences in ASCII CHARACTERS.
/L Displays line numbers for differences.
/N=number Compares only the first specified number of lines in each file.
/C Disregards case of ASCII letters when comparing files.
/OFF[liNE] Do not skip files with offline attribute set.

To compare sets of files, use wildcards in data1 and data2 parameters.

C:\batch>


Code: [Select]dir /b c:\*.bat > batfiles.txt

dir /b c:\batch\*.bat > batfiles2.txt

comp batdiles.txt batfiles2.txt



I have not tested the comp command.Quote from: jokenno14 on January 26, 2010, 04:33:15 PM
(basiclly B is a direct mirror copy of A).

Since you appear to be using Windows 7, try ROBOCOPY with the /MIR option.

e.g.

Code: [Select]ROBOCOPY A B /MIRQuote from: oldun on January 26, 2010, 06:10:55 PM
Since you appear to be using Windows 7, try ROBOCOPY with the /MIR option.

e.g.

Code: [Select]ROBOCOPY A B /MIR

Wow! Never heard of ROBOCOPY! looks fantastic!

I should only need one line then:

robocopy A B /MIR / E /Z right? That will keep both destination and SOURCE the same but will it also act as a incremental backup?

Thanks for the help!You do not need /E with /MIR. Also, you only really need /Z when backing up to a network share.
7974.

Solve : What does this script do??

Answer»

We use a script to AUTOMATE the reboot of our servers. The script is run from the task manager with a parameter that indicates the number of times the routine should run before it quits. So it's CALLED like this: serverrebootscript.bat 100

The script starts like this:

Code: [SELECT]@echo off
If "%1"=="" GOTO ERROR
set E2=0
set E1=0
set E0=0
goto firstrun

:firstrun
query session >sessions.txt
FIND "Active"<sessions.txt
IF NOT errorlevel 1 GOTO loop

:loop
echo Users logged on, checking retry limit
echo Incrementing retry count
:E0
if %E0%==9 goto E1
if %E0%==8 set E0=9
if %E0%==7 set E0=8
if %E0%==6 set E0=7
if %E0%==5 set E0=6
if %E0%==4 set E0=5
if %E0%==3 set E0=4
if %E0%==2 set E0=3
if %E0%==1 set E0=2
if %E0%==0 set E0=1
goto DONE
:E1
set E0=0
if %E1%==9 goto E2
if %E1%==8 set E1=9
if %E1%==7 set E1=8
if %E1%==6 set E1=7
if %E1%==5 set E1=6
if %E1%==4 set E1=5
if %E1%==3 set E1=4
if %E1%==2 set E1=3
if %E1%==1 set E1=2
if %E1%==0 set E1=1
goto DONE
:E2
set E1=0
if %E2%==9 set E2=0
if %E2%==8 set E2=9
if %E2%==7 set E2=8
if %E2%==6 set E2=7
if %E2%==5 set E2=6
if %E2%==4 set E2=5
if %E2%==3 set E2=4
if %E2%==2 set E2=3
if %E2%==1 set E2=2
if %E2%==0 set E2=1
goto DONE
:DONE
If "%E2%%E1%%E0%"=="%1" GOTO RetryLimit

I think all of the "E" business above is a counter but I don't understand how it works so I'm hoping someone can explain it to me.

I'm also interested in knowing if I can replace all of that using something like this:

Code: [Select]SET /A Counter=0
goto firstrun

:firstrun
query session >sessions.txt
FIND "Active"<sessions.txt
IF NOT errorlevel 1 GOTO loop

:loop
SET /A Counter +=1
goto DONE

:DONE
IF "%1" EQU %COUNTER% GOTO RetryLimit

I've left an awful lot of the script out and just focused on the section I want to replace so if you notice holes in the script or things that could be written differently . . . I agree . For right now I'm just interested in learning about the "E" section.

Thanks for the help,

MJA word preceeded by a colon ":" indicates a flag/label/marker (people call them different things, I think Microsoft calls them labels) This works with the "goto" and "call" commands, and allows you to chunk your script.
Code: [Select]goto :blue
CODE1

:blue
CODE2

exit
When you get to 'goto :blue' it will skip down to the line ":blue" and then CONTINUE. This will skip whatever CODE1 is.

Code: [Select]call :Green
CODE1

exit
:Green
CODE2
goto :eof
In this case when you got to 'call :Green' it would skip down to the line ":Green" and continue until it runs into "goto :eof" and then goes back, so you would exicute CODE2 before CODE1. You can also use 'Call :Green' as many times as you wish in your code. It works much like a function in c++ would, but can start without being called (it will walk right past a flag, so be careful where you place them.)

You can replace it with this: Additionally everything in the second block of text does nothing - as there is no logic to do anything else but execute the code at :loop

Code: [Select]@echo off
If "%1"=="" GOTO ERROR

:firstrun
query session >sessions.txt
FIND "Active"<sessions.txt
IF NOT errorlevel 1 GOTO loop

:loop
echo Users logged on, checking retry limit
echo Incrementing retry count
set /a counter=counter+1
if "%counter%"=="%1" GOTO RetryLimitThank you!

MJ

7975.

Solve : Batch file not responding?

Answer»

When I execute my batch COMMAND
Code: [Select]PATH "C:\Program Files\folder\"
gui.exe -u username -p password -m Hostname -vp "View Point"

START /max IEXPLORE www.google.ca
It opens up the gui program and the code seems to stop there but does not OPEN up my IE until I close the 1st program then my batch continue to the next line and then open up the IE.

I would like it to open up the 1st program, then continue to the next line and open up my IE.

Any comments or suggestions is greatly appreciate.

tks

Use "START" to run gui.exewow, this is so embarrassing.

thank you Oldun.Quote from: locbtran on January 26, 2010, 05:55:19 PM

When I execute my batch command

gui.exe -u username -p password -m Hostname -vp "View Point"


Windows errors related to gui.exe?

gui.exe is a process belonging to an advertising program by searchnugget.com. This process monitors your browsing habits and distributes the data back to the author's servers for analysis. This also prompts advertising popups. This process is a security risk and should be removed from your SYSTEM.

http://www.liutilities.com/products/wintaskspro/processlibrary/gui/

7976.

Solve : basic question...?

Answer»

hello, i was wondering, is there a way to GET a list of all current DRIVES under dos? Have a comp here without windows installed and having difficulty accessing which drive is the cd-rom... doesnt appear to be D:....Well, I can't FIND any commands of that nature, but If you type A:, then B:, C:, D:, E:, F:, one of them should do it. It's a bit long, but it should work. PERHAPS DOS doesn't "see" the CD-ROM. Did you have it before?no

7977.

Solve : need some help witnh Batch command in Windows?

Answer» HI all,
I have LOG Compressor script which USED to work before, suddely it STOPPED working
and I am not able to understand the meaning for the following line
can some one help me in understanding this

if NOT EXIST E:\logs\web\%4 mkdir E:\logs\web\%4

what will this line do ??the batch is started with at least 4 parameters; the 4th is a folder name. If it does not exist it is CREATED.
7978.

Solve : Set Variable Equal to the Second Wednesday of the Month?

Answer»

Since the date of the second Wednesday of the month changes every month I am unsure of how to reference this day of the month so I can set it equal to a variable. My plan is to add the logic to a script I run every day to maintain the servers. Instead of manually running a Windows Updates check after Patch Tuesday I want my script to determine if it is the right time in the month to fetch updates.

So . . . how can I set a variable equal to the second Wednesday of every month?

Thanks,

MJGet the day, if it's Wednesday then check if the day of the month is between 8 and 14 (inclusive). If it is, bingo!

Untested.A clever solution. Thank you. Is there anything native or a CMD tool that you know of that does this?@echo off
Set SecondWed=False
Echo wscript.echo weekdayname(weekday(Date()), False) ^& "," ^& day(date) ^& "," ^& monthname(month(date),False) > DayDate.vbs
For /f "tokens=1,2,3 delims=," %%A in ('cscript //nologo DayDate.vbs') do (
Set DayName=%%A
Set DayDate=%%B
Set MonthName=%%C
)
Echo Today is %DayName% %DayDate% %MonthName%
If "%DayName%"=="Wednesday" (
If %DayDate% gtr 7 (
If %DayDate% lss 15 (
Set SecondWed=True
)
)
)
Echo Is second Wednesday: %SecondWed%
If "%SecondWed%"=="False" goto End

REM From here to :End will only be executed on the
REM target day

Echo Today is the second Wednesday of the month

:End





%date% holds the date, from there you can do some veriable arrangement to find it.

for me (could be diffrent format for you) %date% = Mon 09/09/2013

Code: [Select]
:find_2nd_Wed
setlocal EnableDelayedExpansion
for /f "tokens=* delims= " %%A in ("%date%") do (
set a=%%A
set b=%%B
)
for /f "tokens=2 delims=\" %%A in ("%b%") do set b=%%B
set /a b+=0

if "%a%"=="Mon" set /a b+=2
if "%a%"=="Tues" set /a b+=1
if "%a%"=="Thur" set /a b+=6
if "%a%"=="Fri" set /a b+=5
if "%a%"=="Sat" set /a b+=4
if "%a%"=="Sun" set /a b+=3

:loop.1
if not %a% GTR 14 (
if not %a% LSS 8 set day=%a%
) else (
goto :loop.1
)

set a=
set b=
goto :eof
This is untested, and some of the day names may be off. But it gives the general IDEA of I was trying to convey.
Quote from: Lemonilla on September 09, 2013, 02:12:51 PM

could be diffrent format for you

What if they live in (say) Europe?
HTTP://ss64.com/nt/date.html Gives a list of date -> locale

Also, you may find 'wmic path win32_localtime get day,dayofweek,weekinmonth' to be useful. According to ss64.com it is on XP Pro-win7.
Code: [Select]@echo off
setlocal EnableDelayedExpansion
wmic path win32_localtime get day,dayofweek,weekinmonth
for /f "tokens=1,2 delims==" %%A in ('wmic path win32_localtime get day^,dayofweek^,weekinmonth /value') do (
set %%A=%%B
)

set dow=%DayOfWeek%
set wim=%WeekInMonth%

Echo day = %day%
echo dow = %dow%
echo wim = %wim%


:loop.dow
if %dow% LSS 3 (
set /a dow+=1
set /a day+=1
)
if %dow% GTR 3 (
set /a dow-=1
set /a day-=1
)
if not %dow% EQU 3 goto :loop.dow

:loop.wim
if %wim% LSS 2 (
set /a wim+=1
set /a day+=7
)
if %wim% GTR 2 (
set /a wim-=1
set /a day-=7
)
if not %wim% EQU 2 goto :loop.wim

echo The second wednesday OCCURS on %day%
Sorry for the double post, just realized I had forgotten to clean up my code before posting it.
Code: [Select]@echo off
setlocal EnableDelayedExpansion
for /f "tokens=1,2 delims==" %%A in ('wmic path win32_localtime get day^,dayofweek^,weekinmonth /value') do (
if not "%%A"=="" if not "%%B"=="" set %%A=%%B
)

set dow=%DayOfWeek%
set wim=%WeekInMonth%

:loop.dow
if %dow% LSS 3 (
set /a dow+=1
set /a day+=1
)
if %dow% GTR 3 (
set /a dow-=1
set /a day-=1
)
if not %dow% EQU 3 goto :loop.dow

:loop.wim
if %wim% LSS 2 (
set /a wim+=1
set /a day+=7
)
if %wim% GTR 2 (
set /a wim-=1
set /a day-=7
)
if not %wim% EQU 2 goto :loop.wim

echo The second Wednesday occurs on %day%.
Thanks guys. As usual I requested help when I needced this right-away but other "hotter" things came up and I haven't gotten a CHANCE to apply your ideas yet. I'll post back for sure when I have. I really appreciate the help.

MJ
7979.

Solve : help with dos?

Answer»

i accidently hit restart ms-dos and when i turn on my computer it SAYS C:/windows and i DONT know what to TYPE to get it to WORK agian.win <enter>

7980.

Solve : CHOICE vs. SET command?

Answer»

I want to use BATCH files to allow a Yes/no prompt e.g. "Do you wish to continue? (Y/N)" but I am having trouble. I saw the CHOICE command, and tried it, but since I am using Version 5.1, I can't use it. This site says the SET command can be used the same way, but I can't figure out how to use the SET command in the same way. It doesn't seem to fit what the CHOICE command is capable of. And I don't know how to write code like this: I'm not a genius PROGRAMMER! Can anyone please tell me how to use SET this way?Code: [Select]
set /p var=promptstring


Use the %var% variable in your batch file as needed. Note: Choice only allowed ONE byte responses and used errorlevels. Set does not use errorlevels and response lengths are only limited by the size of the environment space.

Hope this helps. Well, I don't get BAD COMMAND OR FILE NAME anymore, but what comes after that line? I'm just learning, so I'm building a TEST.BAT. I want to make it so when you type 1, you GOTO 1, then 2, and so on. Could you please type up a sample text with such a SET command? I apologize, but I haven't used DOS for 12 years.This is about as simple as it gets. Perfect for a Wednesday afternoon.

Code: [Select]
@echo off
set /p var=Enter Option
goto %var%
:1
echo 1
goto end
:2
echo 2
goto end
:3
echo 3
goto end
:4
echo 4
:end


Good luck. Boy, I am a newbie, after all!

I looked at an example of SET and it said a bunch of stuff about things I could never remember. This is much easier. Thanks!

My lack of understanding just might have something to do with the fact I'm 14. Oh, well. Back to the typing board.Quote

I apologize, but I haven't used DOS for 12 years.


Quote
My lack of understanding just might have something to do with the fact I'm 14


Huh?What I just said is that I am 14 years old. I'm young, and didn't use more that a little of DOS growing up, since Windows came out. At least, that's when I GOT it.

Actually, I had one more question. In that example, what if someone types 5? That's not a choice, so it terminates the .BAT file. How do I get it to return to the beginning?That's one of the problems with set. Choice only allowed you to enter a defined response and otherwise beeped if you did not.

Code: [Select]
@echo off
:start
set /p var=Enter Option:
if %var%==1 goto 1
if %var%==2 goto 2
if %var%==3 goto 3
if %var%==4 goto 4
goto start
:1
echo 1
goto end
:2
echo 2
goto end
:3
echo 3
goto end
:4
echo 4
:end


Not nearly a clean as CHOICE, but it gets the JOB done. Thank you. I suppose that's it. I'll get back to learning some more advanced functions of DOS. Have a good day, Sidewinder.
7981.

Solve : Copy to clipboard without using clip.exe?

Answer»
Hello guys,

I've been using this method for a very very long time and got used to it,
But then I was wondering if there is another way to copy text to the clipboard
without using this file called clip.exe which I always have to carry with it in order
to make my batch script work with it. would be nice if some ONE can HELP me.
Thanks in advance


This works but in modern VERSIONS of windows it asks you if you want to allow it access.

Code: [Select] @echo off
echo.> %temp%\tmp.vbs set oIE=CreateObject("InternetExplorer.Application")
echo.>>%temp%\tmp.vbs oIE.Navigate "about:blank"
echo.>>%temp%\tmp.vbs Do Until oIE.ReadyState = 4:wsh.Sleep 50:Loop
echo.>>%temp%\tmp.vbs oIE.document.ParentWindow.ClipboardData.SetData _
echo.>>%temp%\tmp.vbs "text", wsh.stdin.readall

> %temp%\tmp.txt ECHO aaabbbccc
type %temp%\tmp.txt | CSCRIPT //nologo %temp%\tmp.vbs
del %temp%\tmp.vbs %temp%\tmp.txt
Thanks foxidrive,

What I'm really looking for is a way to copy and paste with my batch without the need of clip.exe
Now with the script you just posted, the only problem I see is that it involves the use of .vbs script
which in Windows 8 all my batch scripts containing .vbs seems to fail.

What error do you get?

The script above is no good for unattended work anyway, it asks for permission to run it each time.
7982.

Solve : How to use a batchfile in order to make a shortcut on the desktop??

Answer»

Hey guys,

i need some help with this issue. I already searched around, but couldn't find the proper SOLUTION to my problem:
I want my batchfile to create a shortcut to another batchfile with the same path on the desktop. The point is i don't want static paths as i would like to redistribute this "creator". I would like to focus on possibilities that are IMPLEMENTED in WinXP. shortcut.exe doesn't exist on my system and this VBS stuff seems to be a good alternative except that i don't know the substitudes for the path in which the scipt exist and i'm not sure in general how the code should look like. It would be really cool if you can solve the issue by only using a batch file.

Best regards,
Serious.RayWell for the path, use this:
"%userprofile%\Desktop\FILE.BAT"

and then in the VBS (a better solution in case some computers do have shortcut.exe and some don't) would require those enviroment variables added in somehow. Ok thx for this, but the .bat files are located like this:

D:\Program Files\Game\shortcutproducer.bat
D:\Program Files\Game\launcher.bat

Want-to-have:
%userprofile%\Desktop\launcher.lnk

Shortcutproducer is supposed to make a shortcut (launcher.lnk) on the desktop to launcher.bat which is in the same folder as shortcutproducer.bat. So the target path for the shortcut is the same as in which shortcutproducer.bat and launcher are in: D:\Program Files\Game\. This path should be auto detected and used.A batch file might work?


C:\Documents and Settings\Bill Richardson\Desktop>type launch.bat

Code: [Select]@echo off
E:
CD "Program Files\Game"
dir /b

call shortcutproducer.bat

dir /b

call launcher.bat
C:

cd %profileuser%/desktop
Output:

C:\Documents and Settings\Bill Richardson\Desktop> launch.bat
launcher.bat
shortcutproducer.bat
Hello, This is shortcutproducer.bat
launcher.bat
shortcutproducer.bat
Hello, This is launcher.bat

C:\Documents and Settings\Bill Richardson\Desktop>Shortcut.exe is part of the NT Server Resource Kit. It's about 11MB which is a lot of overhead for a single program. I could not find a reputable site for the single program download.

An alternative is VBScript which comes with Windows and is much more elegant than any batch file could ever hope to be.

Code: [Select]set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Shortcut Script.lnk")
oShellLink.TargetPath = WScript.ScriptFullName
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "CTRL+SHIFT+F"
oShellLink.IconLocation = "notepad.exe, 0"
oShellLink.Description = "Shortcut Script"
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save

Fill in the values as needed (they are the same as if you right clicked the desktop and created a shortcut manually). Currently the script will create a shortcut to Notepad on the desktop which uses the user path to the desktop and will change from machine to machine.

Good luck.

Thanks. After additionally searching for the "current directory" stuff i was ABLE to finish my vbscript:

Code: [Select]set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
strCurrentDirectory = WshShell.CurrentDirectory
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Game Launcher.lnk")
oShellLink.TargetPath = strCurrentDirectory & "\launcher.bat"
oShellLink.WindowStyle = 1
oShellLink.IconLocation = strCurrentDirectory & "\game.ico, 0"
oShellLink.Description = "Game Launcher"
oShellLink.WorkingDirectory = strCurrentDirectory
oShellLink.Save
So the variables i was searching for can be obtained like this:

Code: [Select]set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
strCurrentDirectory = WshShell.CurrentDirectory

7983.

Solve : check for numerical values in a .txt file?

Answer»

I have an MS SQL query that outputs a .txt file containing a 6 character numerical string in the first line, STARTING at pos 1.
If the query has no result the output will be whitespaces in the 1st line in the 7 first POSITIONS in the same .txt file (and for some reason a 2nd line with lots of whitespaces).

I've run into problems since the string in pos 1-6 in 1st line of the .txt file is used as input string to another application that goes bananas if I put null/whitespace into it.

How can I check if the .txt file actually has 6 numerical CHARACTERS in the first line at pos 1-6?

I'd appreciate any help... Code: [Select]set /p "var="<"file.txt"
if "%var%"==" " echo seven spaces were found.Thanks foxidrive...it's ALWAYS so easy once you see the code...

Have a great DAY

7984.

Solve : batch to delete directory and subfolder files?

Answer»

Dear all,

Can you please help me in creating a batch file, to delete directory and subfolder files.


Thank you,
puli,
Sys adminHave you had a look at the help ?
Type help at the command promptQuote from: puli.sysadmin on January 25, 2010, 03:47:29 AM

"Can you please help me in creating a batch file,
to delete directory and subfolder files."


C:\batch>type deldir.bat

Code: [Select]@ECHO off

md puli
cd puli

md subpuli

echo puli in subpuli > puli.txt
dir
type puli.txt

cd \
cd batch

echo.

echo REMOVE directory and subpuli

echo.

rd /s puli

echo.
Output:

C:\batch>deldir.bat
Volume in drive C has no label.
Volume SERIAL Number is F4A3-D6B3

Directory of C:\batch\puli

01/25/2010 01:04 PM .
01/25/2010 01:04 PM ..
01/25/2010 01:04 PM 19 puli.txt
01/25/2010 01:04 PM subpuli
1 File(s) 19 bytes
3 Dir(s) 303,027,625,984 bytes free
puli in subpuli

remove directory and subpuli

puli, Are you sure (Y/N)? y


C:\batch>dir puli
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

File Not Found

C:\batch>Thanks friend, for your inputs... the batch file is working fine.


Thank you so much.U cud also use this
Code: [Select]rd /S /Q NAMEOFTHEFOLDER
7985.

Solve : does anybody know how to email from batch file??

Answer» hello guys

i want to plot FTP Client and want to do setup for email on BATCH FILE! does anybody know about it?
Google for "Timo Salmi" and his batch FAQ. You will find scripts for all sorts of THINGS including emailing.I'm using blat.exe for sending e-mails from batch scripts and it works great.

Check http://www.blat.net/examples/batch.html out.
7986.

Solve : How to check if a directory is empty or not?

Answer» HI there,

I would like to copy files from one directory to another directory. If the source directory is empty, I would like to print a warning MESSAGE and skip the xcopy command. How to do it? Thank you.

J.If you test directory size in batch, it will always come up empty (restricted to files). XCOPY has the /s /e /t switches that may be ABLE to do what you need (type XCOPY /? at a command prompt for details) ALTHOUGH putting out a message could be problematic.

WinScript is always an option as folders have a SIZE property you can test.

Check out The Windows SCRIPT Center and it's links for more info.

Hope this helps. Hello,

Just made a .BAT file that answers your problem neatly:

@ECHO OFF

IF NOT EXIST %1 GOTO Error

XCOPY %1 %2
GOTO End

:Error
ECHO Source does not exist.
GOTO End

:End


Call it whatever you want; I call it ZXCOPY.BAT
Good luck!
7987.

Solve : Printing Q. Basic files on a USB printer?

Answer»

My nephew has created a 'virtual' machine within 'XP'to allow me to use DOS6.22 any own 'Q.Basic SOFTWARE. My computer has USB ports and a paralllel PORT (LPT 1). My INKJET printer has a USB plug. How can I get this printer to print from Q.Basic as WELL as from my Windows Office applications? (Assuming that there is a way)Im not familiar with the way virtual machines work, but you could save the source file as ASCII (Save /A I think, its been a while) to a LOCATION accessible by your main pc and print it from there

7988.

Solve : How to check to see if a service is running on multiple computers?

Answer»

Hey all;

I'd like to write a batch file (not good with powershell or the wmic command) that reads a TEXT file for computer names, then runs the sc.exe command against each one then builds a list (csv) file that looks like "computername, running or computername, stopped". I greatly appreciate any help.

cfowlerDumping the output from this command to a file is easy with adding >> to the END of the command followed by the file you want the output to go to. But if you want this data in a structure that will be clean to work with in CSV format in excel etc, you will have to clean it up with another routine to refine it.

so if you add >>Output.csv to the end of the instruction it will redirect the output which is normally to the user display to be written appended to the csv file. So after it is run on say 5 systems, you would have a list of info written to this csv. But it will be just as it is presented on a display but DUMPED as raw text to a csv file that has no DELIMITER to import clean to a spreadsheet.

If you just want to GENERATE a report to see which computers have services active or inactive you can just append the redirected output to a text File such as adding >>Output.txt to the end of the line that has the instruction to check for service running.Already capable of that - run the command from the command prompt manually against every machine - no thank you - over 1500 machines. Not looking for the appending command, looking for the way to employ a loop, if anyone can share that knowledge it would be greatly appreciated.Code: [Select]For /f "delims=" %%A in ('type "FILENAME_HERE") do
SC ....... >>output.txt
)
%%A is the name of the computer.

where FILENAME_HERE is formatted thus:
Code: [Select]Computer1
Computer2
Computer3
Computer4
Computer5
Computer6
Computer7
Quote from: cfowler on September 06, 2013, 09:49:56 AM

I'd like to write a batch file (not good with powershell or the wmic command) that reads a text file for computer names, then runs the sc.exe command against each one then builds a list (csv) file that looks like "computername, running or computername, stopped". I greatly appreciate any help.

"computername, running or computername, stopped"

What information do you want? I don't think you have specified the task properly.



Quote from: foxidrive on September 16, 2013, 07:20:05 PM
"computername, running or computername, stopped"

What information do you want? I don't think you have specified the task properly.

The end result of what I'm after would be a file called endresult.csv (for example), which would look something like this:

computername1,running
computername2,running
computername3,stopped

Does that explain it a bit better?Have you mentioned anywhere which service you are testing?
7989.

Solve : Executing a Remote Batch File?

Answer»

I need to execute a batch file on a set of other PC's from my work station. How do I write the batch file so that it executes on the remote pc rather than on my station?I have been FRUSTRATED by this myself. Apparently if the PC's are members of a WORKGROUP you cannot REMOTELY execute jobs. If the PC's are on a DOMAIN you can provided:

Quote

Before you can launch a script remotely, the system on which it runs has to be
configured to support remote scripting. This requires that Windows Script Host
5.6 be installed on the remote machine, that the user launching the remote
script be a MEMBER of the remote machine’s Local Administrators group, and
that remote scripting be enabled in the registry.


For an example of a remote script, CHECK out:

http://www.script-info.net/jsvbs/msscript/ws/wsconrunningscriptsremotelyrunningscriptovertherefromhere.php

For command line support check out REXEC: (you need to scroll down)

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx

Hope this HELPS.
7990.

Solve : XCOPY Error LOG??

Answer»

I use the following XCOPY syntax to backup to an external HDD:

xcopy /h /i /c /s /e /y C:\"Documents and Settings"\*.* G:\Backup\ /d


Q. How can I create an error log?

Q. How can I log files changed / new files copied?This code may work:

set log=c:\xcopy.log
set error=c:\xcopy.error.log
echo %DATE% %time% >> %log%
echo %date% %time% >> %error%
xcopy "c:\mirc\*.*" c:\test\ /c/y/i/e/v/f >> %log% 2>> %error%

[glb]Gizmo73[/glb]It works!

Q. What does the 2 >> mean?

Q. Can I put another 3 >> %user% behind it?DOS commands allocate devices for it's output. STDOUT which is USED generally for INFORMATIONAL messages that record the programs PROGRESS and STDERROR which is used for errors. By using >> %log%, you redirected the STDOUT data STREAM to whatever device %log% defined; by using 2>> %error% you redirected the STDERROR data stream to whatever device %error% defined.

I am not aware of a third device, but DOS can be quirky, so you never know.

Hope this helps.

7991.

Solve : Custom Batch TUI OS?

Answer»

Thanks......... Thanks........ sorry 2 post
Do any of you have any suggestions ( aparentlly this one is stupid ) for an OSwhile the whole concept is a tad unreasonable, I was specifically referring to to "converting batch to C++" as if they actually have ANYTHING in common... and then you go on to quote the main reason being that C++ is "standalone" which suggests your not very familar with C++ or PROGRAMMING languages in general.

And, of course, no real understanding of what an OS is. What your saying is, to you, like saying you'll build a SCALE model to test FIRST because it's easier, but what you don't realize is that you simply cannot make that scale model with the tools you propose; and even if you are able to make a basic interface program you will still be faced with the inevitable truth that it has no practical purpose. trust me, been there. One of my first "batch" projects. Of course I had the added advantage of knowing that what I was creating was not really an OS.

Thank you for explaining that.... well what do I do now, I've run out of Ideasthe first 500 prime numbers that are palindromes?

7992.

Solve : Color Text in vbs?

Answer»

So I am trying to rewrite one of my batch scripts in vbs to learn, and I have run into a problem. I don't know how to write this section in a different color (other than black). I tried wscript.font.color(0,255,0) which I found somewhere, but It didn't work. Any advice would be great.

Code: [Select]dim m(2),TODAY,dow,wim,mNAME,Mend(2),Dayy
dim cd
cd = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

today=day(date)
dayy=day(date)
m(0)=month(date)-1
m(1)=month(date)
m(2)=month(date)+1
mNAME=MonthName(m(1))
dow=weekday(date)

if m(0) = 1 then Mend(0)=31
if m(0) = 2 then Mend(0)=28
if m(0) = 3 then Mend(0)=31
if m(0) = 4 then Mend(0)=30
if m(0) = 5 then Mend(0)=31
if m(0) = 6 then Mend(0)=30
if m(0) = 7 then Mend(0)=31
if m(0) = 8 then Mend(0)=31
if m(0) = 9 then Mend(0)=30
if m(0) = 10 then Mend(0)=31
if m(0) = 11 then Mend(0)=30
if m(0) = 12 then Mend(0)=31

if m(2) = 1 then Mend(2)=31
if m(2) = 2 then Mend(2)=28
if m(2) = 3 then Mend(2)=31
if m(2) = 4 then Mend(2)=30
if m(2) = 5 then Mend(2)=31
if m(2) = 6 then Mend(2)=30
if m(2) = 7 then Mend(2)=31
if m(2) = 8 then Mend(2)=31
if m(2) = 9 then Mend(2)=30
if m(2) = 10 then Mend(2)=31
if m(2) = 11 then Mend(2)=30
if m(2) = 12 then Mend(2)=31

Do Until dayy=1
If dow = 1 Then
Do Until dow=1
dayy=dayy-1
dow=dow-1
Loop
Else
dayy=dayy-1
dow=7
End If
Loop


Do Until dayy=Mend
' Read File h.txt To Find Holiday Date
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(cd & "\h.txt", 1)
dim working
Do Until objFile.AtEndOfStream
working = objFile.ReadLine
a = Split("" & working & "", ":",-1,1)
wscript.echo(a(0) & "," & a(1) & "," & a(2)) '* This is the LINE I want to color.
Loop
objFile.Close
' READ.END

'''MORE CODE TO COME'''
Loop
You cannot colorize the console with native VBScript code. A messy workaround would be to launch your VBScript from a batch file and use the color command to colorize the console WINDOW. Only scripts using the CScript engine have access to the console (STDIN, STDERR, STDOUT).

If you have any of the Microsoft Office programs installed, you can put your output in say, an Excel worksheet or a Word document where you can change fonts and colors using the Excel or Word builtin methods and/or properties.

HTML Applications (VBScript wrapped with HTML) would work but they are designed to create their own window where your output would go. HTML Applications (HTA file extension) have no access to the console.

If you have the time and the patience, you can use Powershell. The Write-Host cmdlet (used for output to the console) has both foreground and BACKGROUND color parameters.

7993.

Solve : Create a bartch file that concatenates filename with directory name?

Answer»
Hi all,

I'm trying to write a batchfile (called "Convert" in the example below) that concatenates from a given directory, all file names in that directory with the directory names of teh subdirectories. E.g. running "Convert" in the RootDir of this directory structure :

RootDir > Test1Dir > MyFile.txt

would result in a filename "RootDirTest1DirMyFile.txt"

The batchfile would need to convert all files in RootDir.

Any help really appriciated.Do the files get new names but stay in their original locations, or do they get moved?

Quote from: Steven on January 23, 2010, 07:54:03 AM
RootDir > Test1Dir > MyFile.txt

Would result in a filename "RootDirTest1DirMyFile.txt"

The batchfile would need to convert all files in RootDir.

Any help really appreciated.


C:\>type filedirname.bat
Code: [Select]@echo off

cd \

cd Test1Dir

dir

copy MyFile.txt xMyFile.txt
ren MyFile.txt RootDirTest1DirMyFile.txt

dir

Output:

C:\>filedirname.bat
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\test1dir

01/23/2010 11:23 AM .
01/23/2010 11:23 AM ..
01/23/2010 11:23 AM 8 MyFile.txt
1 File(s) 8 bytes
2 Dir(s) 303,144,689,664 bytes free
1 file(s) copied.
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\test1dir

01/23/2010 11:24 AM .
01/23/2010 11:24 AM ..
01/23/2010 11:23 AM 8 RootDirTest1DirMyFile.txt
01/23/2010 11:23 AM 8 xMyFile.txt
2 File(s) 16 bytes
2 Dir(s) 303,144,689,664 bytes free

C:\test1dir>Thanks all. The difficult thing to get solved is the automatic scan of the entire directory structure. The batch file would need to start from the root directory, and from that point, scan all subdirectories (multiple levels), search all files in those subdirs, and convert the filenames. Quote from: Steven on January 24, 2010, 02:27:52 AM
Thanks all. The difficult thing to get solved is the automatic scan of the entire directory structure. The batch file would need to start from the root directory, and from that point, scan all subdirectories (multiple levels), search all files in those subdirs, and convert the filenames.

There are ways of doing this. Can I please ask a clarifying question? It seems to me that what you want to do is this:

(Where D represents the drive letter) - start in some SUBFOLDER, an arbitrary DISTANCE down the folder tree, say:

D:\Some Folder\Some Other Folder maybe\Topdir

and look in all the subfolders under that folder, renaming all the files found as follows:

take the path from Topdir and the filename, and rename each file with a string which is its path and filename with the slashes removed thus

Topdir\animals\cats\lion.txt becomes Topdiranimalscatslion.txt

Each file keeping its existing extension and remaining in the folder in which it is found. The previous part of the complete path (e.g. Some Folder\Some Other Folder maybe\) not to be part of the new filename?

That is what I hope you can clarify.


Is that correct?

I have written and tested a batch script that seems to do what the OP requires ... if he/she clarifies as I asked, I will probably post it here, so let's see if they come back...

Wouldn't this work?

@echo off
setlocal enabledelayedexpansion
set path2top=D:\somedir\otherdir\
For /f "delims=" %%a in ('dir /b /s %path2top%') do (
set filepath=%%a
set filepath=!filepath:\=!
REM ren %%a !filepath!
echo Rename %%a to !filepath!
)

Untested. If it says it has "Renamed" the desired files to the desired name, remove the word REN and RUN the script again.

Quote from: Helpmeh on January 24, 2010, 09:57:44 AM
Wouldn't this work?


I thought the OP WANTED the relative path from some top folder which was not necessarily the root folder of a drive, therefore the full dir /b /s path would have to be processed somehow, and an /a-d might be handy...

This is what I hacked out...

Code: [Select]@echo off
setlocal enabledelayedexpansion

REM set top folder
set TopFolder="D:\SubRename\Animals"

REM make Topdir current directory
cd /d "%TopFolder%"

REM Get top dir's path
for /f "delims=" %%P in ("%TopFolder%") do set TopDirPath=%%~dpP

REM Set char to replace
Set ReplacedChar=\

REM Set replacement character(s)
REM Leave blank for none
set ReplaceWith=

REM Or e.g. replace with dash
REM set ReplaceWith=-

REM Or e.g. replace with -$$$-
REM set ReplaceWith=-$$$-

REM Or e.g. replace with a space
This is how you would do a space
set "ReplaceWith= "

REM For each file in and under top dir...
REM Change the filespec from *.* if desired to filter files
REM standard wildcard rules apply
REM e.g. *.txt to only operate upon .txt files
set filespec=*.*
for /f "delims=" %%F in ('dir /s /b /a-d %filespec%') do (

REM Find the file's full path, name and extension
set FullPath=%%~dpnxF

REM Remove part of path above TopDir
Set SubPath=!FullPath:%TopDirPath%=!

REM Replace char(s) in path and name
set NewName=!SubPath:%ReplacedChar%=%ReplaceWith%!

REM Inform user of old file path+name and new name
echo File: "!FullPath!"
echo New name: "!NewName!"

REM Rename command syntax
REM Rename [Drive:][\Path\]OldName NewName
REM Remove REM from following line after testing

REM Carry out rename operation
REM Remove REM to activate the next line
REM Rename "!FullPath!" "!NewName!"
echo.

)

echo Finished
pause


Before...

Code: [Select]D:\SubRename\Animals>dir /s /b /a-d
D:\SubRename\Animals\Test.txt
D:\SubRename\Animals\Birds And Fish\Eagle\Test.txt
D:\SubRename\Animals\Birds And Fish\Salmon\Test.txt
D:\SubRename\Animals\Cats\Lion\Test.txt
D:\SubRename\Animals\Cats\Panther\Test.txt
D:\SubRename\Animals\Dogs\Bichon Frise\Test.txt
D:\SubRename\Animals\Dogs\Poodle\Test.txt
D:\SubRename\Animals\Horses\Foal\Test.txt
D:\SubRename\Animals\Horses\Mare\Test.txt
D:\SubRename\Animals\Horses\Stallion\Test.txt
Run the batch...

Code: [Select]File: "D:\SubRename\Animals\Test.txt"
New name: "AnimalsTest.txt"

File: "D:\SubRename\Animals\Birds And Fish\Eagle\Test.txt"
New name: "AnimalsBirds And FishEagleTest.txt"

File: "D:\SubRename\Animals\Birds And Fish\Salmon\Test.txt"
New name: "AnimalsBirds And FishSalmonTest.txt"

File: "D:\SubRename\Animals\Cats\Lion\Test.txt"
New name: "AnimalsCatsLionTest.txt"

File: "D:\SubRename\Animals\Cats\Panther\Test.txt"
New name: "AnimalsCatsPantherTest.txt"

File: "D:\SubRename\Animals\Dogs\Bichon Frise\Test.txt"
New name: "AnimalsDogsBichon FriseTest.txt"

File: "D:\SubRename\Animals\Dogs\Poodle\Test.txt"
New name: "AnimalsDogsPoodleTest.txt"

File: "D:\SubRename\Animals\Horses\Foal\Test.txt"
New name: "AnimalsHorsesFoalTest.txt"

File: "D:\SubRename\Animals\Horses\Mare\Test.txt"
New name: "AnimalsHorsesMareTest.txt"

File: "D:\SubRename\Animals\Horses\Stallion\Test.txt"
New name: "AnimalsHorsesStallionTest.txt"

Finished
Press any key to continue . . .


After...

Code: [Select]D:\SubRename\Animals>dir /s /b /a-d
D:\SubRename\Animals\AnimalsTest.txt
D:\SubRename\Animals\Birds And Fish\Eagle\AnimalsBirds And FishEagleTest.txt
D:\SubRename\Animals\Birds And Fish\Salmon\AnimalsBirds And FishSalmonTest.txt
D:\SubRename\Animals\Cats\Lion\AnimalsCatsLionTest.txt
D:\SubRename\Animals\Cats\Panther\AnimalsCatsPantherTest.txt
D:\SubRename\Animals\Dogs\Bichon Frise\AnimalsDogsBichon FriseTest.txt
D:\SubRename\Animals\Dogs\Poodle\AnimalsDogsPoodleTest.txt
D:\SubRename\Animals\Horses\Foal\AnimalsHorsesFoalTest.txt
D:\SubRename\Animals\Horses\Mare\AnimalsHorsesMareTest.txt
D:\SubRename\Animals\Horses\Stallion\AnimalsHorsesStallionTest.txtQuote from: Salmon Trout on January 24, 2010, 11:05:06 AM
Hack

Mr. Trout you are very thorough and usually accurate. ( I have not tested your latest creation. )

What is the practical application for the batch that Steven, the Original Poster has requested?Thank you Mr Richardson.
7994.

Solve : re-archiving a file without...?

Answer»

Quote from: Ocalabob on April 11, 2013, 12:00:47 PM

Using WIN7 from a command prompt the line below worked for me:

Code: [Select]echo>>FOOT-PRO.TMS

I tested that and it puts "ECHO is off" inside the file.

This also works to change the archive attribute but appends a blank line. Maybe the teacher expects the file to be modified, but that's not in the spirit of the task.

Code: [Select]echo.>>FOOT-PRO.TMS
We still haven't solved this conundrum without moving or copying the file. Quote from: foxidrive on April 12, 2013, 01:38:09 AM
Maybe the teacher expects the file to be modified, but that's not in the spirit of the task.

I'd argue that GIVING stupid tasks with trick answers isn't in the spirit of learning.I agree. But I figured out a solution.

Code: [Select]echo e|edlin /b foot-pro.tms >nul
Cons are that it creates a .BAK file, ADDS an EOF marker and isn't meant to handle binary files.Also Edlin is not available on most default installs. Actually I don't think it works Post DOS5 edlin is a default utility in Windows 8 where I tested this.

It's also in a default Win7 install, and a W2k install and is in my XP install.I think I figured it out: it's only available on 32-BIT Versions of the OS. which is why I do not have it on my 64-bit Windows 8 or Windows 7. chophillies will have to comment if they have 64 bit systems. edlin and debug are 16 bit tools so don't work in 64 bit systems.

debug will write the file too and change the archive bit.Powershell's Set-ItemProperty can set / unset attribute bits, but this is not fundamentally different from using the ATTRIB command, is it?


COMPUTERS on campus run windows 7 64 bit. Most 32 bit os have been replaced on campus with the exception of a couple servers i use as vms for my networking class. There i can access a 32bit version of xp.

Since the command line course is also available to take exclusively online, i believe the solution she had in mind would probobly not be restricted to the type of os the student is using. Not every student who takes the command line course is required to take the networking course therefore any student with a more modern 64 bit os would be left hanging.

I cant wait till class tuesday to find out her magic answerI tried piping echo across to SET /P and redirecting but that still wrote a new line and I also tried redirecting nul into set /p and redirecting that to the output file but that didn't work either. I can't think of anything else to try.

>>foo.txt echo.|set /p.=
>foo.txtThought the compact command might work but still a no go.Quote from: chophillies on April 12, 2013, 12:26:32 PM
I cant wait till class tuesday to find out her magic answer
Please update us on the Magic Answer I believe 2 things...

A) The instructer is either cruel...or an idiot...
B) This exercise won't produce any good grade no matter what result but you'll probably do WELL on the amount of research...
7995.

Solve : DOS Emulator?

Answer»

I am looking for a DOS emulator that will run with Windows 7. I need to run some DOS BASED accounting software and need to print financial statements. Software I have tried in the past would not allow me to print. Does anyone have any recommendations? It probably matters which printer is specified in the DOS software - not all printer drivers will be emulated.We use local printers that are attached to our CPUs. All of our printers are DOS compatible. Do you think I would need different emulators for the various printers we use? You could try DOS Box. Even though the MegaBuild VERSION is obsolete (no support or updates), with a few changes to the configuration file and mapping the LPT1 device to the remote printer, I've been able to use a legacy 16-bit financial program (including printing checks) with no problems. For a local printer:

Code: [Select]Edit config file DOSBOX Megabuild like this

#parallel1=file append:C:\Users\user\filename.txt

Change to

parallel1=file dev:lpt1

You shouldn't have to CAPTURE the port (map LPT1). After installation, editing the config file will be a entry on your DOSBOX program entry on the start menu.

Good luck.

Quote from: dawnmattia on September 17, 2013, 07:43:15 AM

We use local printers that are attached to our CPUs. All of our printers are DOS compatible. Do you think I would need different emulators for the various printers we use?

The hardware printers are being driven by the emulator, through Windows drivers. The emulator has to capture the printer output from the virtual machine and I am suggesting that it may handle some printer types inside the virtual machine, but not others.

In other words, changing the printer in the dos software could help, if it is set to use some exotic printer.

sidewinder seems to have some experience there so give his SUGGESTIONS a go.
7996.

Solve : how to create a partition without losing any data?

Answer»

Hello EVERYONE. My computer died after INSTALLING a driver for an xbox 360 wired controller. I need to how to CREATE a partition without losing any data USING command prompt and am unable to FIND anything on google so far. Can anyone help me?

7997.

Solve : Copying same name files from different folders?

Answer»

Good afternoon to all, may I please ask for some help.

I have over 1000 folders named differently by date which contain the same number of text files all with the same NAME. I want to EXTRACT the same file from each different folder and CREATE the same folder structure somewhere else, however each folder only containing that particular file.

What I have

Folder1 -&GT; a,b,c,d
Folder2 -> a,b,c,d
Folder3 -> a,b,c,d
Folder4 -> a,b,c,d

What I want
Folder1 -> b
Folder2 -> b
Folder3 -> b
Folder4 -> b

I tried using a for loop in DOS together with the XCOPY command however I am not managing, any help would be much appreciated

Thanks

NoelDoes this do what you want?

Code: [SELECT]xcopy "c:\folder1\b" "d:\backup\" /s

7998.

Solve : pen drive infected with ffffffff.fff. How can I remove it?

Answer»

My PEN drive has got infected with ffffffff.fff. I have scanned it with Microsoft security essential and QUICK heal (PAID) antivirus scanners but it is still in pen drive.

Please help to REMOVE it.Post in MALWARE section of this site.

7999.

Solve : Batch Games?

Answer» HELLO. I have recently posted an article on tips for MAKING games with batch files, and here are a few TRICKS hat I have recently figured out. First, ALWAYS use variables for stats, or my Batch Stat Engine:
Code: [Select]:: Copyright Stinger721 Industries (c) 2010
:STATENGINE
set hp1=1
set hp2=2
set hp3=3
set hp4=4
set hp5=5
set hp6=6
set hp7=7
set hp8=8
set hp9=9
set hp10=10
set hp11=11
set hp12=12
set hp13=13
set hp14=14
set hp15=15
set hp16=16
set hp17=17
set hp18=18
set hp19=19
set hp20=20
set hp21=21
set hp22=22
set hp23=23
set hp24=24
set hp25=25
set hp0=0
set mp1=1
set mp2=2
set mp3=3
set mp4=4
set mp5=5
set mp6=6
set mp7=7
set mp8=8
set mp9=9
set mp10=10
set mp11=11
set mp12=12
set mp13=13
set mp14=14
set mp15=15
set mp16=16
set mp17=17
set mp18=18
set mp19=19
set mp20=20
set mp21=21
set mp22=22
set mp23=23
set mp24=24
set mp25=25
set mp0=0
set str1=1
set str2=2
set str3=3
set str4=4
set str5=5
set str6=6
set str7=7
set str8=8
set str9=9
set str10=10
set str11=11
set str12=12
set str13=13
set str14=14
set str15=15
set str16=16
set str17=17
set str18=18
set str19=19
set str20=20
set str21=21
set str22=22
set str23=23
set str24=24
set str25=25
set int1=1
set int2=2
set int3=3
set int4=4
set int5=5
set int6=6
set int7=7
set int8=8
set int9=9
set int10=10
set int11=11
set int12=12
set int13=13
set int14=14
set int15=15
set int16=16
set int17=17
set int18=18
set int19=19
set int20=20
set int21=21
set int22=22
set int23=23
set int24=24
set int25=25
set dex1=1
set dex2=2
set dex3=3
set dex4=4
set dex5=5
set dex6=6
set dex7=7
set dex8=8
set dex9=9
set dex10=10
set dex11=11
set dex12=12
set dex13=13
set dex14=14
set dex15=15
set dex16=16
set dex17=17
set dex18=18
set dex19=19
set dex20=20
set dex21=21
set dex22=22
set dex23=23
set dex24=24
set dex25=25
set luk1=1
set luk2=2
set luk3=3
set luk4=4
set luk5=5
set luk6=6
set luk7=7
set luk8=8
set luk9=9
set luk10=10
set luk11=11
set luk12=12
set luk13=13
set luk14=14
set luk15=105
set luk16=16
set luk17=17
set luk18=18
set luk19=19
set luk20=20
set luk21=21
set luk22=22
set luk23=23
set luk24=24
set luk25=25
set lvl1=1
set lvl2=2
set lvl3=3
set lvl4=4
set lvl5=5
set lvl6=6
set lvl7=7
set lvl8=8
set lvl9=9
set lvl10=10
set lvl11=11
set lvl12=12
set lvl13=13
set lvl14=14
set lvl15=15
set lvl16=16
set lvl17=17
set lvl18=18
set lvl19=19
set lvl20=20
set exp1=1
set exp2=2
set exp3=3
set exp4=4
set exp5=5
set exp6=6
set exp7=7
set exp8=8
set exp9=9
set exp10=10
set exp11=11
set exp12=12
set exp13=13
set exp14=14
set exp15=15
set exp16=16
set exp17=17
set exp18=18
set exp19=19
set exp20=20
set exp21=21
set exp22=22
set exp23=23
set exp24=24
set exp25=25
set exp26=26
set exp27=27
set exp28=28
set exp29=29
set exp30=30
set exp31=31
set exp32=32
set exp33=33
set exp34=34
set exp35=35
set exp36=36
set exp37=37
set exp38=38
set exp39=39
set exp40=40
set exp41=41
set exp42=42
set exp43=43
set exp44=44
set exp45=45
set exp46=46
set exp47=47
set exp48=48
set exp49=49
set exp50=50
set exp51=51
set exp52=52
set exp53=53
set exp54=54
set exp55=55
set exp56=56
set exp57=57
set exp58=58
set exp59=59
set exp60=60
set exp61=61
set exp62=62
set exp63=63
set exp64=64
set exp65=65
set exp66=66
set exp67=67
set exp68=68
set exp69=69
set exp70=70
set exp71=71
set exp72=72
set exp73=73
set exp74=74
set exp75=75


And now, for putting things in, like an impressionable variable use this example to your advantage:

Code: [Select]@echo off
:MAIN
echo ENTER your name:
set /p name=Your Name:
echo Hello %name%!!
goto EXIT
:EXIT
pause
exit


I don't KNOW of any other chunks of helpful code for batch fle game making. If you have any, please post:It would be better to store the information in files...so the information wouldn't be lost when the program closes.
\
8000.

Solve : How to get no messages from DOS when using "NET USE" command?

Answer»

I hope someone can help me to GET the messages from DOS, when using the "NET USE" command NOT on my screen.

I made a program in FOXPRO 2.5 (DOS) and my screen is completely gone when i use "NET USE"

Does sombody has an awnser??

HarryIf you want to stop all output from NET USE, you can add ' 1>nul 2>&AMP;1' after it.

EDIT: you do mean command prompt, not DOS right?Quote from: [emailprotected] on April 13, 2013, 08:28:37 AM

I made a program in FOXPRO 2.5 (DOS) and my screen is completely gone when i use "NET USE"

Explain what you mean, a BIT more.