Solved Defrag a chosen volume using .bat

December 21, 2017 at 06:28:39
Specs: Windows 10
Good morning. I started using dos in college and I have a project to do where in a batch file the user will chose a volume which he desire to defrag.

Well I thought about this and said well imagine we have a like 10 volumes. I will create a variable where the user will type the volume he wants to defrag. I wrote this code but it is not working and I think the variable is not being read.

@echo off
echo Defragmentation
set /p= Type the volume you want to defrag
defrag %p%: /D

Can someone help please?
Thank you in advance

See More: Defrag a chosen volume using .bat

Report •

December 21, 2017 at 06:56:25
Change the "set" line to:

set /p p= Type the volume you wish to defrag

Report •

December 21, 2017 at 22:32:45
✔ Best Answer
fwiw: prior to any set /p, it is good practice to clear the target variable, or otherwise handle possibilities:
set p=
set /p p=xxx

If 'p' is not cleared, and it has a value, and the user hits [ENTER] key, it will retain that value, and NOT go to null/undefined.

message edited by nbrane

Report •
Related Solutions

Ask Question