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.

7901.

Solve : find replace help needed?

Answer»

I want to replace

    in an text file


    with



    • tttt-3.0.36
      <
      P>tttt-3.0.36[/url]



    • Here is what i tried
      for /f "tokens=* delims= " %%a in (%scriptsdir%/Mobilebranchota.html) do (
      set str=%%a
      IF !str!==^
        @echo off>> %scriptsdir%/branchota1.html
        set str=!str:^
          =^
            ^^^^%BUILD_NUMBER%^^

            %BUILD_NUMBER%^^^

            !
            echo !str! >> %scriptsdir%/branchota1.html

            "listview" data-divider-theme="d" data-inset="false">=
            • https://aa.com/mobiledist/test/images/orange.png" class="ui-li-thumb" />

              [/url]
            • ="listview" data-divider-theme="d" data-inset="false">

              Can some one help meNo need for the multiple posts...
              It's also not a good idea to use an e-mail ADDY for a User name...
              Unless you want your Inbox barraged with SPAM...Try something like this (UNTESTED):

              Code: [Select]@echo off
              setlocal enabledelayedexpansion
              for /f "delims=" %%a in (' TYPE "%scriptsdir%/Mobilebranchota.html" ') do (
              set str=%%a
              IF "!str:~0,14!"=="<ul data-role=" (
              >>"%scriptsdir%/branchota1.html" echo ^<ul data-role="listview" data-divider-theme="d" data-inset="false"^>
              >>"%scriptsdir%/branchota1.html" echo ^<li^>^<a href="https:google.html" data-transition="slide"^>
              >>"%scriptsdir%/branchota1.html" echo ^<img src="%imgpath%orange.png" class="ui-li-thumb" /^>
              >>"%scriptsdir%/branchota1.html" echo ^<h3 class="ui-li-heading"^>%BUILD_NUMBER%^</h3^>
              >>"%scriptsdir%/branchota1.html" echo ^<p class="ui-li-desc"^>%BUILD_NUMBER%^</p^>^</a^>^</li^>
              ) else (
              >>"%scriptsdir%/branchota1.html" echo(%%a
              )
              )If you continue to re-post the same request over and over they will be removed.
              Last warning.
              This is not live chat.

              patio.
7902.

Solve : i need a basic bat file...?

Answer»

ok i need a basic bat file i need it to be able to send an emulated press of a key (up arrow) to the active window every 10-20 secs (random)
if u make one email it to me at [emailprotected]

-generikk

email ADDY removed to prevent SPAM.A batch file (basic or otherwise) does not have the built-in functionality to send key strokes.

Your Win7 machine has tools to do this HOWEVER. Alternatives would be a VBScript using the sendkeys method of the SHELL object. Powershell would be overkill, but you can send key strokes with the Windows.Forms class. A third party alternative would be to download and INSTALL AutoIt.

Just curious as to application of this?

Most automation has specific timing INVOLVED where you dont want random between 10 and 20 sec intervals.

7903.

Solve : find and replace?

Answer»

I WANT to REPLACE <--test--> in hml to and add two more lines below using batch file.You didn't REPLY in your other THREAD - either here or another site I saw it on.sorry if i missed it,
Can i have a solution here please.

i am not able to get the syntax righ to place <!-- in html while i am trying to replace@foxidrive <cough> May I?

Greetings [emailprotected],
Quote

sorry if i missed it, Can i have a solution here please.

You are one lazy son of a batcher. Return to the other forum where you asked the same question and pick up your reply. In addition, you may want to CONSIDER changing your log in name.

Later.


7904.

Solve : "Start" command?

Answer»

Hello everyone!

I'm a begginner at programming and I've recently started learning the MS-DOS and I've been really eager to learn as much as I can since . While trying out different commands found in help section I've found the "Start" command and I've been trying to get the hang of it but I've encountered a few questions that I haven't been able to find an anwser to neither in the internet nor the help section and I was hoping if you guys could help me solve them...
So here it goes :

~How do I start a whole folder worth of a specific files(in my case, music )?
for example : My music catalog is LOCATED at "C:\Users\G-Man\Desktop\Music"
I've learned how to start a single music file as well as starting selected music file with a selected program but couldn't make my WMP start the whole folder as a playlist .

~Is it possible to make the program select and play 1 random music (out of all music files in the active folder)?

~Is it possible to make the program locate and play music from all the folders that are WITHIN the active folder?
for example : My folder "C:\Users\G-Man\Desktop\Sounds\" contains lots of other folders( like : Ambient/Chillstep/Altrock/90s etc.) and within each one of them are music files that I'd like to learn to play together in a big playlist .

I'm really sorry if someone actually made a topic covering this, if so I'll delete this emidiately .
I'm really new to this so any help you could provide would be really helpfull and appreciated
And english isn't my tongue language so please disregard the gramatical errors .Look into the for command.

~ for /f "delims=" %%A in ('dir /b /a:-d') do start %%A

~ set num=%random% blah blah blah
for /f "skip=%num% delims=" %%A in ('dir /b /a:-d') do start %%A

~ for /r (I don't USE this much, so someone else will have to explain it.)

This stuff might not work, but should put you on the RIGHT path.Quote from: Snr1 on October 11, 2013, 01:59:37 PM

~How do I start a whole folder worth of a specific files(in my case, music )?
for example : My music catalog is located at "C:\Users\G-Man\Desktop\Music"
I've learned how to start a single music file as well as starting selected music file with a selected program but couldn't make my WMP start the whole folder as a playlist .

Create a playlist with a DIR /B command

Quote from:
~Is it possible to make the program select and play 1 random music (out of all music files in the active folder)?

It's possible to select a random file from a folder.

Quote from:
~Is it possible to make the program locate and play music from all the folders that are within the active folder?
for example : My folder "C:\Users\G-Man\Desktop\Sounds\" contains lots of other folders( like : Ambient/Chillstep/Altrock/90s etc.) and within each one of them are music files that I'd like to learn to play together in a big playlist .

This is a GOOD program for that:

http://www.freewarefiles.com/A-Random-Music-Player_program_56805.html
7905.

Solve : Find & Replace "

Answer»

Hi can some one HELP me find & Replace say example "<--test-->" with " " in large text file using batch file in a sample.html

the batch file should read and replace <-- with <!-- in a html file.Greetings <a href="/cdn-cgi/l/email-protection" CLASS="__cf_email__" data-cfemail="d9b2afafb0b7b8a0b2acb4b8ab99a0b8b1b6b6f7bab6b4">[emailprotected],
Have you TRIED the SOLUTION you received on another forum?

later.

7906.

Solve : batch predict next word?

Answer»

hi...

how to make batch script to predict next word???

for example i enter a word "wash"...and batch show next word "the" and "car" and so much more

exp-

set /p input=Enter the word :
type %input%

>wash

1. the ( 60% )
2. my ( 25% )
3. yours ( 15 %)

and enter number to choose option
if i choose no.1

echo wash the

and predict next word after "the"

>the

1. car ( 55% )
2. bus (35% )
3. feet (10% )

and more...

i already create combination word
"wash the" pwashthe=5
"wash my" pwashmy=3
"wash your" pwashyour=1
"the car" pthecar=4
"the bus" pthebus=3
"the feet" pthefeet=1

set wash as oldword

and i try to make batch show %nextword%

i dont know some one can understand my poor explaination or not...
i hope somebody COULD...

i need suggestion that could help...ty

This does sound like too much for Batch - Batch is designed for small SCRIPTS to automate COMMON tasks, this is a much more complex project that will really need a full programming language.

That said what you would likely need to do (For the simplest version of this) would be to have a large library of text e.g. the contents of a book stored somewhere, you would then need to scan this for all the words that follow the word you are looking for, Order these words by the number of times they appear and then return the top 3.

I'm really not sure if something like this is even possible in batch, it certainly won't be pretty or fast. You'd really be best to consider using a full programming language like Java/C/Python/Perl.etc - You may be able to get more help with this in our programming section.It is "possible" but I would use a different language for this. Using the same process here is how you would return the top three (with the library setup "word" > word1 > word list (.txt) [all containing their likelihood to follow word1)
Code: [SELECT]setlocal EnableDelayedExpansion
for /f "delims=" %%A in ('dir /b /a:d "%~pd0\word"') do (
for /f "delims=" %%B in ('dir /b /a:-d "%~pd0\word\%%A"') do (
set /p working=<%~pd0\word\%%A\%%B.txt
if not exist tmp md tmp
echo %%B >>"%~pd0\tmp\!working!.txt"
)
)

:: Then all the words with the highest chance at comming next will be on the top in %~pd0\tmp inside the organized text file
:: To read them, you do

set READTO=3
for /f "delims=" %%A in ('dir /b "%~pd0\tmp') do (
if not !toread! LSS 0 (
set /p working=<%~pd0\tmp\%%A
echo !working! >>top3.txt
set /a toread-=1
if !toread! LSS 0
)
)


Keep in mind that none of this code is tested, and is not guaranteed to work.

7907.

Solve : Need help modifying DOS script for continuous ping?

Answer»

Hello,

I have the following script that almost works exactly the way I need it to. Basically I want to continuously ping an IP address and timestamp it to the screen. The problem with the script below is that is only pings 1 time. I want a continously ping say every 30 seconds or so.

Any help would be greatly appreciated.

Thx!

@ECHO off
setlocal

set IP=192.168.1.1

echo Pinging %IP%...

for /l %%a in (1,1,4) do call :pingIt %IP%

endlocal
echo [Done]

:pingIt
for /f "tokens=*" %%a in ('ping -n 1 %1') do @echo %time% %%a |find "Reply from "
goto :eofYour code could be SIMPLIFIED but this should work for you:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set IP=192.168.1.1
:loop
echo Pinging %IP%...
for /l %%a in (1,1,4) do call :pingIt %IP%
echo [Done]
timeout 30 >nul
goto :loop

:pingIt
for /f "delims=" %%a in ('ping -n 1 %1') do @echo !date! @ !time! - %%a |find "Reply from "
goto :eof
Foxidrive, awesome!!! Thanks so much, this works perfectly! I spent hours Google searching yesterday and couldn't find what I needed.

Thanks againI had a follow up to this question..... SINCE DOS does not support logging the output to a file, is there anyway to log this output and save to a file?

ThanksMy two cents.
Constant pinging is not a good practice. If you need to analyze a network connection, there are others software and HARDWARE tools.
Just saving.
Agreed 100%, however I am trying to test battery CAPACITY, i.e. send a constant ping to a device that is running on batteries to determine how many hours it will last.

ThxQuote from: gil_happy on October 07, 2013, 05:26:57 PM

I had a follow up to this question..... Since DOS does not support logging the output to a file,

You are mistaken.

Quote from:
is there anyway to log this output and save to a file?

Code: [Select]"batchfile.bat" >file.log
and

Code: [Select]>>file.log ping localhost Foxidrive, once again, awesome!

ThxJust building off what Foxidrive said,
">" Overrides the file
">>" edits the file (adding output to the end)
7908.

Solve : Batch to remove blank lines from a TXT file.?

Answer»

It would take me the rest of the night. I need to be awake in the morning. I get report files that have too many blank lines (white space). The lines are not always NULL length, that might have tabs or spaces, but no visible chars.
No need to preserve then original file.

So, can you help me please? I need to get to bed.

CODE: [Select]TYPE "file.txt" |findrepl "^\s*$" /V >"newfile.txt"
This uses a helper BATCH file called findrepl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

7909.

Solve : Total beginner question! How do you create a batch file to count to 100??

Answer»
When I say total beginner.. i really mean it!
Have been GIVEN a task to learn dos in half a day! Struggling big time!
One of the missions is to create a batch file that counts to 100.
I'm failing miserably at this!!

HELP Type in FOR /?
that will get you startedermm.. not really.
much more of a totally beginner than I imagined.. Although I have only been doing this since 9 today!
You can put this in a .bat file. It pauses at the end for the sake of being able to see it has done what you want... It's really fast though so im not sure if this helps you 'complete the mission'?

@ECHO OFF
FOR /L %%i IN (1,1,100) DO (
ECHO %%i
)
PAUSE
set count=0
:loop
set /a count=%count%+1
if not #%count%#==#100# goto loop
goto endQuote from: sfin on September 27, 2013, 03:32:01 AM
learn dos in half a day!

This is not possible. Who gave you this "task"?
Quote from: SALMON Trout on September 27, 2013, 10:27:50 AM
This is not possible. Who gave you this "task"?

Quote from: patio on September 27, 2013, 10:29:28 AM


Ahh, it's *your* fault! So in detail, there are three ways to do what you want to do.

The first is the most useful in scripts, which is a GOTO based loop, which would go something like this:

Code: [Select]set counter=0
:loop
set /a counter=counter+1
echo %counter%
if not %counter% == 100 goto :loop
The first line, gives us a base value to work with, and also truncates (empties) any previous value the variable may have had.

The second line, :loop, is a marker, (A batch label) to return to later
The third line is the key line of the program, it increases the variable 'counter' by one, it works using the arithmetic argument '/a', which tells set to deal with the phrase after the equals like a calculator would.
The fourth is what proves that the script is counting, it prints the current number to the screen, no fuss about it.
The fifth is what makes the program stop when we want it to, as well as making it continue until we want it to, it literally translates to "start again from the line with 'loop' written on it, unless you are already up to 100"

The second way of doing a recursive loop like this, is the SIMPLEST way of achieving what you want, and will do it all in one line.
for /L %%n in (1,1,100) do (echo %%n)
This uses a for loop, which is broken up into three parts, FOR, IN, and DO
FOR
tells us what argument (letter variable) to deal with, in this case 'n', prefixed with a double %
IN
tells us how and where to find our argument, we have put a '/L' after the FOR part, so we are dealing with numbers (as opposed to files,) in the brackets we have 1,1,100; start, step, and end, so we start at 1, step forward 1 at a time, and end at 100. after each step it passes the number through %%n into
DO
is a function to deal with, it is just ECHO %%n, so it prints the number it is up to to the screen,


The final method is almost identical to the first, except we use CALL instead of GOTO

Code: [Select]set counter=0
:loop
set /a counter=counter+1
echo %counter%
if not %counter% == 100 call :loop
This is different in the way that it deals with the looping process. I can explain FOR and CALL in more detail if you want, but if you don't understand want I just wrote, then read it again more thoroughly, or go for a slower step by step tutorial somewhere. I hope this helpedI noticed no one posted this, but you can use
Code: [Select]set /a LoopToOneHundred.Counter+=1
to count %LoopToOneHundred.Counter% up by 1, instead of writing out
Code: [Select]set /a LoopToOneHundred.Counter=LoopToOneHundred.Counter+1
(which can get long when your variable gets over 10 letters).Quote from: Lemonilla on September 29, 2013, 10:49:11 AM
you can use
Code: [Select]set /a LoopToOneHundred.Counter+=1
to count %LoopToOneHundred.Counter% up by 1

Yeah Thanks Lemonilla, I forgot to add that in the notes, but I was THINKING about it,

Also you could say
Code: [Select]if /I %counter% LSS 100 goto :loop
which gives the script a bit more integrityQuote from: spivee on September 29, 2013, 06:35:25 PM
Yeah Thanks Lemonilla, I forgot to add that in the notes, but I was thinking about it,

Also you could say
Code: [Select]if /I %counter% LSS 100 goto :loop
which gives the script a bit more integrity

What does the /I switch do here? (I know what it means, I just wondered why you use it in that line)


Quote
What does the /I switch do here?

I wasn't aware that it wasn't necessary to include the /I switch, until after I posted that. I learned almost all of what I know from the help utility, and it is modeled around using == and switching to explicits with /I if necessary, which I assume is because the /I switch once upon a time wasn't optional.Quote from: spivee on September 30, 2013, 02:31:19 PM
switching to explicits with /I

I am not sure what you mean by "switching to explicits". All the /I switch does is make string comparisons case-insensitive e.g. if /I "ABC"=="abc". Since numbers don't have case, it is unnecessary with if %counter% LSS 100.


Quote from: Salmon Trout on September 30, 2013, 03:46:49 PM
I am not sure what you mean by "switching to explicits". All the /I switch does is make string comparisons case-insensitive

Oh, you are right, I misread the help util two years ago then... thanks for clearing that up then
7910.

Solve : save file.txt in folder with spesific name?

Answer»

i NEED a help...

my batch create output and batch save output in different name
exp
bI.TXT
bwash.txt
bthe.txt
bcar.txt
byesterday.txt

echo !output2!>>"%setword%"

"%setword%" save output in different name

what i need is to save it in the folder

normally USE

echo !output2!>>"c:\file\file\word\file.txt" to save output in file.txt

but i use "%setword%" to save as variant file name

any SUGGESTION?

What does %setword% contain? A file name? Can't you do this ... ?


echo !output2!>>"c:\file\file\word\%setword%"

echo !output2!>>"c:\file\file\word\%setword%.txt"

7911.

Solve : Is this possible with a batch file?

Answer»

I just want to know if this is possible with a bath file.

I have 12 txt files that I want to copy (This is working) renaming them in new folder (this is working)
But not all of them change every day, so how can I only let the files that I change today, be copied to new folder, and
the others that have not changed and have yesterday date. not copied to folder.

I some ot the code from somwere else.

Here are some of the code

Code: [Select]@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
pause
rem Windows GP
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows GP Restore.txt" "D:\Users\hbezuidenhout\Documents\WindowsGP\Restore\Windows GP Restore %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows GP Clients.txt" "D:\Users\hbezuidenhout\Documents\WindowsGP\Clients\Windows GP Clients %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows GP Backup.txt" "D:\Users\hbezuidenhout\Documents\WindowsGP\Backup\Windows GP Backup %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows GP Tapes.txt" "D:\Users\hbezuidenhout\Documents\WindowsGP\Tapes\Windows GP Tapes %DD% %MM% %YYYY%.txt"
rem Windows VM
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows VM Restore.txt" "D:\Users\hbezuidenhout\Documents\WindowsVM\Restore\Windows VM Restore %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows VM Clients.txt" "D:\Users\hbezuidenhout\Documents\WindowsVM\Clients\Windows VM Clients %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows VM Backup.txt" "D:\Users\hbezuidenhout\Documents\WindowsVM\Backup\Windows VM Backup %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Windows VM Tapes.txt" "D:\Users\hbezuidenhout\Documents\WindowsVM\Tapes\Windows VM Tapes %DD% %MM% %YYYY%.txt"
rem Unix
call :check_copy "D:\Users\hbezuidenhout\Documents\Unix Restore.txt" "D:\Users\hbezuidenhout\Documents\Unix\Restore\Unix Restore %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Unix Clients.txt" "D:\Users\hbezuidenhout\Documents\Unix\Clients\Unix Clients %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Unix Backup.txt" "D:\Users\hbezuidenhout\Documents\Unix\Backup\Unix Backup %DD% %MM% %YYYY%.txt"
call :check_copy "D:\Users\hbezuidenhout\Documents\Unix Tapes.txt" "D:\Users\hbezuidenhout\Documents\Unix\Tapes\Unix Tapes %DD% %MM% %YYYY%.txt"

goto :EOF

:check_copy
:: gets the LAST modified timestamp in VARIABLES
:: file timestamp MMDDYYYY_HHMMSS
:: syntax: getfiledate.bat "c:\path\file.exe"
@echo off
set "file=%~1"
set "file=%file:\=\\%"
WMIC DATAFILE WHERE name="%file%" get lastmodified | find "." >file.tmp
for /f %%a in (file.tmp) do set dt=%%a
set dt=%dt:~0,8%_%dt:~8,6%
set "lastmod=%dt:~0,8%"
del file.tmp

if "%lastmod%" NEQ "%MM%%DD%%YYYY%" (
MD "%~dp2" 2>nul
echo copying file "%~2"
copy /y "%~1" "%~2" >nul
echo DONE
)
goto :EOF

When I RUB this it dows not do what I newed it to do.

And I don't have these files

Code: [Select]:: syntax: getfiledate.bat "c:\path\file.exe"I recognise that code.Quote from: foxidrive on October 03, 2013, 06:19:45 AM

I recognise that code.
7912.

Solve : Create folder from partial filename and move files into that folder?

Answer»

Try this batch...

CODE: [Select]@echo off

REM Optional section start -------------------------------
REM Create Test files

echo hello > "New York A08Z06 Blue Train Horse JEEP Boat.DOC"
echo hello > "New York A08Z06 Blue Train Horse Jeep Boat.xls"
echo hello > "New York A08Z07 Blue Train Horse Jeep Boat.doc"
echo hello > "New York A08Z07 Blue Train Horse Jeep Boat.xls"
echo hello > "New York A08Z08 Blue Train Horse Jeep Boat.doc"
echo hello > "New York A08Z08 Blue Train Horse Jeep Boat.xls"
echo hello > "New York A08Z09 Blue Train Horse Jeep Boat.doc"
echo hello > "New York A08Z09 Blue Train Horse Jeep Boat.xls"
echo hello > "New York A08Z06 Blue Horse Jeep Boat.doc"
echo hello > "New York A08Z06 Blue Horse Jeep Boat.xls"
echo hello > "New York A08Z07 Blue Horse Jeep Boat.doc"
echo hello > "New York A08Z08 Blue Horse Jeep Boat.xls"
echo hello > "New York A08Z09 Blue Horse Jeep Boat.doc"
echo hello > "New York A08Z09 Blue Horse Jeep Boat.xls"
echo hello > "Chicago A01Z01 Green Car Dog Train.doc"
echo hello > "Chicago A01Z01 Green Car Dog Train.xls"
echo hello > "Chicago A01Z02 Green Car Dog Train.xls"
echo hello > "Chicago A01Z02 Green Car Dog Train.doc"
echo hello > "Chicago A01Z03 Green Car Dog Train.xls"
echo hello > "Chicago A01Z03 Green Car Dog Train.doc"
echo hello > "Chicago A01Z01 Green Water Dog Train.doc"
echo hello > "Chicago A01Z02 Green Water Dog Train.doc"
echo hello > "Chicago A01Z03 Green Water Dog Train.doc"
echo hello > "Chicago A01Z04 Green Water Dog Train.doc"
echo hello > "Chicago A01Z05 Green Water Dog Train.doc"

REM These are bad file names
echo hello > "FailAlphaNumeric AB1Z03 Green Car Dog Train.xls"
echo hello > "FailAlphaNumeric AB1Z03 Green Car Dog Train.doc"
echo hello > "FailKeyWord A01Z03 Green Car Dog Bus.xls"
echo hello > "FailKeyWord A01Z03 Green Car Dog Bus.doc"
echo hello > "FailBoth AB1Z03 Green Car Dog Bus.xls"
echo hello > "FailBoth AB1Z03 Green Car Dog Bus.doc"
REM Optional section end -------------------------------

setlocal enabledelayedexpansion
for /f "delims=" %%A in ( 'dir /b *.doc; *.xls' ) do (
for /f "delims=" %%B in ('cscript //nologo Script.vbs "%%~nA"') do Set "Result=%%B"
if "!Result!"=="Bad Filename" (
Echo Not moving file %%A
) else (
If not exist "!Result!" md "!Result!"
Echo Moving file %%A to folder !Result!
Move "%%A" "!Result!" > nul
)
)
echo Complete
echo.
Pause
...which calls this VBscript... (Referred to as Script.vbs in the batch file above)

Note: In the keyword list, put longer phrases before shorter phrases using the same words or the words used singly THUS:

"Large Red Book", "Red Book", "Book", "Red", "Blue", "Water"

Code: [Select]InputString = wscript.arguments(0)
TokensArray = split (InputString , " ")
KeyWordList = Array ("Large Red Book", "Blue Train", "Train", "Blue", "Water")
AlphaBlockFound = False
KeyWordFound = False
OutPutString="Bad Filename"
Wscript.echo "Filename " & InputString
For j = lbound(TokensArray) to Ubound(TokensArray)
MyString=TokensArray(j)
If Len(MyString) = 6 Then
FlagString=""
For k = 1 To 6
MyChar = Mid(MyString,k,1)
If IsNumeric(MyChar) = False Then
If InStr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ", MyChar) > 0 Then
FlagString = FlagString & "A"
End If
Else
FlagString = FlagString & "N"
End If
Next
If FlagString = "ANNANN" Then
AlphaBlockFound = True
AlphaBlock = TokensArray(j)
BlockNum=j
End If
End If
Next
If AlphaBlockFound = True Then
PreambleString = ""
For L = 0 To (BLocknum-1)
PreambleString = PreambleString & " " & TokensArray (L)
Next
PostambleString = ""
For l = (BlockNum+1) To UBound(TokensArray)
PostambleString = PostambleString & " " & TokensArray (L)
Next
PostambleString = trim (PostambleString)
For q = LBound(KeyWordList) To UBound(KeyWordList)
Sstring=Trim(KeyWordList(q))
If instr (UCASE(PostAmbleString), ucase(Sstring)) Then
OutPutString = PreambleString & " " & Mid(TokensArray(blocknum), 1,3) & " " & Sstring
wscript.echo trim(OutPutString)
wscript.quit
End If
Next
End If
wscript.echo OutPutString
You've done it again. It works perfectly. Thanks for taking the time to help me out.

7913.

Solve : need advanced batch file assistance please?

Answer»

Quote from: strokeman on March 04, 2013, 09:04:15 PM

is fine but not processing %1, whats wrong?

@cls
@ECHO Off
ECHO +-----------------------------+
ECHO :XBMC NFO TO DIR Creator V2.0:
ECHO +-----------------------------+
ECHO.

IF not EXIST NFO2DIR.TXT (
ECHO Ensure yourv'e read nfo2dir.txt before you run, Press ^^C if you want to abort. .
echo Because WARNING: This will irreversibly, alter disk structure!!!
ping localhost -n 5 >nul
) else (
START /max notepad NFO2DIR.TXT
)

if not exist *.nfo (
if "%1z"=="z" (
ECHO It appears you haven't run vid. export yet!
ping localhost -n 5 >nul
exit /B
)
)
echo Please wait. . DON'T INTERRUPT!!
ping localhost -n 5 >nul

for %%a in (*.NFO) do md "%%~na" & move /y "%%~na.*" "%%~na" & move /y "%%~na-fanart.*" "%%~na" & move /y "%

%~na-poster.*" "%%~na" & move /y "%%~na-thumb.*" "%%~na"

if EXIST extrathumbs (
RD /s /q extrathumbs
)

if EXIST extrafanart (
rd /s /q extrafanart
echo extrafanart and extrathumbs dir. deleted
) ELSE (
echo extrafanart or extrathumbs dir. not found. . .
)

if not x==%1x goto end <-- may want to change this to 'if "x"=="%1x" goto end' that WAY, if %1 is more than one word, it wont get messed up
set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2
:end
echo Stacked files may exist, no switches given, read manual
ping localhost -n 5 >nul
dir /p
exit /b

set end=-%b%
for %%a in (*%1.*) do call :next "%%a"
goto :EOF
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
move "%~1" "%var%" >nul

@cls
echo Operation COMPLETED Successfully.
ping localhost -n 5 >nul

That's the only thing I can see, but there may be more that i'm missing. Hard to test without the files. If it still doesn't work, try dropping pause's between the chunks of code to find which one is causing the error.Quote from: strokeman on March 05, 2013, 07:29:39 PM
when theres not a %1 given, ie its blank z or x,y,z whatever you give it, z==z, so a TRUE condition is met.

It will fail with quoted terms. That technique from MSDOS days should be replaced with this in windows:

Code: [Select]if "%~1"==""Thanks for the correction foxidrive, I knew it looked funny, but couldn't figure out why.

out of curiosity, why would it fail with quotes? Does it have something to do with not replacing %1? It seemed to work when I used %a% in cmd.In this instance the %1 will contain quotes when long filename elements are used in %1.

if "%1z"=="z"

So that line will expand to this which is a mess and the long filename elements like spaces and & will cause an error MESSAGE:

if ""my file.txt"z"=="z"

@cls
::@ECHO Off
COLOR 1F
ECHO +--------------------------------+
ECHO :XBMC NFO TO DIR Creator V2.00. :
ECHO :(c)2012,2013, by the 'Strokeman':
ECHO +--------------------------------+
ECHO.

IF not EXIST NFO2DIR.TXT (
ECHO Ensure your've read nfo2dir.txt before you run, Press ^^C if you want to abort. .
echo Because WARNING: This will irreversibly, alter disk structure!!!
ping localhost -n 5 >nul
) else (
START /max notepad NFO2DIR.TXT
)
goto miss

if not exist *.nfo (
echo.
ECHO It appears you haven't run vid. export yet!
ping localhost -n 5 >nul
exit /B
)
:miss
if "%~1"=="" (
echo.
echo Stacked video files MAY be present, no
echo commandlines given, continuing anyway. .
ping localhost -n 5 >nul
)

echo.
echo Please wait. . DON'T INTERRUPT!!
ping localhost -n 5 >nul

for %%a in (*.NFO) do md "%%~na" & move /y "%%~na.*" "%%~na" >nul

if exist (*-fanart.*) (
for %%a in (*.) do (
move /y "%%~na-fanart.*" "%%~na" >nul
)
)

if exist (*-poster.*) (
for %%a in (*.) do (
move /y "%%~na-poster.*" "%%~na" > nul
)
)

if exist (*-landscape.*) (
for %%a in (*.) do (
move /y "%%~na-landscape.*" "%%~na" >nul
)
)

if exist (*-thumb.*) (
for %%a in (*.) do (
move /y "%%~na-thumb.*" "%%~na" >nul
)
)

if EXIST extrathumbs (
rd /s /q extrathumbs
)

if EXIST extrafanart (
rd /s /q extrafanart
echo.
echo extrafanart and extrathumbs dir. deleted
) ELSE (
echo.
echo extrafanart or extrathumbs dir. not found. . .
)

set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2

:end
echo.
echo The following is a listing of files not yet processed
echo it dosent show your newly created dir. structure!. . .
echo.
dir /a-d-h
ping localhost -n 3 >nul
goto :eof

set end=-%b%
for %%a in (*%1.*) do call :next "%%a"

goto end
if not "%~1"=="" (
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" >nul
)

:skip
echo.
echo Operation Completed Successfully, you will now have to update Library, After
echo that, please run artwork downloader, then enable extrafanart in chosen skin.
ping localhost -n 5 >nul

i dont get it, have looked at it a million times. if i PUT in a %1 its fine, but with no commandline it gets stuck in the red section, incrementing to affinity, till i ^c it?Looking only at the red bit:

Code: [Select]goto end
:next
set "var=%~n1"
call set "var=%%var:~0,%end%%%"
md "%var%" 2>nul
echo moving %1 to "%var%"
move "%~1" "%var%" >nul
goto :EOFbugger, hl the wrong section, sorry!

set a=%1
setlocal EnableDelayedExpansion
set b=1
:loop.countChar.2
call set c=%%a:~!b!,1%%
if "%c%"=="" goto end
set /a b+=1
goto loop.countChar.2
goto :EOF
The characters % and ^ in filenames might cause problems.

Code: [Select]@echo off
set "a=%~1"
set b=0
:loop.countChar.2
call set "c=%%a:~%b%,1%%"
if "%c%"=="" goto :end
set /a b+=1
goto loop.countChar.2

:end
echo %b%
pause
i just wrapped it in if not exist "%~1" (...code....). so it skips that section if no %1 specified, but thats just avoiding the prob, so will try your way.

thanks so far, you guys rock! theres some issues still, but have other 'work', so will have 2 shelve it for now . but ill be back.
7914.

Solve : file properties?

Answer»

Quote from: novice84 on October 02, 2013, 07:01:23 AM

e.g. size, type, Author, Date modified, Path, etc.

& Project.

above listed these 6 properties will do the job.

I don't mind even if all properties are exported together.Is there a specific file type - doc, xls, ppt, or what?
Quote from: novice84 on October 02, 2013, 07:01:23 AM

but unfortunately I know a little bit of DOS

so I need to learn Wscript now
& Wscript means VBscript ?
are these same or different things ?

This is off topic, but you just need to GET a solution to your problem, whether it uses VBS or JS in WINDOWS Scripting Host (that is cscript.exe [cmd line] and wscript.exe [gui based]) or batch or some helper batch files, or third party utilities, and then understand the immediate details of how to use it.

In the future you will pick up more knowledge and can revisit your older scripts and figure out how they work.
The people here will also help you understand specific details of some code, when you ask.


But to help us develop an appropriate solution, we must have exact details of the task - and the person(s) helping you can then figure out the best or easiest code to solve the job. Knowing the details also enhances our enjoyment of writing some code to help you - otherwise we become bored scripting machines, and not human beings who give up their time to help other people.

Quote from: Salmon Trout on October 02, 2013, 11:59:22 PM
Is there a specific file type - doc, xls, ppt, or what?


no there is no specific type.
as I mentioned before as with DIR command we can list of files that exist in a folder, I was hoping to get more details of every file as we can see in file explorer. I thought it will be simple and straight forward, but seems to be complicated.

if it's required to mention a file type, .doc files we can start with and I hope in code we can easily change file extension to match the need.

Quote from: foxidrive on October 03, 2013, 01:17:21 AM

But to help us develop an appropriate solution, we must have exact details of the task - and the person(s) helping you can then figure out the best or easiest code to solve the job. Knowing the details also enhances our enjoyment of writing some code to help you - otherwise we become bored scripting machines, and not human beings who give up their time to help other people.


I appreciate every ones time & effort but trust me I have tried my best to explain.
well you have asked I will try again

if we use command DIR /A-D > tree.txt
we will get Date Modified, Time & Size along with file name.
so here we already getting 3 file properties.

I thought may be it's EASY the same WAY we can get more details.Again you failed to tell us the type of files you are processing, and haven't listed the properties in the order and format you want, and which properties you want.

It's kind of like taking your car to the mechanic and saying - there's something WRONG with my car, please fix it. And not telling him what is wrong.
7915.

Solve : Robocopy-Dealing with blank in directory name?

Answer»

Hi,
I have these commands in a batch file to copy Thunderbird archive EMAILS to an external disk. For testing, I am running them from a DOS cmd prompt.

Set InPath="C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\Local Folders\Archives.sbd\2013.mozmsgs"
Set OutPath=\\EXTERNALDRIVE\Public\BackUp-Email\Sue-Email-Bkup\2013
Robocopy %InPath%\ %OutPath% /COPY:DATS /Log:EmailBkupLog.txt

I get error 123 (0x0000007B accessing source directory C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\Local
The file name , directory name or VOLUME label is incorrect

The error is because Robocopy is not parsing Local Folders correctly because of the blank after Local
I have tried the following
two sets of quotes
Set InPath="C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\"Local Folders"\Archives.sbd\2013.mozmsgs"

and-no quotes
Set InPath=C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\Local Folders\Archives.sbd\2013.mozmsgs

and-entire path in quotes
Set InPath="C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\Local Folders\Archives.sbd\2013.mozmsgs"

and this- I get no destination directory specified because of the quote around Local Folders
Set InPath=C:\Users\Owner\AppData\Roaming\Thunderbird\Profiles\2l2fhjja.default\Mail\"Local Folders"\Archives.sbd\2013.mozmsgs

I need HELP in correctly specifying the input path.
Thanks
Frank C
Win Vista Ultimate64 bit sp2Greetings Frank,

Quote

Robocopy %InPath%\ %OutPath% /COPY:DATS /Log:EmailBkupLog.txt

Try dropping that backslash '\' and using:

Robocopy %InPath% %OutPath% /COPY:DATS /Log:EmailBkupLog.txt

Best wishes!Thanks for the reply OcalaBob,
That fixed it. I ALSO had to put both paths in quotes because of the UNC ADDRESSING for the external drive.
I fought that battle once before.
Regards
FrankGC
7916.

Solve : Is it possible to sense when a program is opened using vbs??

Answer»

I know you can do it (if not very well) in batch using 'tasklist' and 'fc'. But is it possible to do with vbs?' This computer
strComputer = "."

'Access WMI Object
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Get a collection of all running tasks
Set ColRunningTasks = objWMIService.InstancesOf("Win32_Process")

'Iterate through them showing 2 of the named properties for each
For Each Task In ColRunningTasks
WScript.Echo Task.ProcessId & ":" & Task.NAME
Next

These properties are available (that I know of, they are the column headers you see when you do WMIC Process List at the COMMAND line)

(Not all return values in the above script)

CommandLine
CSName
Description
ExecutablePath
ExecutionState
Handle
HandleCount
InstallDate
KernelModeTime
MaximumWorkingSetSize
MinimumWorkingSetSize
Name
OSName
OtherOperationCount
OtherTransferCount
PageFaults
PageFileUsage
ParentProcessId
PeakPageFileUsage
PeakVirtualSize
PeakWorkingSetSize
Priority
PrivatePageCount
ProcessId
QuotaNonPagedPoolUsage
QuotaPagedPoolUsage
QuotaPeakNonPagedPoolUsage
QuotaPeakPagedPoolUsage
ReadOperationCount
ReadTransferCount
SessionId
Status
TerminationDate
ThreadCount
UserModeTime
VirtualSize
WindowsVersion
WorkingSetSize
WriteOperationCount
WriteTransferCount
These come BACK blank on my system (Win 7 64, SP1)

ExecutionState
InstallDate
Status
TerminationDate

If you wanted to know if a particular task was running you could do something like this

' This computer
strComputer = "."

'Access WMI Object
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Get a collection of all running tasks
Set ColRunningTasks = objWMIService.InstancesOf("Win32_Process")

TestTaskName="notepad.exe"
Running = False

'Iterate through them comparing name property with wanted task name
For Each Task In ColRunningTasks
'make both strings LOWER case to force case INSENSITIVE compare
If lcase(Task.Name) = lcase(TestTaskName) then
Running = True
End If
Next

If Running = True then
Result = " is running"
Else
Result = " is not running"
End If

Wscript.echo TestTaskName & Result


7917.

Solve : Move batch files ...?

Answer»

Hi,

How to write batch file commands to move files (if exists) from root directory to the final . directory?

The files in root directory will be of format "ABC_121002_00023_21_8.dat" Please note here that in 121002, 12 is Year and 10 is month and 02 is date ...

Source : C:\ABCD\ABC_121002_00023_21_8.dat
Destination : C:\ABCD\201210\ABC_121002_00023_21_8.dat <-- 201210 ... 2012 is year and 10 is month from Filename. Assume this folder is already created ... we just need to move files to corresponding folder from filename.

Please let me know.
Thanks.This seems to work.
Code: [Select]for /f "delims=" %%A in ('dir /b ^| find *.dat') do (
for /f "tokens=2 delims=_" %%B in ("%%A") do (
move %%A %%B\%%A
)
)
though it seems to FREAK out if it doesn't have anything to sort.Quote from: Lemonilla on March 18, 2013, 05:21:47 PM

This seems to work.
Code: [Select]for /f "delims=" %%A in ('dir /b ^| find *.dat') do (
for /f "tokens=2 delims=_" %%B in ("%%A") do (
move %%A %%B\%%A
)
)
though it seems to freak out if it doesn't have anything to sort.
You are MISSING the LEADING 20 for the output year.

This can be done with a single FOR loop. Just use tokens=1,2* delims=_
strip the first 4 characters off of %B and add in the leading 20.This should work. @Lemonilla: your find.exe syntax is fubar.

Code: [Select]@ECHO off
setlocal enabledelayedexpansion
for %%a in (*.dat) do (
for /f "tokens=2 delims=_" %%b in ("%%a") do (
set "INFO=%%b"
set "year=20!info:~0,2!"
set "month=!info:~2,2!"
md "!year!!month!" 2>nul
echo "%%a"
move "%%a" "!year!!month!"
)
)
pauseThank you all.
Thank you foxidrive . it works.
7918.

Solve : Batch File Problems?

Answer»

I want to have the date in a file name, problem is that the date is done like this: mm/dd/yyyy. A file name can't have a "/' in it. Any ideas on hwo to overcome that?This is OS dependent.

Code: [Select]
for /f "tokens=1-4 delims=/ " %%a in ("%date%") do (
set mon=%%b
set day=%%c
set yyyy=%%d
)


Now that you have mon, day and yyyy, you can do what you want with them.

Hope this helps. Hey, I've got the same problem, but a different setup.

There is a number like this: X.XX

I need to take the FIRST X and set it as a variable and take the last two XS and set them as a variable.

This'll probably just be the same as the above solution, just with some tweaks, but I'm not SURE how to do it.

BTW, THANKS a lot for your help! What you suggested for my last problem fixed it perfectly! Thanks!Pretty much the same thing. You didn't mention where this X.XX was so I just picked a literal to give you an idea how it WORKS:

Code: [Select]
for /f "tokens=1-2 delims=." %%a in ("X.YZ") do (
set varA=%%a
set varB=%%b
)


Hope this helps. There are two files, each with a number in them. Should this code get those numbers and put them into their appropriate variables or am I doing it wrong?

Code: [Select]for /f %%a in (UserVersionmajor.txt) do (set MAJ=%%a)
for /f %%a in (UserVersionminor.txt) do (set MIN=%%a)You could try it and see. Your're not doing anything destructive, but yeah it should work. Sorry, the last code you gave me is what I need, but I'm getting the stuff out of a file, not just a regular string.Code: [Select]
for /f %%a in (UserVersionMajor.txt) do (
set maj=%%a
)
for /f %%a in (UserVersionMinor.txt) do (
set min=%%a
)


Quote

There are two files, each with a number in them


This works if and only if the first file contains a single record with the major version AND the second file contains a single record with the minor version. If not then you add complexity requiring IF statements to identify the record and to parse out the value you need.

DOS batch is not designed for low level record processing.

Good luck.
7919.

Solve : RENAME?

Answer»

Hi all,

I have a need to run a batch script that renames a file from:

text_abcdefgh_nonvariablestring-DDMMYYY.ext

to

text_abcd_nonvariablestring-DDMMYYY.ext

any thoughts?Seems ok here:

Code: [Select]@echo off
setlocal EnableDelayedExpansion
SET "file=text_abcdefgh_nonvariablestring-DDMMYYY.ext"
for /f "tokens=1,2,* delims=_" %%a in ("%file%") do (
set "abcd=%%B"
echo ren "%%a_%%b_%%c" "%%a_!abcd:~0,4!_%%c"
)
pauseAwesome, worked perfectly. Thanks.

Is there a way to do this without variables? It's just that the simpler I can MAKE the code, the easier it will be for the end USERS of this process to follow what's going on.Quote from: thenoman on October 02, 2013, 05:10:38 AM

Is there a way to do this without variables? It's just that the simpler I can make the code, the easier it will be for the end users of this process to follow what's going on.

What do you mean without variables? Which variable(s) were you thinking of?Quote from: foxidrive on October 02, 2013, 06:14:15 AM
What do you mean without variables?

Gotta be a classic.
7920.

Solve : Vid Problems with DOS?

Answer»

Does anyone know how to get drivers for a Voodoo 4 / 4500 for DOS, or how to get the card to run DOS games? It displays everything else fine, but when I start a game, all I get is a black screen.

Also, I can't remember how or what a VESA driver is for. Any help would be GREAT!More info required!DOSBoxOk, I just built an "old" machine from spare parts. It's a shuttle AVI61 MB, AMD Athalon 950, 256 m pc133, SB 16, running MS DOS 6.3 and Win 3.11.

When I start, it has video fine, but try to launch a game (x-com ufo), and for a brief instant, I can see the script of the batch file in the game run, then nothing. I have to boot to get it to do anything. Years ago, I had ALMOST the same machine running fine (pII, DIF. Vid card & MB), but my memory bytes now. I can't FIND anything for the Vid for DOS, but it seems there was a way...

THANKS

7921.

Solve : Batch file, if else, and reboots?

Answer»

Good afternoon everyone,
I am new to this site and hope someone can assist me in this issue. i have spoken to several admins and i get conflicting commands. so here goes.
i have a batch file that i put into the login script of the gpo to be pushed out to all of the computers. the batch file is simple and runs a registry file, stops the print spooler and RESTARTS it, then refreshes the print spooler. once it is complete it updates the group policy.
batch file:
regedt32 /s printers.reg

net stop spooler
net start spooler

gpupdate /force

it WORKS great but upper management wants to add a couple commands. they want to copy the reg file to the computers on the domain and for the batch file to run only once and force a restart of the computer.
/boot command sends the computer into a endless LOOP of rebooting. so that doesn't work well.
does anyone know the if else statement to complete this?
or the commands to work this issue?

any assistance in this matter would be greatly appreciated.Easiest method would be 2 batch files.

Batch1 - Runs the processes that are desired and calls for execution of Batch2 to start, with Batch 1 ending.

Batch2 - Deletes Batch1 and gives the system the reboot command.

- System processes what you need and only reboots once because Batch1.bat no LONGER exists at the location that causes the boot/reboot loop. Batch2.bat needs to be located in a location outside of a STARTUP area so that it would not be triggered on boot to execute.

* Above works if you plan on 1 time use of logon script per machine, and then removing this logon script from this happening with consecutive logons.

7922.

Solve : Getting Filename & Date?

Answer»

I WANT a file created using DOS like this

Filename,date modified
aa.txt,12/12/2005 6:45 AM

PLEASE send me the commands.The FOLLOWING SYMBOLS cannot be used in a file name:

/ \ | : * ? " < >

Get back to US with a valid question. Please mention your OS as batch language varies between versions.

7923.

Solve : Closing a dos wndow?

Answer»

[size=16]how to close a dos window running through a batch file automatically?

I have given the "exit" command... but still the window does not close.

the commands I gave in the batch file were this:

start c:\windows\desktop\document.doc
exit

and the command shown at the dos window is this:

c:\>start c:\windows\desktop\document.doc

c:\>Exit


After running the Exit command , the dos wondow remains there ,without closing[/size]Probably something LEFT over from the EARLY days of DOS. When the ms-dos prompt (command.com) is started, it's considered a first level processor. When an EXIT in a batch file is encountered there is simply no OS to return to and the EXIT is ignored. You can however manually TYPE EXIT at the prompt to close the window (go figure!:-/).

This does not apply to the command prompt (cmd.exe FOUND on NT MACHINES). A CMD window will behave as you would expect.

7924.

Solve : CACLS leading to deletion of files in root directory on USB Flashdrive?

Answer»

Hi all,

could someone pls help with the below ( I'm using it in the root directory of the USB flash drive, and for a folder called 'USB' which has encrypted file in it )
on decryption the folder is meant to be accessible (by using CACLS), then any decrypted folders/files (excluding the encryption master file which has a +S +H attribute to it) and not ;the 'USB' folder itself are to be deleted / removed...

Below is the code ( this works fine, the moment i switch computers, even though the drive is the same 'E:\' ), it tends to delete any files in the root directory of the USB Flash Drive ( where I execute this batch file from) , also it tends to lock up the Cacls Folder 'USB' and makes it inaccessible even with CACLS COMMANDS !

any help greatly appreciated !
cheers


:: Auto deletion of decrypted files

@Echo Off

cd %cd%

cacls USB /e /c /g %Username%:f

cd USB

cls

start usbsafeguard.exe


echo To delete recently decrypted/viewed files and folders.........press any key
echo.
echo Will only delete copies of decrypted files ( not the original encrypted files)
echo.
echo.

pause

cls

:: Deletes files in USB (except ones with attrib +h +s )

del/A:-H-S USB *.*

:: Deletes/Removes folders in USB folder (but not the 'USB' folder itself)

pushd %1
del /Q *.*
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd


cd..

cacls USB /e /c /d %Username%

exit


Quote from: tomcatonnet99 on March 23, 2013, 08:05:48 AM


del/A:-H-S USB *.*

:: Deletes/Removes folders in USB folder (but not the 'USB' folder itself)

pushd %1
del /q *.*
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd


The first command should PROBABLY be: del /A:-H-S \USB\*.*?

Then the pushd has %1 as a parameter but we don't know what it is.

This should delete the files and folders in \USB but retain the folder.

Code: [Select]pushd "\USB" || goto :EOF
rd /s /q "\USB" 2>nul
popd will give it a try,

1) the del /A:-H-S \USB\*.*? Whats the '?' for pls? is it to determine deletion be done if \usb is not empty
( also would that matter if a folder is empty and I run the above command)

2) could you pls explain how the latter half works?

pushd "\USB" || goto :EOF ......... ( what is || for )
rd /s /q "\USB" 2>nul ............( what is 2> exactly)
popd

many thanks indeed!

Regds

Tom

See the in-line comments in blue.

Quote from: tomcatonnet99 on March 24, 2013, 12:37:34 AM

1) the del /A:-H-S \USB\*.*? Whats the '?' for pls? is it to determine deletion be done if \usb is not empty
( also would that matter if a folder is empty and I run the above command)

The ? suppresses the question 'Are you sure?'
It should work in an empty folder too.


2) could you pls explain how the latter half works?

pushd "\USB" || goto :EOF ......... ( what is || for )

|| is a conditional operator and here it exits the batch file if the folder doesn't exist or cannot be changed to.
It runs if the errorlevel from the preceeding command was true. && is the opposite and runs a command if the errorlevel is zero/false.


rd /s /q "\USB" 2>nul ............( what is 2> exactly)
popd

2>nul redirects a harmless error message (from the STDERROR stream) to the NUL device so it isn't displayed on the screen.

Many thanks foxidrive, truly appreciate that explanation..

I think the problem is CACLS ... the first instance it unlocks the folder 'USB' ... runs through the entire routine without a glitch even with the earlier code for del and rd, run it a second time and it locks the folder and now I've tried everything and it wont unlock!

cacls USB /e /c /grant Everyone:f
cacls USB /p Everyone:f
cacls USB /e /c /g %Username%:f



Any suggestions? Why would it do that ( have tried it on 2 different laptops in WinXP and Win7 and both react similarly, just not the laptop on which it was initially created which is also a winXP) on the parent laptop it is able to unlock successfully regardless of the number consecutive locks/unlocks!

also does CACLS work exactly the same in Win7 / Win8 as I will need to use this flash drive and the above batch file in different environments
It may be because you grant permission to username, but then remove permissions to username and that may include all the default permissions.

What you could do is Edit and grant 'everyone' permission, and do your tasks, and then remove the 'everyone' permission.

You should find that even if it is 'locked' then by starting from an elevated admin prompt you will be able to access the folder again and change permissions.Quote from: tomcatonnet99 on March 25, 2013, 05:40:25 AM
also does CACLS work exactly the same in Win7 / Win8 as I will need to use this flash drive and the above batch file in different environments

The security you are using seems to be a bit haphazard as any admin will be able to take ownership, and change the permissions.

In Windows 7 and 8 there is an additional tool called ICACLS I think, and while CACLS works the same way (I think, I haven't checked deeply) I have found that there are some system folders that it cannot change the permissions of (at least to edit and grant permissions to 'everyone').may be so as regds its inability to change permissions to some system folders but this is on a USB flash drive...

MY set up is as follows:

I have a PROGRAM 'USB Safeguard' which resides in \USB folder, its executable file is hidden
with attrib +h +s. It creates its own .lnk invisible(-s-h attrib) encrypted file(needs password to unlock) ....

1)so far I've never seen it being deleted whilst using the TYPE nul>\USB\*.*

on using Del A:\-s-h %cd%USB\*.* DESPITE the -s -h its still deleting that file ! what am I doing wrong pls?

2) and I don't see why cacls would work on one laptop and not another

regds

further rd /s /q removes the \USB directory as well which isn't what I want for to happen ... only the contents (files and folders except +h +s attrib ones ) to be deleted / removed

If you use the code as provided then it won't remove the \USB folder too because it is in use, as the pushd command opens the folder and locks it from being deleted by the RD command.

Quote
pushd "\USB" || goto :EOF
rd /s /q "\USB" 2>nul
popd
Quote from: tomcatonnet99 on March 25, 2013, 06:14:00 AM
only the contents (files and folders except +h +s attrib ones ) to be deleted / removed

Sorry, that's different to what I had understood you wanted to do.

The RD command will remove all folders and files from within \USB



Another post:

This will not delete hidden files from \usb and will remove the folders and files.

Code: [Select]@echo off
del \usb\*.???
for /f "delims=" %%G in ('dir \usb /b /ad') do rd /s /q "\usb\%%G"
pause
I admit I didn't read all the posts, however I noticed the use of cacls and USB flash drives, so I think it's worth mentioning that flash drives, under normal circumstances, will use FAT32, which does not support Access Control Lists; cacls is a ACL editor, so there might be some assumptions or extra information from the ACL security info that you are trying to use that just isn't available.Quote from: foxidrive on March 25, 2013, 07:12:08 AM
Another post:

This will not delete hidden files from \usb and will remove the folders and files.

Code: [Select]@echo off
del \usb\*.???
for /f "delims=" %%G in ('dir \usb /b /ad') do rd /s /q "\usb\%%G"
pause

thanks, is this the same as using push \usb and then rd/ s /q it?? ( coz thats definitely a lot simpler, as I would need to understand what exactly the above means / how it works)
especially delims .... what is /f and whats the difference between "delims=" and "delims=*"

Quote from: BC_Programmer on March 25, 2013, 01:00:01 PM
I admit I didn't read all the posts, however I noticed the use of cacls and USB flash drives, so I think it's worth mentioning that flash drives, under normal circumstances, will use FAT32, which does not support Access Control Lists; cacls is a ACL editor, so there might be some assumptions or extra information from the ACL security info that you are trying to use that just isn't available.

Yes I'm using the NTFS format as I use the 'safeguard.exe' in the \USB folder which requires NTFS.

the problem is CACLS! it works perfectly well to lock&unlock the \USB from any unintentional deletion; but in Win7 / Win8 ICACLS would be required and as such I would like to have a CACLS /ICACLS available for any system operability...

(ICACLS is just way to complicated, its like MS have just nuked us! to stone age and driven users to an other planet and now we're like aliens! there )

Any ideas/ suggestions to lock / unlock \USB folder?
7925.

Solve : starting logon.bat maximized?

Answer»

Ok I need help. Although im not a DOS fan. I did create a NICE logon.bat that NEEDS some user input. But since I work with a lot of very ignorant users that dont feel the slightest need to investigate that pretty scarey button in their taskbarr, I need that logonscript to start MAXIMIZED. It should really prevent everything else from loading untill they entered their input but that might be a little too much to ask :-). I tried everything I COULD think off (and Im pretty creative) with the start /max command but I cant get it to work. Please help before I strangle a few PEOPLE!Post bat file used:Im sorry, did you mean to ask me if I would post the batchfile I use?I'm guessing Merlin did in fact suggest you post your batch file.

Try using start /max /wait

One quirk I've noticed with START is put the switches before the command you're starting.

Just my 2¢ worth.

7926.

Solve : trying to start up :-/?

Answer»

Hi,
I have windows 98 operating system and have never used the OPTION "RESTART in MS-DOS" and never knew what it was. Well I stupidly decided to investigate the other DAY and restart in MS-DOS . The computer came back on and loaded to a certain point and then just went to C:> and the cursor flashed at this point waiting. Nothing else happened. I've tried shutting down and trying again but the same thing happens.
I tried restarting in Safe mode and all looks fine but in System properties, performance, it says that drives A and C are running in MS-DOS compatability mode and that this reduces overall performance. I've scan disked and defragmented and nothing has changed: without starting up in safe mode the computer will not run. All I want is to get it back to running normally. Can anyone please please help?
EllieAt the c:> prompt type cd\windows Then winJust tried it, all worked perfectly, now back to normal mode. Thank you so, so much, I'll never be investigating again after that little panic!
Thank you!
EllieI will not mind if you inveestigate again.

you could do another thing at that c:> prompt

Just press ctrl+Alt +Del so your computer restarts.

slightly after 3 or 4 seconds when you are at the POST screen press F8 and then you will ENTER to "startup menu"

At this menu you can choose the mode in which you want to start your computer with.

if you are at the windows, you can ALSO enable startup menu like this:

start--> Run--> msconfig

on the "General tab" click "advanced" tab

then check to select "enable startup menu"

click "ok" and then restart your computer when you are asked to do so.

7927.

Solve : Create a batch file, need help please?

Answer»

Hello, need some help please. I need to creat( if possible) one batch that permit to make a search and EXECUTE the file that i searched for. Example I have several bios updates from several models, for example: I have PSTA2, PTA2E, PDVX3(inside of each folder there is the bios .exe. So the idea is to creat a batch file and we execute it ask to input the model to search. we put PSTA2 for example ask for confirmation and execute the update bios.
In many CASES the differents models(PSAT2,PSAT3,PSAXL, etc...) uses the same file to update the bios. So the idea is: i want to put a search line where i put the model name(PSAT2,PSAT3,PSAXL, etc...) in a way that e runs the right file to make the update.
Eaxample: PSAT2,PSAT3,PSAXL, use the same bios file to update(let´s call bios.exe). When i put in the search line PSAT2 runs the bios.exe, if i put PSAT3 runs the same bios.exe .

But to do this i need a way to "say" that file, bios.exe, gives to PSAT2,PSAT3,PSAXL because is the same.With all the incorrect things that can happen with a flash a batch file to run one would be the last project i'd ever consider.iHello patio, agree waht you said, but this is to make my job easy. i am a CERTIFIED in Toshiba and HP and they have a huge number of bios updates for the laptops and PC. The idea is to put all in the same Usb flash to make the job easy.This little snippet is meant more to show method than a solution. I agree that using a batch file to flash a BIOS MIGHT be a bit risky.

Code: [Select]@echo off
setlocal enabledelayedexpansion

:loop
set /p model=Enter Model:
set /p verify=Re-Enter Model:
if /i %verify% NEQ %model% goto loop

for %%v in (PSAT2, PSAT3, PSAXL) do (
if /i !model! EQU %%v bios.exe & goto :eof
)

for %%v in (PSAT4, PSAT5) do (
if /i !model! EQU %%v bios1.exe & goto :eof
)


The key is the for instruction. Within the first set of parens is a list of the model numbers that will execute a common bios flash. Each for statement has it's own set of model numbers which execute a different bios flash. You can have as many for statements a required. The & goto :eof is likely not needed as the flash will probably need a boot, ending the batch file.

Rather than depending on user input, you can replace the loop CONSTRUCT and extract the model directly from the machine:

wmic computersystem get model

You probably need to add path information to the flash files.



7928.

Solve : Notify page when a batch file crashes.?

Answer»

Hello all,

I have more than 15 batch files that they perform a lot of actions (Robocopy, sent emails, etc).
I want to ask if it's possible to have a page (ASP.NET or PHP) where when a batch file crashes or hangs, the page should write smth.
For example will write "Batch file Robocopy" and when it crashes should be "Batch file Robocopy Crashed"
What do you thing, is possible smth like that?I made a monitor in the past that was written in C++ that was a scheduled task that checked on automated processes/ batches as to if they ran or not successfully. At the end of my batch instructions I added

echo. %date%>Routine1_log.txt

In my C++ program it verified the date in this file Routine1_log.txt with the current date. If they matched all was well, however if this file had yesterdays date in it, then I know that the batch did not complete. In my C++ program if a failed automation process was detected I would receive an e-mail with the process that did not complete.

You will need to use a similar routine to test and verify that it was completed. My suggestion is to make a log file entry similar to what i did and have a process that is scheduled monitor for failure on timed intervals. Such as when the process should have completed and hasnt looking for a date match etc.Thank you for your reply,

Can you plz share your c++ program, the things i want are similar to your program.Will SEE if I can dig it up. Haven't used it in over 5 years. Couldn't find my program, but rounded up a better way to do it that is easier just using file compare. In the C++ program I read in contents from 2 files and performed a string compare, but now that I realized that this can be done way easier using FC, I wish i did that back then vs reinventing the wheel...LOL

Code: [Select]@echo off
echo %date%>todays_date.txt

fc c:\test\todays_date.txt c:\test\Last_Run.txt > nul
if errorlevel 1 goto mismatch

:next
exit

:mismatch
echo Mismatch, running notification
START emailme.bat
This batch will exit if they match and start emailme.bat if the dates mismatch between SAY todays date and what should also be todays date in the batch log file created by adding echo %date%>Last_Run.txt to existing batch.

emailme.bat started if there is a mismatch will use Windows Power Shell to email you by creating a batch file with info such as the following example from http://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/ :
Quote

$EmailFrom = “[emailprotected]
$EmailTo = “[emailprotected]
$Subject = “The subject of your email”
$Body = “What do you want your email to say”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

I used a different tool to e-mail myself via command line, but this should be all you need editing for PATHS and piecing this together to make it happen.

Thank you very very much for your reply and for the time you spent to write the code.
I will try it and i will inform you about the results.
7929.

Solve : Output Screen Contents?

Answer»

I'm having a problem outputing the screen results of a batch file (I.E. results of a timed run of an NBTSTAT or other SYSTEM query ) as a text file to be SENT to a directory such as c:\10\Status. Any suggestions appreciated..I would think you need to redirect the output:

nbtstat -n > c:\10\Status

Use any of the nbtstat switches you need.

Hope this helps. Thank you for the redirect suggestion. It will works in the limited example I sent. The problem is I need the complete contents of the screen to display, both on-screen and in a text file. I should have previously stated the extent of the batch file executions - please refer to the example code below. I need the dates and contents of the tracerts and pings and just to foul things further, there is also a 30 second delay between one of the executions.

@ECHO OFF
Date /T
Time /T
ECHO
tracert msn.com
tracert mail.mail.com
ECHO.
ECHO.
ECHO OFF
PING 1.1.1.1 -n 10 -w 3000 >NUL
ECHO.
Date /T
Time /T
ECHO
ping msn.com
PAUSE
Are your text files intended for a permanent record or just a temporary thing until the next time the batch file is run?Just redirect the output from the entire batch run to a file. You can't send a data stream to two separate devices (console and a file) at the same time. A workaround would be to TYPE the file with the redirected output.

ie. batchfile > batch.txt

A few potential problems. The redirect of the PING to the nul device will produce no output and override the redirect of the batch file output. The PAUSE will produce a "Press any key to continue . . ." message to the output file but the user will never see it; makes responding to the message difficult.

Note: the time delay in the PING command will not change any results. Just delay the inevitable.

Hope this helps. The redirect of the PING to the nul device will produce no output and override the redirect of the batch file output.

Not so. Pinging to a non-existant IP and redirecting to the nul device simply acts as a timer and introduces a delay.I stand corrected 2K. I should have worded it a bit BETTER. Sometimes my BRAIN works on a 30 second delay. <<2k dummy wrote: Are your text files intended for a permanent record or just a temporary thing until the next time the batch file is run?>>
Thanks for insights 2k (caught that nul ping thing, huh) - the text files are intended for temporary record only.

Sidewinder: Thanks for all inputs. Your suggestion to redirect the entire batchfile to a text file will work out OK for the actual application. Originally I had a desire to view the batch file output on the console as well as generate a temporary text file record, but that complication both elludes me and is probably unnecessary.As Sidewinder said, you can use the type command to do it.

ping msn.com > c:\10\status\msnping.txt
type c:\10\status\msnping.txt

do the same with other ping command. You can add lines to delete them before the batch EXITS. Or if you want to save them for later review, you can add lines at the beginning of the batch to delete before creating new text files.

7930.

Solve : HELPPP!!!!!!!?

Answer» HI im in deep deep poo i think. I was tryin to reinstall windows xp, but kept being told the computer couldnt fine any hard drives connected to the computer. I have a SATA hdd so i was tryin to run some drivers from a floppy. I booted the pc and a message came sayin hystem.sys not found. so i took the floppy out and booted as normal. i arrived back at my desktop, insterted the floppy and looked at the CONTENTS. On the floppy were 2 dos files that werent on before so i deleted them and rebooted the pc. Now at BOOT up it says dos could not be found and the computer want go past that stage. HELP ME PLEASE!!!!!!Quote
hi im in deep deep poo i think. I was tryin to reinstall windows xp, but kept being told the computer couldnt fine any hard drives connected to the computer. I have a SATA hdd so i was tryin to run some drivers from a floppy. I booted the pc and a message came sayin hystem.sys not found. so i took the floppy out and booted as normal. i arrived back at my desktop, insterted the floppy and looked at the contents. On the floppy were 2 dos files that werent on before so i deleted them and rebooted the pc. Now at boot up it says dos could not be found and the computer want go past that stage. HELP ME PLEASE!!!!!!


Well ...for openers get a pair of CHEST waders ......lol
Your post is a wee bit confusing .......If you had formatted the drive ........how did you manage to end up on your desktop ? and .......the 2 dos files you mentioned .........they had to come from SOMEWHERE .

How about having another go at explaining exactly what you did in detail .........

dl65

7931.

Solve : Batch Antivirus---is this possible??

Answer»

I had done a little bit of batch programming, and I suddenly thought if it was possible to make an antivirus using batch programming. Is this possible for batch?
Thanks for any help You won't make an on-access AV using batch.
Batch alone won't work for a file scanner AV either - you'd need to use external tools or VBS/Jscript/Powershell to help.

The best you could hope for is to have a virus definition database and then compare the files to look for the definitions and move them to a holding folder, but it would be slow also.

McAfee wrote an AV file scanner for Dos back in the dark ages called Scan.

Quote from: foxidrive on August 13, 2013, 07:00:39 AM

The best you could hope for is to have a virus definition database and then compare the files to look for the definitions

You'd need to open the files in binary mode, and you'd need something non-batch for that, and you might as well speed up the database operations with something designed for the job, and you need to download new definitions every so often (another compiled program), so you'd end up with a bunch of compiled programs being co-ordinated by a batch script, at which point it would become much more sensible to ditch the batch script.
Oh I see. Thank you for the help. I just enrolled in a C++ online school last week. I might do the AV stuff using C++ in the future...now I'm just learning the basics of C++.Not to scare you away from making an antivirus as a C++ project since maybe you could, but I have been working with C++ for the last 15 years as one of my choice computer languages to program in and I took in college ... Intro to C++, Intermediate C++, and Advanced C++.

As a beginner with C++ if you have never worked with programming in any other languages, I would suggest not just doing the course work assigned, but constantly explore and try to stay 1 chapter ahead of wherever the class is at and make small programs even if they are as simple as a conversion program, or text based game of some kind to exercise your mind and strengthen your skills.

In C++ as a beginner depending on what development tool you are using, your most likely going to start simple with console programming which is basically programs that when executed they run in a command shell window unless the course is jumping directly into programming for Windows using Visual Studio Express 2010 or 2012 etc.

A good suggestion for a project for C++ and not be in way over your head will be to make a video game, unless your skills with C++ are so well that you want something more challenging and want to take the risk of not having the project completed in time for the deadline at the end of the semester.

My final project for Intro to C++ was a game called SIC BO which is a gambling game. http://en.wikipedia.org/wiki/Sic_bo I decided to program this game for C++ because it was one of my favorite games at Casino's that host it. And it was more advanced than Blackjack or Poker with all the logic involved to make it work, and at the time there was no video game version of it for free on the internet.

For graphics it was all text based and the biggest challenge was squeezing all the information in the limited lines and width of a command shell in ASCII text into the viewable user console shell window, since the Intro C++ course pretty much covered the basics and the most advanced the course had gotten was passing values to arrays and Local and Global Variables as well as the many ways to structure the program within the different loop types since GOTO's will get you scolded as bad programming and myself coming from Basic to C++, I had to break the GOTO habit and force myself to place everything within loops.

Areas that were not taught as a part of Intro to C++ but I had to implement in my game were String Compare http://www.cplusplus.com/reference/string/string/compare/ and adding sound with beep function http://stackoverflow.com/questions/4060601/make-sounds-beep-with-c as well as reading and writing the game data to text file so that the game state could be saved and loaded back up vs always having to start the game fresh with these open/close read/write functions as example here: http://www.cplusplus.com/doc/tutorial/files/

Lastly, I would like to state that the hardest part of making an antivirus program is because you need a vast database of information to go by to detect if something is good from bad, and so while even if you did write an antivirus in C++, you still need a larger piece of the puzzle to make it work and the definitions are not open source to implement into your antivirus.

The fact of the matter is that probably the closest you can get to making an antivirus at the Intro to C++ level would be to make a C++ program that knows how a text file should be structured, and can detect differences between how it is and how it should be through comparison between two arrays with an incremental counter++ to compare for all text characters including spaces between what it should be and what it is, which would be more like a File Integrity Checksum Verification vs an antivirus, but only comparing ascii characters instead of going as advanced as to implement MD5 or SHA-1 hash values.

Quote
The File Checksum Integrity Verifier (FCIV) utility can generate MD5 or SHA-1 hash values for files to compare the values against a known good value. FCIV can compare hash values to make sure that the files have not been changed.

* I would suggest sticking to easier PROJECTS for the course and work on something like this on the side if your determined to make an antivirus.

Once a long time ago I tried to make my own AI using GW-Basic. I thought at 11 years old that it should be not too hard to program the computer to respond just as I would respond to questions. A couple weeks into the project and many many hours into it I soon realized that I could not account for every combination possible for every question that could have been asked and to populate my programming with every response that I would respond with. I also learned later on when getting into algorithms realized just how complicated AI is! http://en.wikipedia.org/wiki/Artificial_intelligence ... but for me I thought at 11 years old that I could make it happen with many many logic conditions IF this THEN that ELSE something else etc, and I soon realized it was beyond what I could program up myself as well as beyond what my computer could store since the amount of STORAGE needed was infinite to account for every question that could ever be asked and answred and even if I programmed it every second of my life, it still wouldnt be complete to be an exact copy of my mind in an AI form. *AND, the other problem was that the more I added in hard coded responses to questions the slower my program executed because later on I learned that FLAT linear logic is VERY SLOW when there are lots of data as for if you had a list of 200 responses to questions and a reponse was # 199 of the 200 that were programmed, it would have to test the input with that of the value of each IF statement before it got to #199 to find a match and THEN print to the display the predefined response. Real AI is best with a Database backbone in which instead of starting at the beginning of the database in search for the response the database such as mySQL could be used to display the response in less than a second similar to a search engine on the internet vs taking seconds, minutes, hours, or days to get to the correct response for the answer since it has to test every single piece of data until it finds the correct piece that is linked to the desired output reponse for the AI. So I gave up a long time ago on making my own AI and I leave it up to IBM with the Watson project http://www-03.ibm.com/innovation/us/watson/

As far as developement tools for C++ go. I have seen TEACHERS using Bloodshed Dev C++ as well as Visual Studio Express edition of C++ to instruct with. I have helped a number of people with C++ recently and this is what the teacher/professor's are using, however you should use whatever the teacher wants you to use to get the best support from the teacher.

When I learned C++ for the first time in 1998 the teacher suggested everyone who wanted to program and test there programs at home to buy Microsoft Visual C++ 6.0 Standard for $350. I didnt have that kind of money to spend and wanted to be able to debug my programs at home, and I got extremely lucky by accident in a mall to find a deal for Borland C++ 5.02 Programming Starter Kit for $8 on clearance at a Walden Book Store which also has Walden software in a clearance section and bought that instead. http://www.amazon.com/Borland-5-02-Programming-Starter-Kit/dp/1575955377

I ended up getting by very well with this Borland C++ 5.02 however there were some differences that I had to work around such as adding or removing the .h to #INCLUDE or #INCLUDE to get it to compile and not tell me that I had like 403 errors in the debugger.If one really wants to do a major project, you start at two opposing ends.

At one end is the "Top Down Approach" where you identify the scope of the problem and outline. a general specification. The other extreme is the "Bottom Up Approach" where you find the raw details of how hard parts of the problem must be resolved.
You an have two teams take each one of the methods. Later they compare notes to see if the project is feasible. If not, back to square one.

The point here is that you can spend too much time at one extreme or the other and not even get near the deadline. The team may discover specific solutions to problems that others had not found. Or they could just waste time re-inventing the wheel.
I like the team approach of deciding whether a concept is doable or a thorough waste of time...Quote from: DaveLembke on August 14, 2013, 06:11:52 PM
the hardest part of making an antivirus program is because you need a vast database of information to go by to detect if something is good from bad, and so while even if you did write an antivirus in C++, you still need a larger piece of the puzzle to make it work and the definitions are not open source to implement into your antivirus.

This is going to be the biggie - to create a viable antivirus application you would need to know a great deal about viruses, and the means to create and keep updated an up-to-date database of virus signatures; the coding is the least part of the task.




Thanks guys for all the replies. I don't think I'm going to do AV in C++....at least not in ten years . I'm just learning the very basics of C++ now with a book and online lessons. Also Dave thanks for your suggestions. I will take mental notes on your post.
Hey guys, I saw something on the internet, and it claims itself to be a batch antivirus.
http://sourceforge.net/projects/batchminiav/
Does it actually have the ability to REMOVE viruses?
thanks!It deletes files from the entire drive just because they are hidden. It does no checking to see if they are in fact malware.
It also states that it processes the root directory - but the /s subdirectory switch is in all the DEL commands.

Accordingly the batch file is suspect as an error this large should have been picked up if it was tested at all.
A process that should have been over in the blink of an eye would have taken quite a number of minutes, to recurse through the entire drive a number of times.


Code: [Select]OPTION6
CLS
ECHO [ 6 ]: Delete suspected hidden exe files
ECHO This deletes suspected hidden exe files in root directory
ECHO.
attrib -s -h C:\NTDETECT.COM
attrib -s -h C:\autoexec.bat
DEL /f /s /ah %_drive%*.exe
DEL /f /s /ah %_drive%*.com
DEL /f /s /ah %_drive%*.cmd
DEL /f /s /ah %_drive%*.bat
DEL /f /s /ah %_drive%*.vbs
DEL /f /s /ah %_drive%*.pif
DEL /f /s /ah %_drive%*.vmx
DEL /f /s /ah %windir%\autorun.inf
DEL /f /s /ah %windir%\system32\autorun.inf
Thank you foxidrive, I understand now.
7932.

Solve : Ordering cross-directories?

Answer»

Hi,
I need your help.
I want to iterate over directories and order all the files found by date.

I have used this command:

cmd /c dir " c:\nuovacartella " /b /s /A:-D /o:-d

but the files are ORDERED at folder level.

See the example:

C:\&GT;cmd /c dir "c:\nuovacartella" /b /s /A:-D /tc /o:d
c:\nuovacartella\cartella file\uno.txt
c:\nuovacartella\cartella file\AAA\ciao.txt
c:\nuovacartella\cartella file\AAA\due.doc
c:\nuovacartella\cartella file\AAA\tre.xsl
c:\nuovacartella\cartella file\AAA\appenaCreato.rar
c:\nuovacartella\cartella file\BBB\B2\son UN file.txt
c:\nuovacartella\cartella Link\son un file
c:\nuovacartella\cartella Link\uno
c:\nuovacartella\cartella Link\appenaCreato
c:\nuovacartella\cartella Link\ciao

C:\>cmd /c dir "c:\nuovacartella" /b /s /A:-D /tc /o:-d
c:\nuovacartella\cartella file\uno.txt
c:\nuovacartella\cartella file\AAA\appenaCreato.rar
c:\nuovacartella\cartella file\AAA\tre.xsl
c:\nuovacartella\cartella file\AAA\due.doc
c:\nuovacartella\cartella file\AAA\ciao.txt
c:\nuovacartella\cartella file\BBB\B2\son un file.txt
c:\nuovacartella\cartella Link\ciao
c:\nuovacartella\cartella Link\appenaCreato
c:\nuovacartella\cartella Link\uno
c:\nuovacartella\cartella Link\son un file

but I want the files ordered cross-folder.
Is there a way to do this (for example, using a batch script)?

Thanks in advance. Leonardo



This writes some TMP files and file4.tmp is the sorted file.

Code: [SELECT]@echo off
del file?.tmp 2>nul
dir "c:\nuovacartella" /b /s /A:-D /tc /o:d >file.tmp
for /f "delims=" %%a in (file.tmp) do >> file2.tmp echo %%~nxa?%%~dpa
sort <file2.tmp >file3.tmp
for /f "tokens=1,2 delims=?" %%a in (file3.tmp) do >> file4.tmp echo %%b%%a

7933.

Solve : Adding a log file Batch Files?

Answer»

I want to add a log file to existing batch file/s. My goal is to ensure the user/s are running their files by creating a log with the DATE/TIME STAMP.

Secondary, I code the Echo off but can still see all the files in copies or deletes what am I forgetting to do? :-/ It's been 15 years since I've had to worry about batch files. Thank you!This will work on NT machines only:

echo %username% %0 %date% %time% >> logfile.log

Echo is for batch file statements and whether they get sent back to the screen. Echo has no control over messages ISSUED by individual programs or commands.

Hope this HELPS.

7934.

Solve : Batch file to remove files in roaming folder for al users (Win 7) ??

Answer»

How to make batch file that removes all files (no folders and no files in folders) in the Roaming Profile for all users ?

This does not work:
del c:\users\*\AppData\Roaming\*.*
del c:\users\%%\AppData\Roaming\*.*
del c:\users\%\AppData\Roaming\*.*

Help ?!PROBABLY because the roaming profile folder is a Win system protected folder and you risk buggering Windows by removing it...
Just curious...why would you WANT to remove it ? ?

I dont want to remove the folder, nor the subfolders in it !

But I want to remove files in the folder !

Thats because lately the UCASH virus adds one or two files in that folder.
And I want to have a tool to remove them easily ...

Well i'm not GOING to be the one to DISCOURAGE you but i will state that a manual method of infection removals is hardly the right way to go about it.In Windows 8 this folder does not have a roaming folder. "c:\Users\All Users\"

And in Windows 7 I see this: no roaming folder either.


C:\Users\All Users>dir /a
Volume in drive C has no label.
Volume Serial Number is FC8D-EAAB

Directory of C:\Users\All Users

07/14/2009 03:53 PM <DIR> .
07/14/2009 03:53 PM <DIR> ..
07/14/2009 03:53 PM <JUNCTION> Application Data [C:\ProgramData]
07/14/2009 03:53 PM <JUNCTION> Desktop [C:\Users\Public\Desktop]
07/14/2009 03:53 PM <JUNCTION> Documents [C:\Users\Public\Documents]
07/14/2009 03:53 PM <JUNCTION> Favorites [C:\Users\Public\Favorites]
01/26/2013 11:04 PM <DIR> Microsoft
07/14/2009 03:53 PM <JUNCTION> Start Menu [C:\ProgramData\Microsoft\Windows\Start Menu]
07/14/2009 03:53 PM <JUNCTION> Templates [C:\ProgramData\Microsoft\Windows\Templates]
0 File(s) 0 bytes

C:\Users\All Users\Application Data>dir /a
Volume in drive C has no label.
Volume Serial Number is FC8D-EAAB

Directory of C:\Users\All Users\Application Data

File Not Found
It's there in both versions...Do you have a DIR output with it in?

My file manager in Windows 8 doesn't show it, and DIR in Windows 7 doesn't show it.

Show hidden files and folders...dir /a does show hidden files and folders.To be clear - there is a roaming folder in other profiles, but not in the All Users profile.


I think now that I misread the first post - he wants all user profiles processed and not the "All users" profile processed. That's going to do a spitload of damage!That was my point...%appdata% is the path to appdata\roaming (at least on windows 7).

Code: [Select]
C:\Users\Lemonilla>cd %appdata%

C:\Users\Lemonilla\AppData\Roaming>


don't know if that helps much, but it might.Until he answers why he wants to do this i think we should hold off on suggestions...as i cannot see any good coming from this exercise ...

7935.

Solve : Open A specified File if a now > Certain File's Modified stamp?

Answer»

Hi

I am rather shamelessly requesting a batch file to do the following -

I have an executable file 'XYZ.exe' that can be accessed by multiple users over a LAN system. It seems that when this file is opened, it creates a clone of itself to a file with another name with .TMP extension and then the Rxyz.tmp file is destroyed and the executable opens. All this takes a fraction of a second. If, however, another user in the LAN attempts to open 'XYZ.exe' before this conversion re-conversion process is complete, the executable 'XYZ.exe' gets left with the .tmp extension and is essentially corrupted showing 0B.

To circumvent this (workaround), the user could be asked to click on the batch file I am requesting instead of on the executable 'XYZ.exe'.

The batch file will reside in the same folder as 'XYZ.exe'.
When opened, it should ..
1. Check for text file 'CheckTime.txt' in the same folder
2. If not existing, it should create it and immediately open the file 'XYZ.exe'
3. If 'CheckTime.txt' is found to be already existing, then the date+time modified should be compared with now and if, say, 6 seconds have not elapsed, the batch should wait until 6 seconds after 'CheckTime.txt' was last modified and then open 'XYZ.exe'
4. Batch file closes, LEAVING only the opened 'XYZ.exe'

The above may be RELATIVELY easy. The twist is ---what if a third user tries to open 'XYZ.exe' via this batch at around the same time?

Any help would be appreciated.

Regards
Look into the commands
attrib
set /p _=<_
goto :_
start
The file XYZ.exe - is that a compiled batch file?Quote from: foxidrive on September 30, 2013, 05:54:05 PM

The file XYZ.exe - is that a compiled batch file?

No, it is a third party software.If the users launch this then it could be all you need.

Code: [Select]@echo off
:loop
If exist Rxyz.tmp echo waiting & timeout 1 & :goto loop
start "" xyz.exe
Another possible solution is to create a unique random folder, copy xyz.exe into it and launch it. Delete the file and folder when it is done.
Everyone would get a separate copy.Quote from: foxidrive on October 01, 2013, 12:00:45 AM
If the users launch this then it could be all you need.

Code: [Select]@echo off
:loop
If exist Rxyz.tmp echo waiting & timeout 1 & :goto loop
start "" xyz.exe

Thank you, makes sense but the .tmp file name is not always consistent. Therefore, either *.tmp or R*.tmp or ??.tmp if I was sure about the temp file name's length or the original request for a batch file.

Also, please confirm that if say, there are 5 PCS on the LAN and more than one user clicks on the short-cut to the new batch file at practically the same time, the batch file will do the needful?Quote from: jds on October 01, 2013, 12:09:20 AM
Thank you, makes sense but the .tmp file name is not always consistent. Therefore, either *.tmp or R*.tmp or ??.tmp if I was sure about the temp file name's length or the original request for a batch file.

You could use *.tmp if there are no other tmp files in the folder.

Quote from:
Also, please confirm that if say, there are 5 PCS on the LAN and more than one user clicks on the short-cut to the new batch file at practically the same time, the batch file will do the needful?

There is a one second delay. In that time frame there could be a clash with multiple users.

The other suggestion I made would solve that for any number of users, if the file can be executed in another folder.Quote from: foxidrive on October 01, 2013, 08:32:33 AM

The other suggestion I made would solve that for any number of users, if the file can be executed in another folder.

While trying to find a solution by code such as requested here, the workaround I use is to have the executable itself saved with different names -
'XYZ.exe', "XYZ1.exe', 'XYZ2.exe' etc. and have different computer's short-cuts point to unique software executables. But this is a workaround. Would dearly like to find a code solution to this problem.In that case it's a little simpler. This is meant to

A) generate a random number,
B) copy the XYZ executable to that new name and launch it,
C) wait until the program is closed and then delete the temporary copy.

A drawback is that an extra cmd window will be on the desktop while the XYZ program is active.

Code: [Select]@echo off
:loop
set "num=xyz-temp-%random%%random%%random%.exe"
If exist "%num%" goto :loop
copy "xyz.exe" "%num%" >nul
echo This window will automatically close when XYZ is ended - don't close it manually.
start "" /w "%num%"
del "%num%"

One workaround for the cmd window is to launch the files normally - and in a scheduled task remove all the temporary executables once a day.

Code: [Select]@echo off
:loop
set "num=xyz-temp-%random%%random%%random%.exe"
If exist "%num%" goto :loop
copy "xyz.exe" "%num%" >nul
start "" "%num%"

This batch file will remove all the temporary executables.

Code: [Select]@echo off
del "d:\folder\xyz-temp-*"
Quote from: foxidrive on October 01, 2013, 09:26:37 AM
In that case it's a little simpler. This is meant to

A) generate a random number,
B) copy the XYZ executable to that new name and launch it,
C) wait until the program is closed and then delete the temporary copy.

A drawback is that an extra cmd window will be on the desktop while the XYZ program is active.


One workaround for the cmd window is to launch the files normally - and in a scheduled task remove all the temporary executables once a day.


This batch file will remove all the temporary executables.

Code: [Select]@echo off
del "d:\folder\xyz-temp-*"


Not sure if Solution #1 will work when USED by multiple users at the same time (beside being ugly).
With Solution #2, can it be modified to remove previously created temporary exes whenever the batch file is run from any LAN PC? Sort of checking for temp files and if they are not open to delete them.

The question still not answered adequately is, "Will the batch file code work when executed by more than one user at precisely the same time?" Say PC1 executes 'openfile.bat' and at the same time user on PC2 double-clicks the short-cut to 'openfile.bat' - it nothing happens (as in nothing adverse) when PC2 user double-clicks, it is OK with me. He will simply try again after a few seconds thinking that he has not double-clicked properly.

Solution #3 ??
Is there any code that can execute this way -
When the 'Openfile.bat' file is executed, a run on time (now+2 seconds = x) is executed to open 'XYZ.exe' at time x and 'Openfile.bat' closes.

If 'Openfile.bat' is accessed again, it fetches x and executes a run on time command (now + 2 seconds or x+2 seconds, whichever is later) and 'Openfile.bat' closes. I imagine that 'Openfile.bat' will open, run and close in milliseconds, even over a LAN.

In this way there is a pre-defined settable minimum interval between the open attempts of 'XYZ.exe'
7936.

Solve : Need to run the program "extract75" from?

Answer»

I have a program that parses NITF files in order to extract the metadata into SEPARATE text files. The PROBLEM is that I need to run the program on about a zillion files in order to set up a database of the output info.
The GUI for the program prompts the user for certain parameters (using radio buttons) and has text boxes for the input and output files. How do I run the program from within the BAT file? What SYNTAX do I use to set the parameters?
I could find any info on your extract75 program. But I did find 3½ million herbal REMEDIES going by that NAME. I don't suppose they're intechangeable? Anyway, you need to find out if in fact the program can be run at the command line and what run time parameters are needed. The GUI help may help you with that info.

After that, you need to build a FOR loop in a batch file to process all zillion files.

Let us know.

7937.

Solve : how to run the application on the command prompt?

Answer»

Hi,

IAM runnign an VB application( an installable that is installed on the MACHINE) .I invoke the application by going through the start menu->program files->application.what i NEED is i want to run the application from the command prompt.

if i goto the program file->run and type the exe of the application, the application is got invoked.

can any of you please LET me know hw to run the application from the command prompt.

thanks in advance

sathishHow was it written:?>http://www.softinterface.com/What_Is_CL.HTM

7938.

Solve : DOS OPERATING SYSTEM?

Answer»

I WANT a DOS OPERATING SYSTEM that is on a floppyhttp://www.freedos.org/

7939.

Solve : dos partitions?

Answer»

I am putting windows 98 on this computer and booted from the win 98 boot disk, went into fdisk to create dos partitions and forgot to delete the ntfs partition that was already there so my c drive ended up with 8mb. I then deleted the ntfs partition which had all the hard drive space and tried to delete the small dos partition I made but it keeps telling me i'm not ENTERING the right volume number. So I made an EXTENDED dos partition with the space from the ntfs drive i deleted and was hoping I could make it the the C drive but I have no idea how to do it. I WOULD like to just erase everything but dont know how. help gparted is a linux tool that may help you remove it all.

http://gparted.sourceforge.net/I went back into it after I made the first post LAST night and managed to delete the problem partitions, created 1 large partition and loaded windows 98 with no problem.

7940.

Solve : batch script to search file better or close to window search?

Answer»

Try removing "@echo off" and opening it from command prompt and POSTING what it shows here.
(EASY way to do this is Rightclick->Mark->ArrowKeys+Shift->Enter)
K:\PC\powershell 2.0\bat.bat\buat BATCH>if not defined token (
echo Search for what string?
set /p token=>
echo.
)
Search for what string?
>masa


K:\PC\powershell 2.0\bat.bat\buat batch>set a=0

K:\PC\powershell 2.0\bat.bat\buat batch>for /F "delims=" %A in ('dir /b | find "
masa"') do (
set /a a+=1
echo !a!. %A
echo !a!. %A 1>>log
)

K:\PC\powershell 2.0\bat.bat\buat batch>(
set /a a+=1
echo !a!. masa 3 saat.txt
echo !a!. masa 3 saat.txt 1>>log
)
1. masa 3 saat.txt

K:\PC\powershell 2.0\bat.bat\buat batch>(
set /a a+=1
echo !a!. masa dlm saat.txt
echo !a!. masa dlm saat.txt 1>>log
)
2. masa dlm saat.txt

K:\PC\powershell 2.0\bat.bat\buat batch>echo.


K:\PC\powershell 2.0\bat.bat\buat batch>echo Enter number of file to open.
Enter number of file to open.

K:\PC\powershell 2.0\bat.bat\buat batch>set /p op=>
>1

K:\PC\powershell 2.0\bat.bat\buat batch>for /F "tokens=1,2,3 delims=." %A in (lo
g) do (if %A EQU 1 start %B )

K:\PC\powershell 2.0\bat.bat\buat batch>(if 1 EQU 1 start masa 3 saat )should be:
tokens=1,2
not
tokens=1,2,3

OR you can change "%%B to %%B.%%C"Quote from: Lemonilla on October 01, 2013, 05:17:56 AM

should be:
tokens=1,2
not
tokens=1,2,3

OR you can change "%%B to %%B.%%C"

thank you

i try tokens=1,2,3 because batch not read file TYPE example ".txt"

i forgot add %%C on %%B can solve the problem

now batch work perfectly...thank you x10000000000
7941.

Solve : Dice Rolling?

Answer»

Hi there, another newbie here. I'm trying to make a batch file rpg using notepad. My game needs combat so I need to simulate 2D6 being rolled and adding any modifier. The results need to be as random as possible each time its run.

Any help will be gratefully received, feel free to email me at [removed to prevent spam]

Let the game begin.

Ron.To do the random number, you just use the %random% variable which will generate a number between 0 and 32768. Since you want it in the range of 1-6, you'd do something like this:

Code: [Select]Set /a DieA = %random% * 6 / 32768 + 1
Set /a DieB = %random% * 6 / 32768 + 1
Echo %DieA% - %DieB%

Personally I've found this to not be too random, but it's the best I've found so FAR ANYWAY. I used this in a Russian Rulette game I made, so I know it works.

Also, I would recommend using Notepad++ for your scripting rather than Windos' Notepad.exe. Notepad++ has SYNTAX highlighting for BAT so it makes it a lot easier to keep track of your script as you're writing it.

As a LAS note, you may consider moving this thread to the programming board as you'll probably get the best advice there.If you are going with the cmd internal random system, then you can either round off your number manually, using
Code: [Select]set /a num=%random%*(upper-lower+1)/32768+loweror using modulo, which does the same thing, but more readable, and without relying on the size of %random%'s possible input
Code: [Select]set /a num=%random% %% (upper-lower+1) + lower
if you want to make the random number yourself then there are a bunch of methods you can use, the first is with a linear function:
Code: [Select]newseed=(multiplier*oldseed+constant) %% moduluswhich is fairly effective, in fact I think that that is how the ms-dos random works anyway, although this method is usually done with really big numbers using hardware, so that it is efficient yet unpredictable.
modulus represents the range of your numbers, so if you were to remake the %random% system, the modulus would be 32767, but note that this method can and will output a zero.
you would be best off dealing with a large modulus and using the %random% method with the output, this probably means that %random% would be a whole lot simpler.

Another simple and effective random system is the middlesquare method, but its not really possible to use without planning its sequence of outputs.
In this method you just take your previous number, square it, and take out the middle digits that would reduce the numbers size to match the seed.
eg.
seed: 12345
12345 squared: 152399025
the middle 5 digits of 152399025: 23990
new seed: 23990

and so on and so forth, but the problem is that some sets are just ineffective, for example, 2500 points to an output of 2500, and therefore any other number that will eventually give you 2500 will loop forever, you can increase the output by one if it would otherwise equal the original, and repeat until you FIND a unique number, but then there will be loops of numbers that are too short to use, so overall this method requires a lot of handling to use in batch, but I did make a script that middlesquares numbers for you, so it is possible.

Have fun, and good luck!

7942.

Solve : once compressed, redirect compressed file to another command line?

Answer»

Hi,

under windows 7, i created a bat file including several command lines.

my first command line compress a folder (using 7-zip) to a tar file (this works great)
my second command line should:
a. wait that folder is compressed to a file
b. take the compressed file (content of compressed folder) and inject it / redirect it to a command line (this new command line should compress to gzip format)

my main problem it's :
1. i don't know how to tell 2nd commandline to wait till folder is FINALLY compressed.
2. how to redirect (without typing the filename of compressed folder) the new compressed archive to new command line ?

i tried to understand how <& works but i'm not sure this is what i need

could you help me please ?
thxFirst you need to show the actual code you created.

One question. Why are you compressing twice?
Because unfortunatelly 7-zip doesn't allow to CREATE a tar.gzip file in 1 shot... and i need to create such file extension...not only tar, not only gzip but like under linux...tar.gzipDid you see the first part of my post?
You could CALL 7-zip using START /WAIT or you could use the free IZarcCC which does it all at once (well, it creates the tar and then gzips it but you only use one command)

Installer http://www.izarc.org/download/IZArcCL.exe

Website http://www.izarc.org/index.html

(This is the "Command Line Add-on" I am using.)

Auto-it is a folder containing a mixture of text files and .exe files total 4,796,368 bytes

C:\test>"C:\Program Files (x86)\IZArc\IZARCC.exe" -a -r -cx "C:\Archives\Auto-it.tgz" Auto-it

-cx is max compression

01/04/2013 20:47 3,429,444 Auto-it.tgz

Can just make a tar file:

C:\test>"C:\Program Files (x86)\IZArc\IZARCC.exe" -a -r "C:\Archives\Auto-it.tar" Auto-it

01/04/2013 20:50 4,843,520 Auto-it.tar

It needs the full PATH for the archive file or else it makes it in the program folder. Note the program path will be different on 32 bit Windows. You can change the .tgz extension afterwards. If you supply .tar.gz on the command line when running it makes filename.tar.tgz






I have learned from past experience that some programs just dont obey the wait option.
Batch files are sequential. Dont use the start command to run 7zip. Quote from: Squashman on April 01, 2013, 02:06:05 PM

I have learned from past experience that some programs just dont obey the wait option.
Batch files are sequential. Dont use the start command to run zip.

Command line exectutables don't need the start command. Anyhow, from a batch file he should be using the 7-Zip command line executable, 7za.exe. This returns only when the compression/archiving task is done. It's at 7-zip.org.

personally i already use auto-it and even if it is a good software, i agree that some applications do not respond to wait...
but more than that i don't want to use any artefact or extra software for that...i know because i already saw it on web that it is possible without that solution.

for example my first command like could be:
"c:\Program Files\7-Zip\7z.exe" a -r -mx9 -ttar my_archive my_folder_to_compress/*.*

and the 2nd command line should be in this case:
"c:\Program Files\7-Zip\7z.exe" a -r -mx9 -tgzip my_archive my_archive.tar
Auto-it is just an example folder I used.

I don't think you understood what I wrote.

If you don't want to use "extra software", why are you using 7-zip?

Why don't you use the 7-zip command line version 7za.exe? This would avoid all your problems.

Is English not your first language? (LA langue des rosbifs n'est pas ta langue maternelle ?)



I use 7z.exe and it works to pass the command to the archiver and wait for the file to be created.

This should work.

Code: [Select]@echo off
set "file=My_Archive"
"c:\Program Files\7-Zip\7z.exe" a -r -mx9 -ttar "%file%.tar" "my_folder_to_compress\*"
"c:\Program Files\7-Zip\7z.exe" a -r -mx9 -tgzip "%file%.tgz" "%file%.tar"Quote from: foxidrive on April 01, 2013, 03:45:16 PM
This should work.

This did work, both in a batch (7-zip did not return until each task was complete) and also when entered at the prompt...

Note: my Windows is 64 bit, so it installs 32 bit programs under C:\Program Files (x86)\. On a 32 bit system the install will be under C:\Program Files\

U:\Pan2>dir doctest
Volume in drive U is USB-U
Volume Serial Number is 70B2-B275

Directory of U:\Pan2\doctest

02/04/2013 18:53 <DIR> .
02/04/2013 18:53 <DIR> ..
14/02/2003 11:17 11,776 aseptic01.doc
14/02/2003 11:17 11,776 aseptic02.doc
14/02/2003 11:17 11,776 aseptic03.doc
14/02/2003 11:17 11,776 aseptic04.doc
14/02/2003 11:17 11,776 aseptic05.doc
14/02/2003 11:17 11,776 aseptic06.doc
14/02/2003 11:17 11,776 aseptic07.doc
14/02/2003 11:17 11,776 aseptic08.doc
14/02/2003 11:17 11,776 aseptic09.doc
14/02/2003 11:17 11,776 aseptic10.doc
10 File(s) 117,760 bytes
2 Dir(s) 318,992,576,512 bytes free


U:\Pan2>"C:\Program Files (x86)\7-Zip\7z.exe" a -r -mx9 -ttar "Doctest.tar" "Doctest\*"

7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
Scanning

Creating archive Doctest.tar

Compressing Doctest\aseptic01.doc
Compressing Doctest\aseptic02.doc
Compressing Doctest\aseptic03.doc
Compressing Doctest\aseptic04.doc
Compressing Doctest\aseptic05.doc
Compressing Doctest\aseptic06.doc
Compressing Doctest\aseptic07.doc
Compressing Doctest\aseptic08.doc
Compressing Doctest\aseptic09.doc
Compressing Doctest\aseptic10.doc

Everything is Ok

U:\Pan2>"C:\Program Files (x86)\7-Zip\7z.exe" a -r -mx9 -tgzip "Doctest.tgz" "Doctest.tar"

7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
Scanning

Creating archive Doctest.tgz

Compressing Doctest.tar

Everything is Ok

U:\Pan2>dir doctest*
Volume in drive U is USB-U
Volume Serial Number is 70B2-B275

Directory of U:\Pan2

02/04/2013 18:53 <DIR> Doctest
02/04/2013 18:54 123,904 Doctest.tar
02/04/2013 18:55 2,654 Doctest.tgz
2 File(s) 126,558 bytes
1 Dir(s) 318,992,576,512 bytes free

7943.

Solve : Need help with a .cmd file, pretty please!?

Answer»

To save petty details, here is what I am currently using
Keep in MIND the listed code works perfectly on its own when I EDIT the file with a specific directory.

Quote

-Fileremover.cmd-

takeown /F "whatever directory I want" /r /d y
icacls "whatever directory I want" /grant administrators:F /t
call cleanit.cmd

Quote
-cleanit.cmd-

rd /s /q "whatever directory I want"

I am trying to figure out a way to either
A: have the cmd promt me to input the directory to execute the takeown, or
B:use a bat/cmd file to replace a designated directory with a directory specified on the command prompt window inside a CREATED copy or a cmd file.

so for example,
COPY C:\test.txt test2.txt
COPY C:\cleanit.cmd cleanit2.cmd
then have it replace "whatever directory I want" with something I enter into the cmd prompt

afterwards of course have them run then get deleted through some means, which I can do. It is just the input I am having trouble with, I searched high and low as well as tried a few switches and different lines.

I would be happy to even learn some scripting if needed. I just want this to be successful. Thank you for reading and your responses
If this does not make sense I am more than happy to try and clarify. Code: [Select]set /p fpath=Enter in the full path to a directory:
takeown /f "%fpath%" /r /d yThanks Squashman, that actually did the trick, sadly I guess i'll have to input it twice, once for the remover and once for the cleanit.
Either way fantastic job! I greatly appreciate it.Why do you have the CleanIt as a separate batch file? Why not have all the code in one batch file?

And no you would not have to do it twice. You can pass command line arguments to a batch when you start a batch file or call a batch file.

Code: [Select]call cleanit.cmd "%fpath%"Code: [Select]rd /s /q "%~1"
With such simple and basic code I would just combine these two batch files into one.

I was thinking about that actually, I have only starting delving into DOS (Specifically 5.0), and cmd promt so im still in my infancy. I actually figured out I didn't have to re specify it, which did make me happy!
either way it's a decent makeshift virus remover (or at least for what I was trying to get rid of) just wanted to make it more user friendly.

I think I will take your advice though and combine them!So I ended up keeping it in two separate files but thanks to you, this is my end result.

Quote
Fileremover.cmd

set /p fpath=Enter in the full path to a directory:
takeown /f "%fpath%" /r /d y
pause
icacls "%fpath%" /grant administrators:F /t
pause
call cleanit.cmd

Quote
cleanit.cmd

rd /s /q "%fpath%"
pause
@ECHO OFF

:choice
set /P c=If file is still present, would you like to try a GOOGLE search?[Y/N]?
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice


:somewhere

echo "Opening up www.google.com"
start www.google.com
echo "Hope you find a way to REMOVE your piece of data!"
pause
exit

:somewhere_else

echo "Huzzah! You win, you awesome person you "
pause
exit

Thanks again Squashman.
7944.

Solve : TCP and batch?

Answer»

Hey all, this would be my first post to this forum.
I have been looking for a while to see if there is any way to deal with TCP/IP through BATCH files, I don't completely understand networking, so I'm looking at this as a learning experience in terms of networking as well as batch-network communication, assuming that it is... possible?
Yeah, thanks What d'ya want to do in batch? You can copy THINGS across a network - that uses TCP/IP in most cases.Well the ultimate goal is an IRC bot, I've seen in haskell, a lazy, functional programming language, the IRC server was read as if it was a text document, which makes sense CUZ IRC seperates with a CRLF
so is it possible to read server files in that way, or whatever I'm actually looking for...Still makes no sense...
IRC is all text...Hmm? Yeah the haskell bot read through the IRC data by opening a file which represented the text data or something... I guess, and if that method is possible with batch, then I already have all of the scripts that I need to deal with that data once I have it, I just have no idea how to get there, so I'm starting by trying to understand TCPQuote from: spivee on September 29, 2013, 08:59:24 AM

Well the ultimate goal is an IRC bot

That's not something I would consider trying to achieve in batch. Use a High Level Language (HLL) to write it in.But the goal isn't to create an IRC bot, the goal is to become comfortable with any such networking capabilities available in batch. I'm aware of how I can make an IRC bot in haskel and I could find a tutorial for C++ fairly easily, but again, that isn't the goal.Quote from: spivee on September 29, 2013, 08:59:24 AM
Well the ultimate goal is an IRC bot

Quote from: spivee on September 29, 2013, 09:08:04 PM
But the goal isn't to create an IRC bot

Are you sure? That first context was TAKEN out of context, my ultimate goal is to make an irc bot in batch, ergo the goal wasn't to make an irc bot in general. Sorry for the AMBIGUITY... and the contradiction that followed
7945.

Solve : CD's?

Answer»

I was wondering:

Is there any way to burn FILES to a CD? Is there already a command, or is there a .BAT file I could write?In XP, there is a DIRECTORY C:\Documents and Settings\%UserName%\Local Settings\Application Data\Microsoft\CD BURNING\ where you can stage your files. XP will POP up a balloon. Click the balloon and you can copy the files to a CD.

You may also be able to script your CD burning software.

Hope this HELPS.

7946.

Solve : Help in deleting a lot of dodgy files in my C driv?

Answer»

I have about 20 files in my C: drive CALLED ÷ they are 400Kb in size and when I go to delete them it tells me Cannot read from source file or disk.

They are not doing anything as done virus check and spyware scan, which are all kept up to date, and nothing is showing up. All they seem to be doing is taking up valuable space on the C: drive

Any ideas how I can get rid of them??

Force delete? Type the delete command, then the pathname, stating with "C:\" If you've already tried this, just say so. Have you tried opening the files to see what they are? Or are you worried that this might trigger viruses?They are just in my c: drive outwith other folders. Am worried that I might delete everything if i do C:> Del *.*Oh, and cant open them, when i DOUBLE click it automatically opens the " Open With" option.Type DEL, then C:\ then the filename. That should delete the file, but nothing else.The file name is just a divide sign, dont know how to type that in DOS, any ideas?What do the files properties show? Do they belong to any recognizable application?When I RIGHT click and properties it shows no name szie 0 bites and space on disk 0 bites.Try highlighting the files, hold down the shift key, and PRESS delete.Dont know if it helps but this is what I'm getting

http://i9.photobucket.com/albums/a51/weefatbob/image001.pngDid the shift-delete not WORK?Nope, didnt manage to *censored* it with that.Open a new folder and drag all of them into it.....or use the left side of the mouse highlight them and send them to the bin......or use system mechanic from iolo....Weird?
Try del c:\Alt + 246.* (Number pad)

7947.

Solve : DOS Hot Keys?

Answer»

Does ANYONE remember the key(s) used to repeat a DOS COMMAND at the Dos Prompt? ie if you typed PING URL, and then wanted to repeat it again, there was a key or combination of keys that would bring the command up again.

ThanksF3

7948.

Solve : Append one line in Batch File?

Answer»

hi
I have 2 different problem
1. How to append one line in existing Text file through one batch PROGRAMMING in MS-DOS/WINDOWS.
2. How to logon server without giving the username and password through Batch Programming in the above mentioned platform.
Thanks & Regards
Rishi,INDIAFOR #1 use the >> symbol to append data to a file.

Code: [Select]
ECHO text >> file.ext


#2 I don't really understand. You can pump signon information into a login SCRIPT by redirecting the information.

Code: [Select]
echo name > signon.dat
echo pswd >> signon.dat
loginscript < signon.dat


Hope this helps.

7949.

Solve : doskey redirect not working?

Answer»

So I was messing around with doskey, and came up with the idea of making a macro that would open the /? text in notepad, as it is often to long to read on cmd.exe. The problem I've run into is that it doesn't seem to like redirecting the output. Here's what I have so far.

Code: [Select]doskey note=$* 1>tmp.txt 2>&1 $T notepad tmp.txt

output: (cmd)
Code: [Select]
C:\Users\Lemonilla>note help
For more information on a specific command, type HELP command-name
ASSOC Displays or modifies file extension associations.
ATTRIB Displays or changes file attributes.
BREAK Sets or clears extended CTRL+C checking.
BCDEDIT Sets properties in boot database to control boot loading.
CACLS Displays or modifies ACCESS control lists (ACLs) of files.
CALL Calls one batch program from another.
CD Displays the name of or changes the current directory.
CHCP Displays or sets the active code page number.
CHDIR Displays the name of or changes the current directory.
CHKDSK Checks a disk and displays a status report.
CHKNTFS Displays or modifies the checking of disk at boot time.
CLS Clears the screen.
CMD Starts a new instance of the Windows command interpreter.
COLOR Sets the default console foreground and background colors.
COMP Compares the contents of two files or sets of files.
COMPACT Displays or alters the compression of files on NTFS partitions.
CONVERT Converts FAT volumes to NTFS. You cannot convert the
current drive.
COPY Copies one or more files to another location.
DATE Displays or sets the date.
DEL Deletes one or more files.
DIR Displays a list of files and subdirectories in a directory.
DISKCOMP Compares the contents of two floppy disks.
DISKCOPY Copies the contents of one floppy disk to another.
DISKPART Displays or configures Disk Partition properties.
DOSKEY Edits command lines, RECALLS Windows commands, and
creates macros.
DRIVERQUERY Displays current device driver status and properties.
ECHO Displays messages, or turns command echoing on or off.
ENDLOCAL Ends localization of environment changes in a batch file.
ERASE Deletes one or more files.
EXIT Quits the CMD.EXE program (command interpreter).
FC Compares two files or sets of files, and displays the
differences between them.
FIND Searches for a text string in a file or files.
FINDSTR Searches for strings in files.
FOR Runs a specified command for each file in a set of files.
FORMAT Formats a disk for use with Windows.
FSUTIL Displays or configures the file system properties.
FTYPE Displays or modifies file types used in file extension
associations.
GOTO Directs the Windows command interpreter to a labeled line in
a batch program.
GPRESULT Displays Group Policy information for machine or user.
GRAFTABL Enables Windows to display an extended character set in
graphics mode.
HELP Provides Help information for Windows commands.
ICACLS Display, modify, backup, or restore ACLs for files and
directories.
IF Performs conditional processing in batch programs.
LABEL Creates, changes, or deletes the volume label of a disk.
MD Creates a directory.
MKDIR Creates a directory.
MKLINK Creates Symbolic Links and Hard Links
MODE Configures a system device.
MORE Displays output one screen at a time.
MOVE Moves one or more files from one directory to another
directory.
OPENFILES Displays files opened by remote users for a file share.
PATH Displays or sets a search path for executable files.
PAUSE Suspends processing of a batch file and displays a message.
POPD Restores the previous value of the current directory saved by
PUSHD.
PRINT Prints a text file.
PROMPT Changes the Windows command prompt.
PUSHD Saves the current directory then changes it.
RD Removes a directory.
RECOVER Recovers readable information from a bad or defective disk.
REM Records comments (remarks) in batch files or CONFIG.SYS.
REN Renames a file or files.
RENAME Renames a file or files.
REPLACE Replaces files.
RMDIR Removes a directory.
ROBOCOPY Advanced utility to copy files and directory trees
SET Displays, sets, or removes Windows environment variables.
SETLOCAL Begins localization of environment changes in a batch file.
SC Displays or configures services (background processes).
SCHTASKS Schedules commands and programs to run on a computer.
SHIFT Shifts the position of replaceable parameters in batch files.
SHUTDOWN Allows proper local or remote shutdown of machine.
SORT Sorts input.
START Starts a separate window to run a specified program or command.
SUBST Associates a path with a drive letter.
SYSTEMINFO Displays machine specific properties and configuration.
TASKLIST Displays all currently running tasks including services.
TASKKILL Kill or stop a running process or application.
TIME Displays or sets the system time.
TITLE Sets the window title for a CMD.EXE session.
TREE Graphically displays the directory structure of a drive or
path.
TYPE Displays the contents of a text file.
VER Displays the Windows version.
VERIFY Tells Windows whether to verify that your files are written
correctly to a disk.
VOL Displays a disk volume label and serial number.
XCOPY Copies files and directory trees.
WMIC Displays WMI information inside interactive command shell.

For more information on tools see the command-line reference in the online help.


C:\Users\Lemonilla>

output: (notepad)
Code: [Select]

So from what I understand it is not performing 1>tmp.txt 2>&1 and allowing notepad to create tmp.txt. Any assistance would be great.You can adjust the pages and buffers in CMD.EXE properties which will allow you to scroll up and down in the history and read all the help.

Or use this batch file: call it H.BAT and launch it like this

H IF
H MORE
H CMD
H DIR

@echo off
%1 /? >"%temp%\helptext.tmp.txt"
start "" notepad "%temp%\helptext.tmp.txt"

It's untested.Lemonilla,
Can you try the top down method?
Tell in plain English what you want to do without using symbols or code. Then somebody can show you possible code samples s using available Windows tools suitable to the job.
Note Pad is not well suited for command line tasks. Instead, Windows has some advanced command line features that are way BEYOND DOS. It is called Power Shell. Presently Power Shell is what Microsoft recommends for command line operations with extended usability. DONKEY is not a part of it.
Here is a video about Power Shell.
http://www.youtube.com/watch?v=qv0ZpVfKiRs

This was mainly for CONVENIENCE sake. I find it difficult to read the help menus on the small cmd window, especially with the font it uses. It is also very useful to have the menu as a different window, so you can refer back to it when you are typing without scrolling.

In plain English:
I wish to create a way to open the help menu of any command (from any directory) in a separate notepad window.I decided to mess around with doskey as well and I noticed that when you type

Code: [Select]doskey note=$* 1>tmp.txt
into command prompt it created the txt file, making it so when it runs note the txt file is not being created.

One solution to this problem would be to do this...

Code: [Select]doskey note=$*^>tmp.txt $T start tmp.txt
that way the txt file wont be created until the note command is called.
this is tested and works for me.

The reason the ^ is needed is because it is considered to be a escape character which allows you to type characters that would usually do something in the program.

This page may explain it better then I can http://ss64.com/nt/syntax-esc.html

so using escape character logic, you could also do this...

Code: [Select]doskey note=$*^>tmp.txt ^& start tmp.txt
and it will have the same effect.
Thanks hibyy! I could have sworn that didn't work last time i tried, but I think I put the ^ in the wrong place

To have it automatically delete the tmp.txt file, you have to add a delay in
Code: [Select]doskey note=$* /? ^>tmp.txt $T start tmp.txt $T ping localhost -n 3 ^>nul $T del tmp.txt

The length of the delay seems to be important, depending on the length of the file being written. 3 seems to be best, but I haven't checked every command.

This removes the annoying pathways that appear, making it look neater. Although you notice the delay more.
Code: [Select]doskey [emailprotected] off $T $* /? ^>tmp.txt $T start tmp.txt $T ping localhost -n 3 ^>nul $T del tmp.txt $T echo on

7950.

Solve : Loop FTP upload file and run again never die.?

Answer»

I have this "test_event.log" file from Window and like FTP to Unix server. So I wrote this batch script. The code run ftp worked fine. But I like to keep this batch script loop and run again after 30'. I don't want batch script end. Anyone have any idea how to make this work? Please help....thanks

Quote

@echo off
Start /W "C:\PROGRA~2\TEST\OUT"
set "file=test_event.log"

(
echo open my.HOST.name
echo myusername
echo mypassword
echo cd "/staging/osdc/dtran"
echo binary
echo put "%file%"
echo close
echo quit
)> "ftp.txt"
ftp -s:"ftp.txt"

ping -n 30 127.0.0.1
Code: [Select]@echo off
Start /W "C:\PROGRA~2\TEST\OUT"
set "file=test_event.log"

(
echo open my.host.name
echo myusername
echo mypassword
echo cd "/staging/osdc/dtran"
echo binary
echo put "%file%"
echo close
echo quit
)> "ftp.txt"

:loop
ftp -s:"ftp.txt"
ping -n 30 localhost >nul
goto :loopThanks for the reply...I got the error below after transfer completed. After 30 seconds ftp can override over that file again. Is something wrong here? Please help. Thanks

Quote
ftp -s:"ftp.txt"

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be USED interactively.

FTP [-v] [-d] [-i] [-n] [-G] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuf
fer] [-b:asyncbuffers] [-w:windowsize] [host]

-v Suppresses display of remote server responses.
-n Suppresses auto-login upon initial connection.
-i Turns off interactive prompting during multiple file
transfers.
-d Enables debugging.
-g Disables filename globbing (see GLOB command).
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a Use any local interface when binding data connection.
-A login as anonymous.
-x:send sockbuf Overrides the default SO_SNDBUF size of 8192.
-r:recv sockbuf Overrides the default SO_RCVBUF size of 8192.
-b:async count Overrides the default async count of 3
-w:windowsize Overrides the default transfer buffer size of 65535.
host Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.The batch file you posted needed the login info changed - did you do that?

You SAID the error occurred *after* the transfer succeeded - that is unlikely with the code shown.Thanks...but i checked unix server with command "ls -ltr" didn't see new time stamp every 30 seconds just same file. Seem like didn't loop resend again after 30 seconds.

@echo off
Start /W "C:\PROGRA~2\TEST\OUT"
set "file=test_event.log"

(
echo open my.host.name
echo myusername
echo mypassword
echo cd "/staging/osdc/dtran"
echo binary
echo put "%file%"
echo close
echo quit
)> "ftp.txt"

:loop
ftp -s:"ftp.txt"
ping -n 30 localhost >nul
goto :loopThanks Foxidrive. I typo the output somehow. The code worked GREAT. Thanks a lot for ur help.Hi Foxidrive or anyone can help me with this code. I like to apply this code run 4 hours and will (timeout, stop, end...) not loop ftp file again....job will complete. Let say this code start at 9a then 1p will not loop ftp again. I did a lot the tested and can't figure out how to make this work yet. Please help.... . Thanks

Quote
@echo off
Start /W "C:\PROGRA~2\TEST\OUT"
set "file=test_event.log"

(
echo open my.host.name
echo myusername
echo mypassword
echo cd "/staging/osdc/dtran"
echo binary
echo put "%file%"
echo close
echo quit
)> "ftp.txt"

:loop
ftp -s:"ftp.txt"
ping -n 30 localhost >nul
goto :loop
Quote from: dtran on April 08, 2013, 11:44:18 AM
I like to apply this code run 4 hours and will (timeout, stop, end...) not loop ftp file again....job will complete. Let say this code start at 9a then 1p will not loop ftp again.

This line should make it exit when it is 1pm after the last run. The time format in your system might be 12 hour time in which case you will have to change the 13 to 1

for /f "delims=:" %%a in ("%time%") do if %%a EQU 13 goto :EOF

See below:


Code: [Select]@echo off
Start /W "C:\PROGRA~2\TEST\OUT"
set "file=test_event.log"

(
echo open my.host.name
echo myusername
echo mypassword
echo cd "/staging/osdc/dtran"
echo binary
echo put "%file%"
echo close
echo quit
)> "ftp.txt"

:loop
for /f "delims=:" %%a in ("%time%") do if %%a EQU 13 goto :EOF
ftp -s:"ftp.txt"
ping -n 30 localhost >nul
goto :loopAwesome....really nice. Thanks very much for this.