No of visitors who read this post: 642
Category: Batch scripting
Type: Question
Author: Alick
Your rating: None Average: 5 (1 vote)

I try to run a batch file with a file extension ".BAT". This is a very long batch file that I’ve seen from the net. I want to test it on my computer. This is “Bubble sort” batch file.

Here is the full batch file code that I copied from the net.

@echo off

 set /a count=0


 echo %1 > _%count%.var

 set /a count=count+1


 if "%1" == "" goto :startSort

 goto loop


 set /a total=%count%-1


 set /a count=0


 set /a next=%count%+1

 call :swap %count% %next%

 set /a count=count+1

 if "%swapped%" == "true" goto :RestartSort

 if "%count%" == "%total%" goto :output

 goto :sortLoop


 set /P var1="" < _%1.var

 set /P var2="" < _%2.var

 if /I %var1% LEQ %var2% goto noSwap

 ren _%1.var _temp.var

 ren _%2.var _%1.var

 ren _temp.var _%2.var

 set swapped=true

 goto :eof


 set swapped=

 goto :eof


 for /L %%i in (0,1,%total%) do call :showval %%i


 erase *.var

 set next=

 set offset=

 set total=

 set count=

 set var=

 set var1=

 set var2=

 goto :eof


 type _%1.var

 goto :eof

Now there only problem is doesn’t work on my computer. When I double click it and try to run the batch file it only shows the path to the .BAT file I tried to run. I pretty sure that the code really works cause I also tried it with my younger brother’s laptop. What would be the cause of this error?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

# Comment Id: 14437

First of all what ever the sorting is used in file what you need to tell was that what kind of OS you are using and what is the file execution type in your system. What I can tell you here is just see your file type that is not set to read only. And then check these steps also to find the problem:


Select the DEFAULT Programs


Check all the types you want to execute. Also set the types of files here.

And a major thing is to check that you have saved your file with a .bat extenuation. I hope it will help a lot.