No of visitors who read this post: 482
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

:loop

 echo %1 > _%count%.var

 set /a count=count+1

 shift

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

 goto loop

:startSort

 set /a total=%count%-1

:RestartSort

 set /a count=0

:sortLoop

 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

:swap

 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

:noSwap

 set swapped=

 goto :eof

:output

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

:cleanup

 erase *.var

 set next=

 set offset=

 set total=

 set count=

 set var=

 set var1=

 set var2=

 goto :eof

:showval

 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:

Go to your CONTROL PANEL

Select the DEFAULT Programs

Now go to SET ASSOCIATION OF 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.