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.

1401.

Solve : Error code 1706 when remote reboot the server?

Answer»

Dear All,

I RUN the operation menu to shutdown server or reboot server, with the code, but return the error code 1706. I SEARCH the error code but not to POINT of my problem.  I COPY the command to reboot , it able to do remote server reboot.  Please advice. 

ECHO 1 - Shutdown
ECHO 2 - RESTART
ECHO 3 - Ping test
ECHO 4 - Quit
ECHO.
SET /p M=Type 1  2  3  4  then press ENTER:
IF %M%==1 GOTO PING
IF %M%==2 GOTO SHUTDOWN
IF %M%==3 GOTO RESTART
IF %M%==4 GOTO QUIT

:PING
set /p servername=" Enter the server name "
set /p yesno=Are you ping the "%servername%" ? [y/n]
IF "%yesno%" == "y"  GOTO CONFIRM1
IF "%yesno%" == "n"  GOTO MENU

:CONFIRM1
ping "%servername%"

:SHUTDOWN
set /p servername=" Enter the server name "
set /p yesno=Shutdown the %servername% ? [y/n]

IF "%yesno%" == "y"  GOTO CONFIRM2
IF "%yesno%" == "n"  GOTO MENU

:CONFIRM2
shutdown -m \\"%servername%" -s 

GOTO MENU

:RESTART
set /p servername=" Enter the server name "
set /p yesno=Reboot the "%servername%" ? [y/n]
IF "%yesno%" == "y"  GOTO CONFIRM3
IF "%yesno%" == "n"  GOTO MENU

:CONFIRM3
shutdown -m  \\"%servername%" -r

GOTO MENU

exit

1402.

Solve : autoexec.bat stored in an EEPROM?

Answer»

Hi everyone!!

I have this problem with a pick and place machine. The program of the machine is stored in an EEPROM and when i start it up it it goes directly to it's start-up menu.
Now, the machine WORKS with DOS (it LOADS an autoexec.bat and a config.sys) Can i remove any LINE that loads the .exe file that starts the machine in ORDER to get the MS-DOS prompt at startup?

SORRY about my english!

1403.

Solve : Sleep - Batch Files?

Answer»

Hello, is there something SIMILAR to that "at" COMMAND, but for WINDOWS 98. Because for the "at" command, the batch file closes, or is hidden, and I was wondering if I could do that with a windows 98 ONE.

1404.

Solve : disable directory acess using dos command?

Answer» HELLO,
How do i disable the directory acess using DOS COMMAND?
so if SOMEONE tries to acess it from DOS or Windows ........ it should not get open.
Thank you
Regards,
prachiLook at the SYNTAX for "attrib" for your SYSTEM. I think you will find the answer there.

                                Phil
1405.

Solve : how works the 'DIR redirection'  ???

Answer»

The  command:

DIR > myfile.txt - Takes the output of dir and re-routes it to the file myfile.txt instead of outputting it to the screen.

my question:
after WICH pattern does is work? my portable MP3 player seems to run TRACKS according to this pattern, not after the alphanumeric sorting (renaming the files or giving them a sequential number does not help either)hi,
not sure if i understand u correctly, but the pattern for dir is DETERMINE by dir command.

ie to SORT by size of file dir /o:s

see dir /?

1406.

Solve : system.bat error?

Answer»

my pc is having a system.bat ERROR, what should i do to fix this error and what is the function of system.bat and its EFFECT to the entire operating system?SCAN for BUGS ? >http://securityresponse.symantec.com/avcenter/venc/data/bat.wimpey.dr.html  and what operating system have you got?and what is the problem you are having.

1407.

Solve : Compare the file with IF in Batch File?

Answer»

In the DOS BATCH file how can i compare the SIZE of two FILES  & call NEW batch file if it is equal

1408.

Solve : [enter] w/in a batch file?

Answer»

is there a WAY to instruct a batch FILE to ACT like the enter key has been HIT after INITIATING a .exe installation file?

1410.

Solve : Batch file active window scripting??

Answer»

Hi,

I'm a LITTLE new at this scripting stuff...What i need to do  is use the windows scheduler to schedule to open LOTUS Notes Application off hours. It opens with an active window asking for a password. I need to just send the password and it will open. I'm not sure how to go about getting past the password part...

I figured I could just use a simple COMMAND line batch file to do this, but is it possible to send KEY strokes to an active window using this??? Any direction anyone could GIVE me would be so great. Thanks ...

1411.

Solve : Date Stamp?

Answer»

hi all,

this is a SILLY question but i hope you all can help me...  

i want ot create a LOG file that has a date stamp... say after running a bat file, it will generate a log file bat_042604.log (for bat file run on Apr 26 '04) and bat_042704.log for run on Apr 27 '04.  

what command can i USE to put the date on a variable in a format 042604 an not 04/26/04  

can any one helpbtw i am using Windows NT ver 4...Hi
I use this to make a folder NAMED as date.
Ihave tested it with rename it SEEMED ok
I believe you can use it for time aswell

FOR /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do SET date=%%a-%%b-%%c
md %date%

1412.

Solve : is ther a way to run a batch prog silently?

Answer»

is there a WAY to run a BATCH program without a window open? therefore, when executed, it will not be seen by the user. Or perhaps there is some way to align it so it is off screen?
i just would like a program to run without the apearance of it doing so.
thanksTry echo off
I do that all the time,
whenever you need to SAY something from the script, use echo.
To stop just one COMMAND from showing, use
IE. del *.iniIf you run the batch file from a shortcut you can SET it to run minimised

1413.

Solve : .bat - delete files by creation date?

Answer»

hello....

i need a batch file (.bat) or help on ONE...
Basically i need SOMETHING that can delete the file on basis of the date it was created.

I am gonna use it for deleting my logfiles that are a week old.

Any SUGGESTION???

thanksHi
Until somebody comes up with the answer I create a hold folder then use scheduler to run a batch file that clears out last weeks and MOVES this weeks in.

1414.

Solve : Set a variable from a file or a command?

Answer»

I am trying to write a BATCH FILE that will set the value that a command returns to a variable.

For example

I have a command called STRINGS which returns the first 4 letters of a string.

It is used by writing

strings left today,4

and will return toda (the first 4 letters of today)

I want to set a variable to be the value that is returned, so that I can then test it.

I have tried

%6 = (strings left today,4)

if %6 == "toda"

Another way I have tried is to output the value to a file.

strings left today,4 > output.txt

but I don't know how to read the value of output.txt into a variable.

Can someone help me do this?


I noticed you did not have any replies to this. This is bad because I am tring to accomplish the same thing.
Example is: set osver=`ver`
Tring to set the output of the version command into the variable osver. In UNIX scripting this is very simple by just doing "osver=`ver`" and the results of the ver command would be stored in the variable called osver.
  Very interested if you found a solution that works because I have already tried the approach of putting the results into a file and then no sucess in reading it back out into a variable...
   LET me know if you have found a solution and I will check other places and let you know if I find something that works...

                                [email protected]Hope I can help......If you can output strings data into a text file you could then us the following to assign a varible

for /f "tokens=1-2" %%a in (output.txt ) do call c:\another_batch.bat %%awith the code

for /f "tokens=1-2" %%a in (output.txt ) do call c:\another_batch.bat %%a


refer to %1 in another_batch.bat

1415.

Solve : format drive?

Answer»

how do U format your hard drivejustin.......if you are running WinXP .......FOLLOW these INSTRUCTIONS....
http://support.microsoft.com/?kbid=313348#4

If your running some other O/S ...follow these instuctions...
http://avenir.dhs.org/articles/software/formatoften.html

Hope this helps.....Remember ,when you format ...all info on the drive will be removed , so save anything you want before you start.

Hope this helps

DL65  as dl65 all info will be LOST so save your drivers  and you can always look at this if you wish>http://www.newlogic.co.uk/kbase/fdisk/page1.htm

1416.

Solve : Program too big to fit in memory?

Answer»

Hello.

I'm running ms dos 6.22 on virtualbox. When I attach a floppy disk image on drive A and run INSTALL.EXE it SAYS "Program too big to fit in memory".

I set my base memory to 32MB.

What can I do?What program are you trying to install with Install.exe? Perhaps the software checks for space PRIOR to installation and the program needs greater than 32MB whereas the Floppy only has 1.44MB maximum on it.MS-DOS executables have their minimum memory REQUIREMENTS (conventional memory) coded into their headers. "Program too big to fit in memory" is an MS-DOS error which means you do not have ENOUGH free conventional memory.

You can check free memory using mem /c.

Though often it just means the executable is either corrupted or for a newer Windows OS.

1417.

Solve : Delete Lines From Plain Text File If End Of Line Matches Set Values?

Answer»

To preface, I have a folder named MOVIES that I store all of my movie files in. Within that folder are subfolders for each letter of the alphabet, the # sign (for movies that begin with a number or other non-alphabetic character), and a folder named MUSIC RELATED (for music related movies.)

I made the batchfile to by default, output a folder label, which is the letter of the alphabet that is the folder name, surrounded by dashes to make it very easy to see the next letter in the output file.  I can also provide the argument   /nolabels   to output without the folder labels, but that's beside the point.

OUTPUT EXAMPLE:

- - - - - - - -  - MUSIC RELATED  - - - - - - - -
VAN HALEN LIVE SHOWS    <--- This is a sub-folder that contains what it is named. Only the folder name is output, not its contents)
AC-DC - Let There Be Rock [1980].mp4
Mayor Of The Sunset Strip [2003].mp4
Mayor Of The Sunset Strip [2003].srt
Searching For Sugar Man [2012].idx
Searching For Sugar Man [2012].mp4
Searching For Sugar Man [2012].sub

- - - - - - - -  #  - - - - - - - -
2001 - A Space Odyssey [1968].mp4
2001 - A Space Odyssey [1968].srt
The 40 Year Old Virgin (Unrated ) [2005].mp4
The 40 Year Old Virgin (Unrated ) [2005].srt

- - - - - - - -  A  - - - - - - - -
A Street Cat Named Bob [2016].idx
A Street Cat Named Bob [2016].mp4
A Street Cat Named Bob [2016].sub
Airplane! [1980].mkv
Airplane! [1980].srt

... Etc ...

I have a batchfile that adds the names of movies to a plain text file, of all the folders and movie files within the folder that the batchfile is run from.
To make it clear, I have a folder full of movies with names such as the following:

EXAMPLE OUTPUT FROM EXISTING BATCHFILE:

                 
- - - - - - - -  - MUSIC RELATED  - - - - - - - -
VAN HALEN LIVE SHOWS
AC-DC - Let There Be Rock [1980].mp4
Mayor Of The Sunset Strip [2003].mp4
Mayor Of The Sunset Strip [2003].srt
Searching For Sugar Man [2012].idx
Searching For Sugar Man [2012].mp4
Searching For Sugar Man [2012].sub


The batchfile works perfectly, except that ideally, I would like for the .srt, .idx, and .sub (files that contain the subtitles for each movie) to NOT be included in the resulting text file output.

EXAMPLE OUTPUT OF THE DESIRED MODIFIED NO SUBTITLES BATCHFILE:

- - - - - - - -  - MUSIC RELATED  - - - - - - - -
VAN HALEN LIVE SHOWS
AC-DC - Let There Be Rock [1980].mp4
Mayor Of The Sunset Strip [2003].mp4
Searching For Sugar Man [2012].mp4


Ideally, I would like to have the same batchfile do this, but if need be, I could run my existing batchfile, then run a different batchfile to process the output text file from the first to ACHIEVE my desired result.

I am not against using an external program, such as the awesome Notepad++, from within the batchfile to do some processing if need be. But if POSSIBLE, it would be great to not use anything but the batchfile itself, or themselves, to accomplish everything.

I don't know how to check each output line for a certain ending, and to not output that line if it finds a match to any of the following endings:

.idx
.sub
.srt

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PART 2

I would also like to add another argument named   /noext   that would output everything the same, but strip off the file extension part of each movie.

EXAMPLE OUTPUT WITH THE  /noext  ARGUMENT SPECIFIED:

- - - - - - - -  - MUSIC RELATED  - - - - - - - -
VAN HALEN LIVE SHOWS
AC-DC - Let There Be Rock [1980]
Mayor Of The Sunset Strip [2003]
Searching For Sugar Man [2012]


I think I know how to do everything except how to strip off the file extensions for this part.

Attached is my batchfile as-is.

Any help is greatly appreciated?

- ThaumTry using findstr; eg.

Code: [Select]dir "%%a"/OGN /B | findstr /v /i "\.srt$" | findstr /v /i "\.idx$" | findstr /v /i "\.sub$"

Edit: formatting; looks like markdown doesn't work on here?I did not know about FINDSTR.  But even with your code, I am uncertain how to use it to omit outputting to the text file?The idea is to pipe the output from the dir command to findstr. By piping I mean direct the output of a command into another command by using the | symbol. Findstr can be used in multiple ways; it can exclude a text pattern, or it can show text based on the pattern. What I did there was exclude any lines that end with those extensions by chaining multiple calls to findstr, with each one excluding another extension. In order to use it, replace the dir command in the for loops you have in the batch file with something similar to what I posted.

Hope this helps.Thanks so much for taking the time to help.

Here is what I have to start with:


(
    echo - -  LIST GENERATED: %DATE%  - -
    FOR /F "delims=" %%a in ('dir /A:D /OGN /B') DO (
      echo.
      echo - - - - - - - -  %%a  - - - - - - - -
      dir "%%a"/OGN /B
    )
)> MOVIE_LIST.TXT


I've tried multiple ways of replacing your code into mine, but can't get it to work.

Would you mind modifying what I have above with your example, since I can't seem to grasp it?Oh stupid me. I got it now and it works exactly as I wanted. THANKS!!!

Is there a way to edit and/or delete posts we make on here?

Now for part 2:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PART 2

I would also like to add another argument named   /noext   that would output everything the same, but strip off the file extension part of each movie.

EXAMPLE OUTPUT WITH THE  /noext  ARGUMENT SPECIFIED:


- - - - - - - -  - MUSIC RELATED  - - - - - - - -
VAN HALEN LIVE SHOWS
AC-DC - Let There Be Rock [1980]
Mayor Of The Sunset Strip [2003]
Searching For Sugar Man [2012]


I think I know how to do everything except how to strip off the file extensions for this part.

Attached is my newest updated version of the complete batchfile. Quote from: carlos1001 on August 06, 2021, 04:58:54 PM

Try using findstr; eg.

Code: [Select]dir "%%a"/OGN /B | findstr /v /i "\.srt$" | findstr /v /i "\.idx$" | findstr /v /i "\.sub$"

Edit: formatting; looks like markdown doesn't work on here?
This can be made more efficient by combining the three FINDSTR commands into one.

Code: [Select]dir "%%a"/OGN /B | findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" Quote from: Thaum2u on August 11, 2021, 02:42:47 AM

I would also like to add another argument named   /noext   that would output everything the same, but strip off the file extension part of each movie.


Code: [Select]FOR /F "delims=" %%G IN ('dir "%%a"/OGN /B ^| findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" /RIVC:"\.jpg$" /RIVC:"\.png$"') DO ECHO %%~nG Quote from: Squashman on August 27, 2021, 09:01:23 AM
This can be made more efficient by combining the three FINDSTR commands into one.

Code: [Select]dir "%%a"/OGN /B | findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$"

Thanks! Quote from: Squashman on August 27, 2021, 09:17:07 AM
Code: [Select]FOR /F "delims=" %%G IN ('dir "%%a"/OGN /B ^| findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" /RIVC:"\.jpg$" /RIVC:"\.png$"') DO ECHO %%~nG

Thanks Squashman!  I am not sure how to implement the code you suggested for me.  The way I did it RESULTS in a blank file.

Here is my default routine (now updated with your more efficient code suggestions):


:DEFAULT
(
    echo - -  LIST GENERATED: %DATE%  - -
    FOR /F "delims=" %%a in ('dir /A:D /OGN /B') DO (
      echo.
      echo - - - - - - - -  %%a  - - - - - - - -
      dir "%%a"/OGN /B | findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" /RIVC:"\.jpg$" /RIVC:"\.png$" /RIVC:"\.bat$"
    )
)> %NAME%.TXT
start notepad %NAME%.TXT


How would you modify that to omit file extensions in the resulting text file?My code:
Code: [Select]FOR /F "delims=" %%G IN ('dir "%%a"/OGN /B ^| findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" /RIVC:"\.jpg$" /RIVC:"\.png$"') DO ECHO %%~nG
replaces this code:
Code: [Select]dir "%%a"/OGN /B | findstr /RIVC:"\.srt$" /RIVC:"\.idx$" /RIVC:"\.sub$" /RIVC:"\.jpg$" /RIVC:"\.png$" /RIVC:"\.bat$"
Could you please learn how to use CODE tags.  It would be much appreciated.

Quote from: Squashman on September 01, 2021, 02:46:07 PM
Could you please learn how to use CODE tags.  It would be much appreciated.

You are awesome!  Thank you so much!  And now I know how to use the code tag as well.
1418.

Solve : missing .bat file?

Answer»

I am missing del_me.bat and cant print more than ONE webpage. RUNNING w98se, have BOOT disk &AMP; cdrom. Please how to re- install that file, preferably from boot diskIf that file REMAINS unchaged after install, you can copy it from a .cab to a floppy and copy it to the proper directory.

1419.

Solve : Deleting text from multiple files??

Answer»

Newcomer to DOS, I couldn't find any hints/tips online about deleting a 'specific' line of text from multiple files of same 'type'.
eg. 'This is my text' to be DELETED from *.HTM files.
Would APPRECIATE if anyone can ADVISE or DIRECT me to suitable solution.
Regards
Pete

1420.

Solve : Create folder from first 5 chars of filename (and move the file to it.)?

Answer»

Here's what I have.

Code: [Select]C:\test\12345-test1.txt
C:\test\23456-test2.txt
C:\test\44444-test3.docI would like to have the script read the first 5 digits from the file, create a folder with those digits, and include the letter T before it. (and then move the file into that folder)

So, the result after running:

Code: [Select]C:\test\T12345\12345-test1.txt
C:\test\T23456\23456-test2.txt
C:\test\T44444\44444-test3.docCurrently, I have this, which does the funciton, I just can't figure out where to put the SET command to extract the 5 characters.
Code: [Select]echo off
for %%a in (*.*) do (
md "T%%a" 2>nul
move "%%a" "T%%~a" 
)I think this needs to be added to choose only the first 5 chars...
Code: [Select]set first5=%%a:~5,1%Thoughts?
echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set FILENAME=%%A
set first5=!filename:~1,5!
md "T!first5!" 2>nul
move "%%a" "T!first5!"
)This WORKED,

echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set filename=%%a
set first5=!filename:~1,5!
md "T!first5!" 2>nul
move "%%a" "T!first5!"
)

EXCEPT the capital A in line 4 had to be lowercase. Quote from: billiehawkins on October 25, 2011, 01:09:33 PM

Except the capital A in line 4 had to be lowercase.

Yes, I made a typo. I am so used to using capital letters for the FOR variables. There is a reason - SEE if you can spot it in the FOR help. I looked hard but I couldn't see the word "thanks" anywhere in your post...

This has been tested and works with the corrected A to a case-change.

Thank you for the support on this, I'm learning so much about For loops from these tasks!
Brilliant stuff guys  Thanks a lot.

I adaped your script to pickout the date from the file name of a PDF report, then move that report to a folder with that date ( for archiving): Example file name:  R9621_XJDE001_D1111201_T161418976.pdf

ECHO OFF
setlocal enabledelayedexpansion

for /f %%a IN ('dir /b T:\B7333\PrintQueue\*.pdf') do (
set filename=%%a
set last21=!filename:~-21!
Set pdfdate=!last21:~0,6!
mv %%a pdfdate/

)

Quote from: billiehawkins on October 25, 2011, 01:09:33 PM
This worked,

echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set filename=%%a
set first5=!filename:~1,5!
md "T!first5!" 2>nul
move "%%a" "T!first5!"
)

Except the capital A in line 4 had to be lowercase.
Shouldn't that set statement be:
Code: [Select]set first5=!filename:~0,5!
1421.

Solve : Help me with a batch that goes recursevly through folder structure?

Answer»

Hello,

can anyone of you give me a hint on a bat file that would go through a folder structure and read data from a specific file ( .txt)

so the ideea is that this .txt file exists in all folders, I need a bat that would read step by step all txt file from al folders

00_Documentation
         test.txt
01_File
         test.txt
        01_subfolder
                     test.txtI don't mean to pry (actually I guess I kind of do), but what exactly are using the read text for? Why does it need to hit all folders and what exactly is it going to do?Good QUESTION...In each folder I have a file a Text file which contains all files name from the folder, I need to read all those files and take out the files names.
I hope I made my self understood:

e.g
00_Documentation
     file1.ppt
    file.2.doc
    file3.xls
    test.txt

in the test file is written that in in 00_Documentation I have the 3 files, I want an automatic way to tell me which files are in which foldersI know this may seem simple, but why wouldn't this work?

Code: [Select] dir c:\ /s /b
That will LIST your ENTIRE directory structure by file name.

Either that, or if you are needing from the test.txt file try this:

Code: [Select]for /f "delims=" %%A in ('dir /s /b *test.txt ') do (
  type %%A
  pause
)

That will go through and display the contents of all of the test.txt files that it can find, pausing for you after each one. If you are looking to output this to a file just use type %%A>c:\file.txt in place of the second line. If you are needing this to do more, like read into each file looking for something, an EMBEDDED for loop would probably be your better option. But again, it is a little difficult to know what it is you are looking to accomplish, especially when the first command should be enough to eliminate the need for your test.txt files.

1422.

Solve : Happy Birthday Sidewinder !?

Answer» HOPE you have a Great One ! !Have a Happy BIRTHDAY Happy Birthday Sidewinder!  Have a good one. THANK you all. It was one of those days when all was in BALANCE...11/11/11

 

1423.

Solve : I need some batch file help!?

Answer»

Friends, I need some help. I need a batch file that will read through a directory structure such as A-E which has folders inside with client name such Apple, Brass, Cotton. I need the batch file to search for a directory call 2012 in every folder if it's not there make it and make two more directories inside it called This Year and Last Year. If it does find a directory called 2012 it should continue to the next folder.

My batch skills are extremely, extremely rusty so the more precise you can be the less of a pain I will be. Let me say I truly appreciate anyone responding to this call for help. I thank you for your time and the next round is on me!

Regards,
Bigwil

PS: I hope I worded this right!Are all of these directories under the same folder? Ex. c:\Dir\A; c:\Dir\B; etc. This may work.

Code: [Select]echo off

REM Place in directory above
REM Creates 2012 folder This Year and Last Year folders within it
REM 10/28/2011

:: rev 5 (folders_subfolders.bat)

rem cls

::Find and enter subdirectories in the current directory
for /d %%a in (*) do (
dir /ad %%a
chdir %%a
::Search for and create 2012 if not exist in folders
FOR /D %%G in (2012)  DO Echo **Found Directory: %%G
IF NOT EXIST %%G mkdir 2012
chdir 2012
::Search for and create This Year and Last Year if not exist in folders
FOR /D %%t in ("This Year") DO Echo **Found Directory: %%t
IF NOT EXIST %%t mkdir "This Year"
FOR /D %%l in ("Last Year") DO Echo **Found Directory: %%l
IF NOT EXIST %%l mkdir "Last Year"
CD ..\..
) Quote from: pathe3 on October 30, 2011, 06:14:23 AM

This may work.

Did you try it? I suspect not, because you used the undocumented, unofficial, UNSUPPORTED (as in "wrong") double-colon comment starters instead of REMs. Double colons (which are in fact broken labels) break PARENTHETICAL structures.



Quote from: Bigwil on October 28, 2011, 12:51:06 PM
Friends, I need some help. I need a batch file that will read through a directory structure such as A-E which has folders inside with client name such Apple, Brass, Cotton. I need the batch file to search for a directory call 2012 in every folder if it's not there make it and make two more directories inside it called This Year and Last Year.
Why don't you post the file you have already.  Show us you've done at least a little work on it Yes, it was tested, not extensively - but it worked. The double colons are a minor issue, just replace them with REMs or eliminate them altogether. There appears to be no shortage of bad manners on this board. A response to a help request, even one containing errors, isn't justification for a smear attack by multiple board members. I'm sure that isn't anything you don't already know, and I'm just as sure that you really enjoy it. Quote from: pathe3 on October 30, 2011, 11:48:55 AM
smear attack

Smear attack? Where? Do you know what "smear attack" means?

Quote
by multiple board members

Multiple? Where?

Quote from: pathe3 on October 30, 2011, 11:48:55 AM
Yes, it was tested, not extensively - but it worked.

It can't have worked with those double colons. We want working code here.
Raven19528, your answer is yes. They are in Y:\Int.

Quantos, as I mentioned I have virtually no skills with batch programming. Besides countless internet searches on how to create batch files, I had no clue as to how to start this project hence the call for help. I had nothing to show you.

Pathe3, I will try your solution and report back.

Salmon Trout, lets keep things positive ok. I appreciate that someone even took the time to respond.

I'll keep you posted.

Thanks again my peers!

BigwilAlright, so try the following. Very similar to pathe3's solution, but a little simpler, which also helps to troubleshoot if needed.

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "delims=" %%A in ('dir Y:\Int /b') do (
  for /f "delims=" %%B in ('dir %%A /b') do (
    set path=%%dpB
    if not exist "!path!\2012" (
      md "!path!\2012"
      md "!path!\2012\This Year"
      md "!path!\2012\Last Year"
    )
  )
)Considering the solution had already been posted, I'm surprised this thread is still alive. Must be the spirits of Halloween.

The Pathe3 entry won't win any BLUE ribbons at the state fair, and probably wont get a medal from Microsoft Best Practices, but the fact is that it works as advertised and to the OP specs.

Quote from: Raven19528 on October 31, 2011, 11:06:34 AM
Alright, so try the following. Very similar to pathe3's solution, but a little simpler, which also helps to troubleshoot if needed.

Good thing. There is a typo which prevents it from working properly. The lesson here is to troubleshoot the snippet before posting.

Gotta go now and extort some candy from my neighbor! Happy Hunting sidewinder... Quote from: Sidewinder on October 31, 2011, 12:41:08 PM
Good thing. There is a typo which prevents it from working properly. The lesson here is to troubleshoot the snippet before posting.

*grumble, grumble* stupid ~ *grumble, grumble*

Edit:
Code: [Select]...
set path=%%~dpB
...
  Quote
I was working in the lab late one night
When my eyes beheld an eerie sight
For my monster from his slab began to rise
And suddenly to my surprise

He wrote a script!

This appears to have been created in a lab, but it goes along with my sense of proportion.

Code: [Select]echo off

for /f "delims=" %%A in ('dir Y:\Int /a:d /b') do (
  if not exist "%%~dpnA\2012" (
    md "%%~dpnA\2012\This Year"
    md "%%~dpnA\2012\Last Year"
  )
)

The MD command will create an entire tree structure if necessary.

Back to the dungeon 'till next year.

Hey Raven19528, thanks so much! We had to make some minor changes but your direction put me 95% on my way. Problem solved, mission accomplished. The solution ended up looking almost exactly like Sidewinder's submission.

Thanks again.
1424.

Solve : Spin?

Answer»

hello! I wonder if ANYONE can help me on this: I would like to use the xcopy command to copy a directory from ONE computer to another. I can do it, in the same computer, but with two diferent computers i can´t. Does anyone can tell me how to do it?
Have you tried making a directory first then copying the files and sub-directors to it?you MAY have to map your FOLDER on the other pc to a drive letter like D: thru Z:  then do an xcopy USING the drive letter.

1425.

Solve : Need help using the type command ouput as variable?

Answer»

I'm using a product called temperature alert.  It creates .log files with temperature dumps.  If I run a "TYPE" command on today's log, I receive several LINE entries.

Example of the last one, which is the one I want to capture:

11/7/2011 11:39:55 AM,68.34



I want to set a variable to 68.34

Please Help!
You can use the tokenising ability of the FOR command to capture a desired PART of a line.

Am I right that you want to:

1. Get the last line of a log file

 and

2. Isolate the final part after the (only) comma?

If so you could do it like this

Code: [Select]for /f "tokens=1-2 delims=," %%A in ( ' type "logfile.txt" ' ) do set variable=%%B
echo Final temperature in log is %variable%

explanation:

One-line FOR /F syntax:

for /f "token block" %%variable in (dataset) do action

Multiline FOR /F syntax:

for /f "token block" %%variable in (dataset) do (
        action1
        action2
        action3
        etc
        )


for /f ... the /f switch means "treat the dataset as a series of lines to be processed"

"token block" ... set various parameters governing splitting the line up into a series of one or more tokens, separated by stated delimiters

"tokens=1-2 delims=," ... split each line into 2 tokens, the first token being everything up to the first comma, the second token being from the first comma to the next comma or the end of the line, whichever comes first. Since there is
only one comma, this effectively isolates the temperature reading in the second comma.

%%variable ... Variable is a single letter a-z or A-Z. If the line is being split into tokens then the first token is assigned to the explicit (declared) variable (%%A in the example) and subsequent tokens are assigned to the implicit variables starting with the next letter of the alphabet (%%B in this case) So if you want 26 tokens (tha maximum for one FOR line) you'd better make the first one %%A or %%a (case matters, %%a is not equivalent to %%A)

dataset ... What we want FOR to process, since we used the /F switch this is the source of the lines to process, in this case the output of the type command. To use a command or program's CONSOLE output in this way we place a single quote before and after the command.  The spaces in the example above are for clarity and are not compulsory.

action ... what you want to do with the token or line (in this case assign it to a variable)

The FOR /F command loops through the output of the command line by line, performing the action on each in turn. When the loop ends, the variable will HOLD the last value assigned.

for full documentation of the FOR command type for /? at the prompt








Thanks!  That is exactly what i asked for. 

Anyway to avoid the overhead of processing the whole file and just get it to skip to the last line?  When I launch, it runs through setting the variable 400 times before getting the final result.  Thanks! Quote from: choward16980 on November 11, 2011, 11:05:11 PM

Thanks!  That is exactly what i asked for. 

Anyway to avoid the overhead of processing the whole file and just get it to skip to the last line?  When I launch, it runs through setting the variable 400 times before getting the final result.  Thanks!

Surely if you have echo turned off (e.g. if you have echo off at the start of the batch) then the time taken to do this will be very short indeed - much less than one seond on any kind of modern computer less than about 20 years old. Otherwise you could install a Windows port of the Unix TAIL utility, I guess.

1426.

Solve : batch file: net sending output??

Answer»

Hi.  I was wondering if you could make a batch file that would net send output of a certain COMMAND.  For EXAMPLE, The contents of C:\owner\documents and settings\desktop or WHATEVER to computer A4.  Well, you get the PICTURE.  I am somewhat NEW to batch files and dos since I have just gotten into them very recently.   Any help would be appreciatednot sure i understand your problem

try "set dircmd=0" that will turn off dir listings.

1427.

Solve : How to Insert a Header Row in a Text File using a Batch program.?

Answer»

New to using this FORUM and batch files, so please bear with me.
It doesn't seem like this would be hard, but I've search everywhere I can think of and can't FIND the answer.

Using Windows 7

Need to open text file, and add a static header. 

Original Text File Example:
XHD051500101103
XHE   PO#1005
XDT2496581 001
XDT2670961 001
XOE  27   33

Need it to be:
Header
XHD051500101103
XHE   PO#1005
XDT2496581 001
XDT2670961 001
XOE  27   33

Any help would be GREATLY APPRECIATED.   

With a little lateral thinking, try this

Code: [Select] >{dummy}.txt echo Header
>>{dummy}.txt type "Original Text File"
del "Original Text File"
ren {dummy}.txt "Original Text File"
SIMPLY put, create a new file with the header in
append the content of your main file
delete the main file
rename the temp file to the original main file name

1428.

Solve : Find Drive letter of CD Drive in Batch file?

Answer»

How do I DETERMINE the drive letter of the CD drive from within a batch FILE?Most PCs with Win9x mount the CDROM as the last drive. Put a readable CD in the drive. You can test for content until you get to an error:

set %d=d:
if not exist E:\nul goto finish
set %d=e:
if not exist f:\nul goto finish
set %d=f:
if not exist g:\nul goto finish
. (continues in similar fashion, however many you want to check)
:
:finish
echo CDROM is drive %d

1429.

Solve : Btach file help needed please?

Answer»

Hi there, I have a PROBABLY easy to make batch file but I dont know syntex of batch files.. and google has not really helped.

My situation is that I have a folder called "Tornado_Backup" and I want to create a batch file that removes all the directories and files inside this folder so that its empty. I tried ECHO Y | DEL *.* but this also DELETES the batch file, and doesnt remove any directories inside of this folder.

What is the best way to go about this? TRY using

Code: [Select]rd /s /q Tornado_Backup
md Tornado_Backup
Try having the batch file right NEXT to the directory, instead of in it.that works i GUESS. Thanks!

1430.

Solve : Run a command if string has a certain character?

Answer»

I have looked around for this, and could not find anything on it.

Anyways, is it possible to search a string/variable for defined characters, and RUNNING a command if that is true?

For example:

SET string=1234567

^ Nothing would happen



set string=1234A567

^ Program would inform you that the string has something other than a numberHere's a start, it won't identify any particular non-numeric character just that there is a non-numeric character in the string, maybe you could work on this.

Code: [Select]ECHO off
cls
setlocal

Echo %1|FindStr /R "[^0-9]" > nul

If %ERRORLEVEL% EQU 0 (echo result=non-numeric)

You can do it in one LINE

Code: [Select]Echo %1|FindStr /R "[^0-9]" > nul && echo String contained at least 1 non-numeric character Quote from: Salmon Trout on October 29, 2011, 01:29:09 AM

You can do it in one line


Sure, and still turn Echo off and Cls and SetLocal and....whatever else:
Code: [Select]echo off&cls&setlocal&Echo %1|FindStr /R "[^0-9]" > nul&&If %ERRORLEVEL% EQU 0 (echo result=non-numeric)
1431.

Solve : Trying to align output?

Answer»

I am working on a batch file where I want it to list stuff about the computer such as computer name, version of windows, disk drive size, etc.  I have the commands to gather the info, and its all going into a textfile that then gets mailed to me.  What I want is it to look neater.

Currently I get...

Computer Name: BERENERD
IP: 192.168.1.125
Version: Microsoft Windows [Version 6.0.6002]

What I want is....

Computer Name:    BERENERD
IP:                          192.168.1.125
Version:                  Microsoft Windows [Version 6.0.6002]

I have been searching for a way to do this and have failed miserably.  I found some posts in this forum from 2010 but it looked like the answer was never given that WOULD work for both XP and later versions of windows (vista, windows 7) any ideas?What you want is a way ton generate a report. Most , if not all, of the commands in DOS or Windows CMD are for working with files s and file names and the attributes of the files.

A delimiter is a symbol used to mark  fields in a record.

Report generation should be done by a suitable application. If the fields  have delimiters you can format a report. Ecell can help you generate a report if the fields, or cells, are in the CSV format. Each value must have a comma to 'delimit' it from another value.

Of course, if you can get it into CSV you can also format in in DOS using the FOR command, which can separate items having delimiters.
Can't be sure about Vista but this might test out okay on XP and Win 7

Code: [Select]echo off
cls
setlocal

for /f "tokens=1* delims=:" %%1 in (trial.txt) do (
    set first=%%1:               .
    echo !first:~0,17!%%2
    )
   
Quote from: Dusty on October 14, 2011, 01:26:06 AM

Code: [Select]echo off
cls
setlocal

for /f "tokens=1* delims=:" %%1 in (trial.txt) do (
    set first=%%1:               .
    echo !first:~0,17!%%2
    )
   

Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" VARIABLE to work.  Also, I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP?

From the FOR /? in cmd prompt:

FOR %variable IN (set) DO command [command-PARAMETERS]

  %variable  Specifies a single letter replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be used.
  command    Specifies the command to carry out for each file.
  command-parameters
             Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable.  Variable names are case sensitive, so %i is different
from %I.

Other than that, all in all, it looks like it would work in Vista and 7 just the same. Quote from: Raven19528 on October 14, 2011, 12:23:27 PM
I didn't think numbers worked for the FOR variable. I was pretty sure it was letters only, and case sensitivity allowed for a maximum of 52 variables to be set. Is that different in XP?

In Windows NT family (2000, XP, Vista, Windows 7, plus Server 2003 & 2008), you can use most of ASCII 33 (!) to 126 (~) the exceptions are, as far as I can see:

34 (") 37 (%) 38 (&) 44(,) 59( 60(<) 61(=) 62(>) 124 )

but the documentation only mentions A-Z and a-z, POSSIBLY to keep things simple for people learning batch scripting.

for example

Code: [Select]C:\>for %# in (a b c) do echo %#
a
b
c

C:\>for %$ in (a b c) do echo %$
a
b
c
Quote from: Raven19528 on October 14, 2011, 12:23:27 PM
Wasn't sure, but were you going for the setlocal enabledelayedexpansion on the third line? That's needed for your "!first:~0,17!" variable to work. 

Oops yes, thank you for the correction, I can only blame the Friday night rums and Cokes for the omission. 

Your other query has been ANSWERED by ST and I can only add that most printable ASCII characters are acceptable in a For loop, including a few of the exceptions noted by ST, altho' there are some which must be Escaped. 

Try this.  If it doesn't work I'll think up some excuse!!  (note the use of the Esc char ^ and other chars " and #):

Code: [Select]echo off
cls
setlocal enabledelayedexpansion

for /f "tokens=1* delims=:" %%^" in (trial.txt) do (
    set first=%%":               .
    echo !first:~0,17!%%#
    )
1432.

Solve : Command Questoin?

Answer»

I have my windows 98 boot disk in my pc and im in dos, what COMMAND to i type in to get teh cd to run in teh D DRIVE?D:At the prompt> a:\ cd windows
enter
c:\win98

or BIOS options boot from cdrom......hit the ctrl/del key on boot...and dont forget you will need you graphics DRIVERS etc...

1433.

Solve : Is it possible to compile Qbasic........?

Answer»

Is it POSSIBLE to compile a text file through Command Prompt if it is written in Qbasic?  ((on XP HOME EDITION))http://www.qbasic.com/

1434.

Solve : Ping and hostname?

Answer»

Hey all,

Im trying to use hostname of ping address' to manipulate my .txt output
--------------
echo off
set a=1

:start
ping -n 1 -r 4 -a 10.1.1.%a%
echo %errorlevel%
if %errorlevel% ==0 (ping -n 1 -r 4 -a 10.1.1.%a% >> a.txt) else (echo error 10.1.1.%a%)
echo ------------ >> a.txt
echo ------------ >> a.txt
echo ------------ >> a.txt
set /a a+=1
if %a% == 255 goto end
goto start
:end
pause
-----------


so far my output is LIKE the below


Pinging 10.1.1.7 with 32 bytes of DATA:
REPLY from 10.1.1.150: Destination host unreachable.

Ping statistics for 10.1.1.7:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
------------
------------
------------

if there is no IP address assigned it STILL goes into my .txt file because it PINGS myself (10.1.1.150) and gives an unreachable. im trying to get my .txt file to only contain ip address that are reachable and a way i can do it is something like,

if ip = 10.1.1.150 do nothing else >> a.txt

if possible i would prefer hostname as im not using a static IP.  im sorry if my question seems a bit confusing.

Thanks for looking,

Khasiar

1435.

Solve : How can a .BAT file distinguish a file from a folder??

Answer»

When an 'if exist' command tells me that ENTITY does exist, how do I TELL WHETHER ENTITY is a file or a folder?
This little snippet may HELP:

Code: [Select]echo off
set /p fname=Enter file name:
for %%v in ("%fname%") do (
  if exist %%~sv\nul (echo "%fname%" IS a directory) else (echo "%fname%" is NOT a directory)
)

The code will PROMPT for user INPUT. Feel free to tweak the code as you see fit.

Good luck. Code: [Select]for /f "delims=" %%A in ("%entity%") do set attribs=%%~aA
if "%attribs:~0,1%"=="d" echo %attribs% is a directory

1436.

Solve : PC DOS?

Answer»

I have an ancient computer that operates under PC DOS and was until RECENTLY connected to a file sharing programme Little Big Lan with two other computers. The main computer printed via another one on the network. As the other computers are no longer part of the network how do I get the main computer to print via its parallel printer port?

I have absolutely no expereince of PC DOS - Help!  a parallel lead and a printer that has a parallel socket, send any print to device LPT:I have a printer and it is connected to the parallel port, but the output is being DIRECTED to another printer on a non existent network.
How do I programe the computer to output to the parallel port?Your subject really is "Little Big LAN", since PC-DOS is only the operating system. This sounds like a commercial/business type of application. A lot of CNC stuff is still run on DOS of one flavour or another. That being said, surely the budget would stretch to an hour or so of an IT PROFESSIONAL's time? Especially since that ancient computer is bound to fail quite SOON? Little Big LAN was "the $75 network" back in the late 1980s/early 1990s. Almost certainly you will need to edit some kind of configuration file. Possibly this can be done via a setup routine or program. Of course you still have the documentation.

Are ye so canny wi' the bawbies ye're afeart tae telephone EQ Consultants in Creiff? (Who sell Little Big Lan)



Many thanks for the help. I couldn't remeber who produced Little big LAN.Essentially, what you need to do is, in each program that does any printing, find the printer configuration setup - it may be a menu item - and see what the printer option is set to. There should be an option you can change, which is at present set to the network printer, that you can alter to LPT1: and save. Unlike Windows, in DOS you have to do printer configuration in each application.
Many thanks for the help.

1437.

Solve : subdirectories?

Answer»

please explaing the significance of the "." and ".." that appear in all subdirectories on a disk
Why does it matter? 
The . directory means the current one, the .. refers to the parent directory
So CD .. will take you one level up (which is about the most useful use of .. I can think of)He is doing homework. The right answer is a little more OBSCURE . The dot and double dot are PLACE holders for the current directory and its parent.
So that "CD .." does not literally MEAN  "got up to to  parent", but it means go to the directory named ".."  instead.
Why does anyone want to know this esoteric stuff? Quote from: Geek-9pm on OCTOBER 12, 2010, 03:16:00 AM

Why does anyone want to know this esoteric stuff?

Not so esoteric actually. Many coders use relative paths in their batch files. Many installers also use relative paths based on what the user types in for the install directory.

Powershell also uses a relative paths owing to the FACT that the current directory is not searched by default. If the current directory contains your Powershell script, you must use .\ to force a search of the current directory or type out a fully qualified path name.

 

1438.

Solve : problem with vista?

Answer»

I am having problem atm so I am looking at going back to XP. But when I try to instal the new software the setup starts then a message comes up SAYING that setup has to be TERMINATED to prevent further damage. I basically says that i need to check for virus's then go again but I have done CHECKS for virus's,Adware,Malware EVERYTHING but nothing comes up and I have completed CHKDSK SEVERAL times. any help would be nice.

1439.

Solve : Saving a webpage to my hard drive through a batch file command?

Answer»

I have Windows XP and am using Notepad for a batch file:

I have a few webpages that I need to open and then save to my hard drive as an htm document.  How can I write a command to do this?  I am not a programmer; I'm just trying to automate a tedious process for my job.  I can open the web page with my batch file, but that's it.

Another question--Only on one of the web pages,  I have to right click on it and then export to excel.  Is there a  way to write a command to do this too?

Thanks for any suggestions...

TeresaYou should use a vbscript for that.

Have a look at the first code block on this site:
http://www.robvanderwoude.com/vbstech_internet_download.php

You just need to change the first line to the URL you want and then save as vbs.even better, use wget

http://users.ugent.be/~bpuype/wget/

Code: [SELECT]S:\Test>wget http://www.robgendlerastropics.com/index.htm
--2010-09-29 18:22:21--  http://www.robgendlerastropics.com/index.htm
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6883 (6.7K) [text/html]
Saving to: `index.htm'

100%[========================================================================================>] 6,883       40.3K/s   in 0.2s

2010-09-29 18:22:22 (40.3 KB/s) - `index.htm' saved [6883/6883]

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/primer.html
--2010-09-29 18:23:11--  http://www.robgendlerastropics.com/primer.html
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47805 (47K) [text/html]
Saving to: `primer.html'

100%[========================================================================================>] 47,805      44.8K/s   in 1.0s

2010-09-29 18:23:12 (44.8 KB/s) - `primer.html' saved [47805/47805]

Quote from: Linux711 on September 29, 2010, 11:05:53 AM

You should use a vbscript for that.

Have a look at the first code block on this site:
http://www.robvanderwoude.com/vbstech_internet_download.php

You just need to change the first line to the URL you want and then save as vbs.

I'm sorry, I've never used a vbscript before.  Can you be more specific as to what part of the code I need and where to put my url and path to save to?

Thanks for your help! Quote from: tmerryman on September 29, 2010, 11:28:36 AM
I'm sorry, I've never used a vbscript before.  Can you be more specific as to what part of the code I need and where to put my url and path to save to?

Thanks for your help!

I suggest wget. See above.
Quote from: Salmon Trout on September 29, 2010, 11:24:19 AM
even better, use wget

http://users.ugent.be/~bpuype/wget/

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/index.htm
--2010-09-29 18:22:21--  http://www.robgendlerastropics.com/index.htm
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6883 (6.7K) [text/html]
Saving to: `index.htm'

100%[========================================================================================>] 6,883       40.3K/s   in 0.2s

2010-09-29 18:22:22 (40.3 KB/s) - `index.htm' saved [6883/6883]

Code: [Select]S:\Test>wget http://www.robgendlerastropics.com/primer.html
--2010-09-29 18:23:11--  http://www.robgendlerastropics.com/primer.html
Resolving www.robgendlerastropics.com... 207.217.125.50
Connecting to www.robgendlerastropics.com|207.217.125.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47805 (47K) [text/html]
Saving to: `primer.html'

100%[========================================================================================>] 47,805      44.8K/s   in 1.0s

2010-09-29 18:23:12 (44.8 KB/s) - `primer.html' saved [47805/47805]

Thank you for the tip.  If this was my home computer, I would definitely try it.  My work, however, will not allow us to download programs.  I will keep WGet in mind for home use.I have modified the script to accept arguments from the command line. These are 2 in number and they are obligatory. 1. The url of the file you want to download 2. The folder you want to download it to.

To use the script from batch files do this

1. Save it SOMEWHERE on your hard drive. GIVE it a suitable name. I will use the name Downloader.vbs here.

2. run it with CSCRIPT if you want it to behave as a command line program, like this:

cscript //nologo c:\scripts\downloader.vbs "http://www.robgendlerastropics.com/primer.html" "C:\downloads"

I don't know about exporting to Excel, sorry

Code: [Select]
 myURL = wscript.arguments(0)
myPath = wscript.arguments(1)
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
If objFSO.FolderExists( myPath ) Then
    strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
    strFile = myPath
Else
    WScript.Echo "ERROR: Target folder not found."
    wscript.Quit
End If
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

'following line is optional
wscript.echo "Downloading " & myURL

objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )

'following line is optional
wscript.echo "Download complete"

Quote from: tmerryman on September 29, 2010, 11:34:12 AM
My work, however, will not allow us to download programs.

download wget at home and bring to work. If this is a legit task that your boss assigned you, there is no reason to restrict using appropriate tools for the job.  

Well, I just downloaded Wget at home.  It's awesome and so simple!  Thank you for CONVINCING me.  lol  I believe I'll sneak it to work. Quote from: Salmon Trout on September 29, 2010, 12:41:37 PM
Code: [Select]objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )


easier...
Code: [Select]objHTTP.Open "GET", myURL, False
objHTTP.Send
objFile.Write(objHTTP.ResponseText)
objFile.Close
1440.

Solve : Output File?

Answer»

Can you change the way the file is outputted.

I need the dos output to be comma seperated

dir *.pst  /s >pst.txtyou could write a batch script to parse the output of DIR
Quote from: electra109 on September 20, 2010, 03:20:29 PM

Can you change the way the file is outputted.

I need the dos output to be comma seperated

dir *.pst  /s >pst.txt

download sed for WINDOWS
Code: [SELECT]C:\TEST>dir *.pst /B /S |sed ":a N;s/\n/,/;ba"
1441.

Solve : Connecting to Unix?

Answer»

Hi,

I'm trying to CONNECT to unix machine and tranfer(FTP) some FILES from my local to somewhere in unix machine. Can you please advice..

Unix machine name : uwsst10
path : /usr/local/files/

I don't want to enter the path everytime after I connected to unix machine to FTP the files. I just wanted to encode the same path in my batch script so it will automatically change the path after we connected to unix machine.

I have code LIKE this.

e:
cd GPS_TEST\Tags\RPT1.txt
ftp uwsst10

After we enter the USERNAME and password it should automatically change the path to "/usr/local/files/" and then FTP the files for us..

1442.

Solve : Batch Network Chat?

Answer»

Hey all, ive recently coded a batch script to use on my school's network...just decided to share it lol
It works by editing/printing a chat log stored in a .dll file (sneaky haha)
It also checks a pre-defined list of users and if the user is not pre-listed then it send a message saying "This is a test message" This is incase a teacher remotely runs the chat
There are LOTS of other features i added like banning users, clearing the screen and many more...anyway, heres the script:
echo off
CLS
COLOR f2
SET scount=0
SET oldmessage=origin123
SET user=%username%
SET message=
SET pat=C:\"Program Files"\"Common Files"\"Microsoft Shared"\OFFICE12
IF /I %user%==Josh SET cuser=Miltzi & GOTO :admin
IF /I %user%==Jay SET cuser=PlayaJay & GOTO :admin
IF /I %user%==miltzj SET cuser=Miltzi & GOTO :admin
IF /I %user%==steinj SET cuser=Jarod & SET unum=11 & GOTO :first
IF /I %user%==steinda SET cuser=Daniel & SET unum=22 & GOTO :first
IF /I %user%==rubine SET cuser=Evan & SET unum=33 & GOTO :first
IF /I %user%==sklairn SET cuser=Nathan & SET unum=44 & GOTO :first
IF /I %user%==portnoyc SET cuser=Craig & SET unum=55 & GOTO :first
IF /I %user%==polakowa SET cuser=Polly & SET unum=66 & GOTO :first
IF /I %user%==selbya SET cuser=Alex & SET unum=77 & GOTO :first
IF /I %user%==vanderwesthuizenl SET cuser=Lance & SET unum=88 & GOTO :first
msg * This is a test message!
exit
REM echo HI >> C:\"Documents and Settings"\miltzj\desktop\1.dll
REM type C:\"Documents and Settings"\miltzj\desktop\1.dll
REM pause
REM C:\Program Files\Common Files\Microsoft Shared\OFFICE12

:CHAT
IF EXIST %pat%\%unum%.dll GOTO :BANNED
SET pat=C:\"Program Files"\"Common Files"\"Microsoft Shared"\OFFICE12
TITLE Grade 11 IT chat
IF EXIST %pat%\checkstats.dll GOTO :BUSY
IF NOT EXIST %pat%\1.dll echo Chat cleared by admin. >> %pat%\1.dll
CLS
type %pat%\1.dll

SET message=
SET /P message=Type message and PRESS enter (Type "help" to view options):
IF ERRORLEVEL 1 GOTO :BACKTOCHAT
IF /I "%message%"=="exit" GOTO :exit
IF /I "%message%"=="help" GOTO :help
IF /I "%message%"=="*censored*" SET message=f**k
IF /I "%message%"=="big *censored*" GOTO :BAN
IF /I "%message%"=="%oldmessage%" GOTO :SPAM
SET oldmessage=%message%
echo %user%: %message% >> %pat%\1.dll
GOTO :CHAT
:exit
CLS
echo %user% left the chat. >> %pat%\1.dll
exit
:help
CLS
echo Welcome to the help section
echo To exit the chat, PLEASE type exit as a message into the chat rather than closing the cmd box manually.
echo To refresh the chats messages, just press enter without writing any text.
echo **NB** If you use any inverted COMMAS (") in the chat, make sure u dont only use one as the chat will crash!
echo Please press enter to go back to the chat
pause
GOTO :CHAT
:ACHAT
SET pat=C:\"Program Files"\"Common Files"\"Microsoft Shared"\OFFICE12
TITLE Grade 11 IT chat
IF NOT EXIST %pat%\1.dll echo Chat cleared by admin. >> %pat%\1.dll
CLS
type %pat%\1.dll
SET message=
SET /P message=Type message and press enter (Type "help" to view options):
IF ERRORLEVEL 1 GOTO :BACKTOACHAT
IF /I "%message%"=="exit" GOTO :exit
IF /I "%message%"=="help" GOTO :help
IF /I "%message%"=="cls" GOTO :CLS
IF /I "%message%"=="amsg" GOTO :AMSG
IF /I "%message%"=="disable chat" GOTO :disable
IF /I "%message%"=="enable chat" GOTO :enable
IF /I "%message%"=="ban user" GOTO :ABAN
IF /I "%message%"=="unban user" GOTO :UNBAN
echo %user%: %message% >> %pat%\1.dll
GOTO :ACHAT
:exit
CLS
echo %user% left the chat. >> %pat%\1.dll
exit
:help
CLS
echo Welcome to the admin help section
echo -
echo To exit the chat, please type exit as a message into the chat rather than closing the cmd box manually.
echo -
echo To refresh the chats messages, just press enter without writing any text.
echo -
echo To clear the screen, type "cls"
echo -
echo To send an admin message, type "amsg"
echo -
echo To disable the chat, type "disable chat"
echo -
echo To enable the chat, type "enable chat"
echo -
echo To ban a user, type "ban user"
echo -
echo To unban a user, type "unban user"
echo -
echo **NB** If you use any inverted commas (") in the chat, make sure u dont only use one as the chat will crash!
echo -
echo Please press enter to go back to the chat
pause
GOTO :ACHAT
:CLS
del %pat%\1.dll
GOTO :ACHAT
:admin
echo %user% joined the chat. >> %pat%\1.dll
GOTO :ACHAT
:first
echo %user% joined the chat. >> %pat%\1.dll
GOTO :CHAT
exit
:BAN
echo Auto-generated stub code >> %pat%\%unum%.dll
exit
:BACKTOCHAT
GOTO :CHAT
exit
:BACKTOACHAT
GOTO :ACHAT
exit
:AMSG
CLS
SET /P adminmessage=Please type your admin message and press enter:
echo ** Message from admin: %adminmessage% ** >> %pat%\1.dll
CLS
GOTO :ACHAT
exit
:SPAM
msg * Please dont spam!
GOTO :CHAT
exit
:exit
exit
:BUSY
msg * Chat temporarily disabled by admin!
exit
:disable
echo This is a statistical reviewer created by Office >> %pat%\checkstats.dll
msg * Chat disabled!
GOTO :ACHAT
:enable
del %pat%\checkstats.dll /Q
msg * Chat enabled!
GOTO :ACHAT
exit
:ABAN
CLS
SET /P bname=Please type the exact username of the user you wish to ban:
IF /I %bname%==steinj echo Auto-generated stub code >> %pat%\11.dll
IF /I %bname%==steinda echo Auto-generated stub code >> %pat%\22.dll
IF /I %bname%==rubine echo Auto-generated stub code >> %pat%\33.dll
IF /I %bname%==sklairn echo Auto-generated stub code >> %pat%\44.dll
IF /I %bname%==portnoyc echo Auto-generated stub code >> %pat%\55.dll
IF /I %bname%==polakowa echo Auto-generated stub code >> %pat%\66.dll
IF /I %bname%==selbya echo Auto-generated stub code >> %pat%\77.dll
IF /I %bname%==vanderwesthuizenl echo Auto-generated stub code >> %pat%\88.dll
CLS
GOTO :ACHAT
exit
:UNBAN
CLS
SET /P uban=Please type the exact username of the user you wish to unban:
IF /I %uban%==steinj del %pat%\11.dll /Q
IF /I %uban%==steinda del %pat%\22.dll /Q
IF /I %uban%==rubine del %pat%\33.dll /Q
IF /I %uban%==sklairn del %pat%\44.dll /Q
IF /I %uban%==portnoyc del %pat%\55.dll /Q
IF /I %uban%==polakowa del %pat%\66.dll /Q
IF /I %uban%==selbya del %pat%\77.dll /Q
IF /I %uban%==vanderwesthuizenl del %pat%\88.dll /Q
IF /I %uban%==all del %pat%\11.dll /Q
IF /I %uban%==all del %pat%\22.dll /Q
IF /I %uban%==all del %pat%\33.dll /Q
IF /I %uban%==all del %pat%\44.dll /Q
IF /I %uban%==all del %pat%\55.dll /Q
IF /I %uban%==all del %pat%\66.dll /Q
IF /I %uban%==all del %pat%\77.dll /Q
IF /I %uban%==all del %pat%\88.dll /Q
CLS
GOTO :ACHAT
:BANNED
msg * You have been banned!
exit

1443.

Solve : Namespace - System Folder - refresh?

Answer»

I have an application that adds an annoying System Folder to the desktop, I can easily script removing this by deleting the registry key but the TRICK I'm running into is being able to refresh the desktop so the icon disappears. If I press F5 on the keyboard the icon is gone, but I RUN this bit of VBS it doesn't WORK. So I'm wondering if anyone has a different workaround? I'd prefer not to kill EXPLORER as in many cases the systray icons don't refresh come BACK correctly. Thanks for the help.

Code: [Select]  'Option Explicit
 Dim WSHShell, strDesktop
 Set WSHShell = WScript.CreateObject("WScript.Shell")
 strDesktop = WSHShell.SpecialFolders("Desktop")
 WSHShell.AppActivate strDesktop
 WSHShell.SendKeys "{F5}"
 'WScript.Quit

 Dim Act : Set Act = CreateObject("Wscript.Shell")
  Act.SendKeys "{f5}"Have you tried this code:

Code: [Select]set oShell= createobject("shell.application")
set oDesktop = oShell.Namespace(0)
oDesktop.self.invokeVerb "R&efresh"

Or this:

Code: [Select]Set WSHShell = CreateObject("WScript.Shell")
WshShell.AppActivate "Program Manager"
WshShell.SendKeys "{F5}"
Looks like this one is the magic I needed...

Thanks.

Code: [Select]set oShell= createobject("shell.application")
set oDesktop = oShell.Namespace(0)
oDesktop.self.invokeVerb "R&efresh"

1444.

Solve : delay in batch script?

Answer»

Hi,

How to SET delay in batch script. I would like my batch script to wait for 15 seconds. Please advice.

Thanks.!!Method (1) USES vbscript sleep method

Code: [Select]REM Delay in seconds
set delay=15
set /a ds=%delay%*1000
ECHO wscript.sleep(%ds%)>wait.vbs
echo %time%
cscript //nologo wait.vbs
echo %time%
del wait.vbs

Method (2) a fixed delay can also be produced by the PING command with a loopback address:

Code: [Select]REM Delay in seconds
set delay=15
set /a pd=%delay%+1
PING -n %pd% 127.0.0.1>nul Shouldn't this line

Code: [Select]cscript //nologo wait.vbs
be like this

Code: [Select]start /wait cscript //nologo wait.vbsThank you for your reply.  Have a good one..!! Quote from: Linux711 on September 15, 2010, 07:33:21 AM

Shouldn't this line

Code: [Select]cscript //nologo wait.vbs
be like this

Code: [Select]start /wait cscript //nologo wait.vbs

No. (Have you tried it?) If start /wait was required I would have included it. 

Used as I showed, cscript returns control (either to a calling script or the command PROMPT) when the vbscript exits, not before.





WRONG thread, wrong reply, sorry
1445.

Solve : IF EXIST for multiple filenames?

Answer»

Hi,

I need to chk if file exists fr multiple file names with OR condition:
Is something like this is pocible, coz i m getting error for this below code,

IF EXIST (D:\Test\Test1.log | D:\Test\Test2.log )


can someone help me? Code: [Select]set bool=0
if exist "D:\Test\Test1.log" set /a bool+=1
if exist "D:\Test\Test2.log" set /a bool+=1
if bool GTR 0 (
    echo at least one of test1.log and test2.log exists
    )Would this not work?

Code: [Select]IF EXIST "File1.txt" (
IF EXIST "File2.txt" (
REM COMMANDS for both files GO here
)
)
I'm on my phone so I can't indent, but I don't think I've MADE any ERRORS... I'll check back tomorrow.that's an AND, not OR.

1446.

Solve : input for batch file?

Answer»

Hello ,

Im trying to make an batch file for net user ""/domain command. If it is possible,i would LIKE if the batch file would ask for my INPUT of reuqested username  . Example " net user %myinput% /domain ".

thanksyou can USE the set /p command (example follows)

Code: [Select]set /p myinput="User name? "
ECHO You typed %myinput%Thank you,

that is exactly what I was looking for.

1447.

Solve : Batch File - Move files from one drive to the other?

Answer»

I have 2 drives that have the same folder HIERARCHY in each.
I NEED a batch file that will look at Drive A, Folder 1 and MOVE all the FILES from there to Drive B, Folder 1 - all the way through the hierarchy.
I am rusty at writing batch files and could really use the help
Thanks in advance!
Heather Quote from: heatherlou on August 31, 2010, 07:12:41 AM

I have 2 drives that have the same folder hierarchy in each.
I need a batch file that will look at Drive A, Folder 1 and move all the files from there to Drive B, Folder 1 - all the way through the hierarchy.

C:test>xcopy /?
Copies files

XCOPY source [destination]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
 
C:test>
1448.

Solve : MS-DOS any vesion needed.?

Answer»
   
     Hello folks,
           I already have Upgrade Install of MS-DOS 6.22 : total of 3 imz files. But in order to install this i need to have a base MS-DOS 6 and below of any version. Could someone help me retain a free imz files of MS-DOS 6 and below so that i can install Dos6.22.
   Microsoft already has an upgrade install of V6.0 READY for download. But i can't use that.
   
      Its easy to get an illegal copy of MS-DOS , you know from where.  I am going all ethical: If someone could help me here i would be utterly greatful.

I plan to install it in MS-Virtual PC 2007: or is it remotely possible to make an IMZ/IMG/IMA out of these MS-DOS 6.0 setup file.

 

Any suggestion is welcomed.Have you CHECKED into FreeDOS http://www.freedos.org/
Its very much like 6.22

Also if you want to play dos games, DOSbox works better than virtual dos environment. VPC2007 doesnt render GRAPHICS well for games etcSince MS-DOS is a copyrighted Microsoft product, there is no "ethical" way of getting it free, except, I suppose, if the legal owner of a genuine floppy install set gives you the set as a gift having first uninstalled it.
Anything here? :

http://computers.shop.ebay.com/DOS-/11685/i.html?_catref=1&_fln=1&_trksid=p3286.c0.m282

Thank you all for your advice,,,its sad to know that no full version of MS-DOS is available for download.
     I already have FreeDOS full version, just simply can't get to install it on Virtual PC.  Since it requires an Active OS partition,,,,,
 E-bay is something i dont want. I was looking for a free download. Its OK if their ain't one, life will still go on,,,,,,,,,

Thank you for giving your take.................. Quote
I was looking for a free download. Its OK if their ain't one, life will still go on

There are plenty of places on the WEB to get various versions of MS-DOS. You just won't read about them on here, because we don't do PIRACY help.
yeah i can get any version of Dos from WWW its a little bit of fishing,,,but then again i dont want any pirated stuffs.
    Ethics and hard work of the developers haunt back which seems to manifest in certain bad ways: in my experience.

i use DOSOX primarily for games. Which i play rarely.

1449.

Solve : Batch file to find newly updated file in FTP Server?

Answer»

HI,

Everyday we need to download newly added files are folder from FTP server to our local machine. I have already downloaded the folder from FTP server. But i need the following in batch script

1. Daily it need to search for any new files are folder added, If so it has to be downloaded to my local machine.

2. It should search all the subfolder too, for example i have folder called A and it may contain subfolders like xyz and even in that we may have some updated files.

3. Is there any possible to use GMail SMTP settings and SEND a mail using batch script. If we find any new files that details has to be mailed to the PARTICULAR users to download.


Please help me on this issue! I used GOOGLE and found nothing...

Thanks
PaulwintechMore questions than answers I'm afraid.

Quote

1. Daily it need to search for any new files are folder added, If so it has to be downloaded to my local machine.

How do you recognize a new file or folder? Date? Time?

What happens to files or folder that are downloaded? Do they get deleted from the server, moved elsewhere on the server?

Quote
3. Is there any possible to use GMail SMTP settings and send a mail using batch script. If we find any new files that details has to be mailed to the particular users to download.

If you have a GMAIL account you can use the Google SMTP server. Click here. You will probably need to write a Windows script using the CDO.Message object.

For batch scripts, you can use Blat which requires a download.

You can also use your own mail server if you have one or your ISP server.

How is all this being done now? Once you can do a walk through of the procedure you're currently using, automating it should be relatively easy.

Let us know.  Hi,

  I need to find new files using date/time

Regards
PaulwintechThis little piece of code will filter the current files (including files in subfolders). It uses the current date for comparison:

Code: [Select]echo off
setlocal enabledelayedexpansion

set dt=%date:~4,10%
for /f "tokens=* delims=" %%i in ('dir c:\folder /a-d /s /b') do (
  set fdt=%%~ti
  set fdt=!fdt:~0,10!
  if !fdt! EQU %dt% echo !fdt! %%i


Now that you can isolate them, what happens next? Stage them in a transmission folder? Transmit each file separately?

Note: My system date is in the FORMAT of dow mm/dd/yyyy. The set dt= statement in the file isolates the mm/dd/yyyy portion. You may have to tweak it for your local date format.

Let us know.  sidewinder, That will only work on his local machine. He needs a way to find the latest files at REMOTE.

OP, This is a job for a programming language with the necessary ftp , smtp libraries, not batch. ( not saying it can't be done, but its tedious ). I recommend Python (or Perl).Hi,

  Is there any possible to take the updated files from share and save it in backup server, For example in Machine A and Machine B have share called mybackup. Everyday they put some of their required backup in that folder.  Backup server should take or compare for any new files present in the share of A/B, and copy the same into backup server.

   Please let me know is there any possibility to do so.

Thanks
Paulwintech
1450.

Solve : Batch file for moving files?

Answer»

Hello all,

I am trying to set up a batch file that will move all files from a directory and it's sub-directories from one pc to a shared server drive (I:\). I was thinking a simple move command would be easy enough but the problem is that there are instances where a file being moved may already exist. If the source file and DESTINATION file have the same file name I want the batch program to skip it and move on the next one. I'm not familiar with the way to code this. Any help would be GREATLY appreciated.

To be more specific I have files on the user's desktop: C:\user\desktop\temp. The temp folder will have sub-directories with IMAGE files. I want all files moved regardless of extension but need to have the directory structure preserved at the destination I:\.

There is a program already in place that will sweep files out of the I:\ drive and archive them but the files being moved from the temp folder may have the same file name. I will have the batch file set up to run at log off so the user will have the images automatically sent for archiving but want to make sure that duplicates are left in the temp folder and can just be swept the next day when the file with the same name has been DELETED and the batch runs again.

I know this is fairly simple but I'm stumped as to make it ignore the file completely. Since I'm having it run at log off I can't have the batch file prompt the user if it's ok to overwrite and having to keep inputting no.

Again any insight would be very helpful.Curious as to why you are using MOVE command and not just an XCOPY /s/d/y instruction?I originally thought XCOPY would do the trick but I want the files moved instead of copied. XCOPY will leave the originals and I'd end up with too many files and would have to figure out a way to get rid of all the files that XCOPY successfully copied and leaving the ones that didn't. Unfortunately MOVE doesn't have a way to leave the original file alone if the file exists in the destination folder. I can have it overwrite automatically but I can't just have it say no without user input. Maybe I just don't know how XCOPY and MOVE work exactly and since I don't have alot of batch file experience I figured I'd look around for pointers.Ok I think I have half a solution so far. I did a lot of looking around and found that you could actually pipe the "n" to the move command so that it will not overwrite files in the destination folder if they already exist.

Kinda looks like this:

echo n|move /-y "D:\TEMP\SOURCE\*.*" "D:\TEMP\DESTINATION"

I knew it was something easy I was just overlooking but I didn't expect it to be that simple.

My problem now is that Move only works on files and not folders so my sub-directories aren't being touched.

If anyone knows a way of making that work I'd be grateful.
If not I'll just have to spend some extra time adding move commands for each and every sub-directory (and there's quite a few). This should work, haven't tested it though.

Code: [Select]ECHO OFF

FOR /f "tokens=* delims=" %%a IN ('DIR /b') DO (
COPY \-y %%a "P:\a\t\h" >
DEL /q %%a
)
Let me know!