Defrag running recursively

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
Mister Fox
Posts: 3
Joined: Tue Feb 21, 2012 1:06 pm

Defrag running recursively

Post by Mister Fox » Wed Feb 22, 2012 12:29 pm

I am trying to make a batch file that will defragment the C: drive on a computer. I have this so far-

defrag C:

When I run the file, it defrags the drive, and then goes back into the defrag command (it looked like it was going to defrag it a second time).

I want the user to be able to leave the file running without having to come back to it to close it. I have an exit command after the defrag command, but the file never closed.

Any way to make it defrag just once?

User avatar
Mister Fox
Posts: 3
Joined: Tue Feb 21, 2012 1:06 pm

Defrag running recursively

Post by Mister Fox » Wed Feb 22, 2012 12:29 pm

I am trying to make a batch file that will defragment the C: drive on a computer. I have this so far-

defrag C:

When I run the file, it defrags the drive, and then goes back into the defrag command (it looked like it was going to defrag it a second time).

I want the user to be able to leave the file running without having to come back to it to close it. I have an exit command after the defrag command, but the file never closed.

Any way to make it defrag just once?

User avatar
jvierra
Posts: 13502
Joined: Tue May 22, 2007 9:57 am
Contact:

Defrag running recursively

Post by jvierra » Wed Feb 22, 2012 1:11 pm

If you name teh file defrag-just-once.bat it will only derag once.

User avatar
jvierra
Posts: 13502
Joined: Tue May 22, 2007 9:57 am
Contact:

Defrag running recursively

Post by jvierra » Wed Feb 22, 2012 2:09 pm

Your statement about recursive makes little sense. Defrag is not recursive and -f only says to force defragmentation if space is low.

If you name the batch file defrag.bat the file will run continuously and do nothing.

I kiddingly asked you to change the file name hoping you would see the problem.

You say you are a student. What kind of student. Junior-high, highschool college?

Again - defrag does not run recursively. Call a batch file with the same name as a call inside the batch file will loop continuously and do nothing.

Usually we jsut put derfrag in a scheduled task that is run late at night once a week. If you put it in a batch file and give it to a user they will not be able to run it. Only an admin can run defrag.

One line in a batch file is not a script. Defrag is a command line utility. Putting it in a bat file does not make it a script.

If you did name the batch file defrag.bat then you have learned something about endless loops.

Good luck


jvierra2012-02-22 21:19:50

User avatar
jvierra
Posts: 13502
Joined: Tue May 22, 2007 9:57 am
Contact:

Defrag running recursively

Post by jvierra » Wed Feb 22, 2012 3:52 pm

There is no MSDOS anymore. Tha tdisappeared with Windows 98 about 15 years ago.

Batch scripting is also called shell scripting. You might start here:
http://www.amazon.com/Windows-Shell-Scr ... 1578700477

Shell scripting is pretty much obsolete now that we have PowerShell although it i suseful fo rsimple thngs but not worth learning as it is very weak in many ways.

In order to use any form of scripting you will have to start by learning how Windows works. I suggest starting with a book on the basics of Windows technologies and work up from there.




Locked