overwraith Posted December 23, 2012 Share Posted December 23, 2012 (edited) I am trying to take some batch script and make it executable line by line in the command prompt. Have made some good progress, but some of the aspects of batch programming still evade me. at this webpage: http://forums.techgu...-selecting.html I found this code: BATCH FILE CODEsetlocal EnableDelayedExpansionset count=0for /f "delims=" %%a in ('dir /b *.mp4') do @( set filename[!count!]=%%a set /a count = count + 1)set /a choose = (%random% * 32768 + %random%) %% countset chosen=!filename[%choose%]!echo %chosen%pause[/CODE]which I figured out I could put the set commands on one line using the '&' operator, and I could change the file scope to all files in the directory:[CODE]BATCH FILE CODEsetlocal EnableDelayedExpansionset count=0for /f "delims=" %%a in ('dir /b *.*') do @( set filename[!count!]=%%a & set /a count = count + 1 )set /a choose = (%random% * 32768 + %random%) %% countset chosen=!filename[%choose%]!echo %chosen%pause[/CODE]Now what is bothering me is converting the variables to command line batch instead of batch file batch. I know the counter variables we have to take off a '%' operator, but the '!' operators really confuse me. Do we have to completely change the '!' operators? This will ultimately be something my ducky types in to select a random file to append an alternate data stream to. It is very important that there is a variable at the end of whatever solution is made which contains the file name. When you paste this in your command prompt to test paste "cmd /V:On" at the beginning to enable delayed variable expansion. My understanding of delayed variable expansion is limited right now, I only know that if it is not enabled and a for loop calls the same variable twice there will be problems.My current code with one '%' removed from the counter variables:[CODE]ATTEMPT AT CONVERTING TO STRAIGHT COMMAND LINEcmd /V:Onset count=0for /f "delims=" %a in ('dir /b *.*') do @( set filename[!count!]=%a & set /a count = count + 1 )set /a choose = (%random% * 32768 + %random%) % countset chosen=!filename[%choose%]!echo %chosen%[/CODE] Edited December 23, 2012 by overwraith Quote Link to comment Share on other sites More sharing options...
overwraith Posted December 23, 2012 Author Share Posted December 23, 2012 (edited) I think it works. Sorry. That's a first.NV. Was late at night when I first posted this. Edited December 23, 2012 by overwraith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.