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.
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Mister Fox
Posts: 3
Last visit: Wed Feb 22, 2012 11:29 am

Defrag running recursively

Post by Mister Fox »

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
Last visit: Wed Feb 22, 2012 11:29 am

Defrag running recursively

Post by Mister Fox »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Defrag running recursively

Post by jvierra »

If you name teh file defrag-just-once.bat it will only derag once.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Defrag running recursively

Post by jvierra »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Defrag running recursively

Post by jvierra »

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.



This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked