| 1. |
Solve : how to asign dir result to the variable? |
|
Answer» how could i ASIGN dir result to the variable how could i asign dir result to the variable i have a question for you. what do you want to do with those directory listing results? are you going to find files ? If say you have 10000 files under the directory, are you going to assign all these files a variable each ?? Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable We cannot assign all the filenames in a directory to one variable. Usually only one line from a file to each variable. Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable Where did Animo go? Ask a question and leave the room? A variable is a storage location in RAM ( Random Access Memory ). The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ). When you shut down the information disappears. A file is a memory location on the Hard Disk. The information remains after shut down. Why would anyone expect to store all the information from a file in a variable location? Your basic understanding of computers is not present. Quote Your basic understanding of computers is not present. And some people can't separate a quote from their own reply. Quote from: billrich on October 30, 2009, 04:21:45 PM separate your quotes from your replies. Its annoying. Quote The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ).this has nothing to do with the question. Besides, the above is statement is wrong. The amount of information we can store in a variable is as equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line, you ARE basically using memory for the whole file. Get your PERSPECTIVE right. Also, there are functions in programming languages that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory. Quote from: billrich Your basic understanding of computers is not present.the pot calling the kettle black.Quote from: gh0std0g74 on October 30, 2009, 06:39:13 PM Pot and Kettle. Animo(OP) wrote "set /a result=`dir /b /o:n"` Animo wrote: "How could I assign dir result to the variable The above does not work." Bill wrote: "We cannot assign all the filenames in a directory to one variable with the for loop in Batch." "Usually only one line from a file to each variable." Bill Wrote: The amount of information we can store as a variable is limited ( usually one line from a text file with batch. ). Ghost wrote (Fed by BC) : "This has nothing to do with the question." Bill explains: Read what Animo (OP) wrote above: Animo was trying to assign all the files in a directory to one variable ( Result ). Ghost wrote "Besides, the above is statement is wrong. The amount of information we can store in a variable is equivalent to how much memory the computer system has. If you read a text file line by line and store into different variables for each line, you ARE basically using memory for the whole file. Also, there are functions in programming languages that reads the whole file into one big variable for the purpose of convenience, but ultimately, storing to many variables or one variable are both the same, they are both still using up memory." Bill wonders: "What does the above have to do with Batch?" No, Ghost you are wrong but you do not use Batch. The Batch for loop will allow only one line to be assigned to each variable. So, what The Ghost writes has nothing to do with Animo's (OP) question. GHOST, What is this about a Pot and Kettle? This has come up before. If you have a huge amount to information that you need to store, common practice is to put into some kind of database that can be stored as a file. For practical reasons the number of variables you can have is limited. If you use a FOR loop and the variables are part of the FOR structure, the limit is 26 variables. A vailable should not be over 128 characters., says one reference. Some versions of ODS put a limit to the amount of memory that will be assigned to variables. Yet if the OP wants to put the names of all the directories into some variables, he can do that. Maybe we don't know why, but it can be done. Anyway, being rude to anyone has little value here. Quote from: billrich on October 30, 2009, 08:17:50 PM Bill Wrote:i say again. The amount of information you can store in a variable is unlimited, its only limited by the amount of physical RAM you have on your system!!! Whether or not DOS batch only read one line each time from a file is not the problem. I don't do batch , BUT i certainly know how to PROGRAM. Code: [Select]@echo off setlocal enabledelayedexpansion set var= for /f "delims=" %%a in (file) do ( set line=%%a set var=!var! !line! ) echo The file contents are: %var% Since you are a so called batch guru, i assume you can see that %var% is one big variable, now containing all the lines of the file. Now, do you understand what this means??? Quote GHOST, What is this about a Pot and Kettle?now i have to give you english lessons? go figure out yourself.Quote from: gh0std0g74 on October 30, 2009, 08:56:50 PM Code: [Select]@echo off Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster? I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago. I'm 72. I don't work. Where does Ghost work as a Programmer? Ghost, read post #8 by Geek above. Quote from: billrich on October 30, 2009, 09:20:18 PM Who wrote the code? Salmon Trout? Excellent. Did you provide a copy to Animo, the original Poster?anyone who knows how to write batch will know its a "standard way" to concatenate lines to one variable. Why should i provide a copy to OP? you are ridiculous. whether i want to provide solutions is my own business. Quote I never claimed to be a "Batch Guru." I had not used batch until I logged on here several months ago.that's why i have written "so called batch guru". which implicitly means i am saying you are not. Quote I'm 72. I don't work.that's why you have plenty of time trolling around. Quote Where does Ghost work as a Programmer?what gives you the idea that i am a programmer? Does it mean i need to be a programmer in ORDER to program? Quote from: animo on October 30, 2009, 03:15:11 AM how could i asign dir result to the variable C:\batextra>type vardir.bat Code: [Select]@echo off REM code by unknown setlocal enabledelayedexpansion dir /b /o:n > dirvar.txt set result= for /f "delims=" %%a in (dirvar.txt) do ( set line=%%a set result=!result! !line! ) echo. echo The directory contents assigned to result variable: %result% OUTPUT: C:\batextra>vardir.bat The directory contents assigned to result variable: .uvwrap_v301.swf .uvwrap_v3 02.swf .uvwrap_v303.swf .uvwrap_v304.swf .uvwrap_v305.swf 2009.January.blanks 20 09.January.dotfile 2line.bat 2pdfdos.bat A.bat anecho.bat ans.bat AUTOEXEC.BAT B .bat Batch1.bat batchname.bat batexe.bat batfile.bat bc.bat bcalc.bat beep.bat b est.bat bill0910.bat bill0911.bat bill72.bat bill72.txt Blues.wma brost.bat BSET Bver.bat caavsetupLog.txt caisslog.txt carbon.bat caret.bat caseyville.gif chan gename.bat chkqo.bat choice.bat christmas.txt clear.bat clock.bat CONFIG.SYS cop yfiles.bat copytxt.bat cosmic.bat count.txt countf.bat countword.bat dalete.bat data.csv data06.txt date.txt datefile.bat datename.bat daydir.bat db.txt del3sec .bat delnet.bat desk.bat dev.bat devstr.bat devtok.bat devtwo.bat devtxt.bat dev u.bat Dias.bat digit.bat dir dirtree.bat dirvar.txt disklog.txt Divide.bat Docum ents dostimer.bat drive.bat echprom.bat envvar.bat err.bat evaluate.bat evaluate .vbs expand.bat extractfolder.bat field1.bat fiels1.bat fifty.bat file.bat file. txt filelen.bat fileprop.bat filetovariable.bat finalstr.bat finalziplist.txt fi nddir.bat findstring.bat findxfiles.bat FlashSavingPluginSetup.exe fold.bat fold 1 fold2 fold3 fold4 fold5 folder1 folder2 folder3 folder4 folder5 for.txt found. bat FP.vbs g.bat game.bat gee.bat generatebat.bat ghost.bat gkata.bat go.bat goo glemath.bat gotoline.bat h3.bat hello.bat helpme.bat helppetty.bat hi.bat his.ba t hist hist.txt hmath.c homewk.txt homework3.bat hope.bat htmldrive.bat inc.bat indent Instruct_for.txt jak.bat kaus.bat kay.bat Keeptime.bat lewbat.bat line.ba t list_of_program_files.txt list2a.txt listone.txt log log.txt longshot.doc lw.b at mac.bat macdir.bat main.bat map.bat map2.bat mapodd.bat match.bat math.bat ma th2.bat menu.bat Menuhope.bat MenuHope.txt mon.bat mon.txt monnum.txt mpgname.ba t MSDIR.bat msin.bat mwc.bat mydate.bat namedate.bat New Stories (Highway Blues) .wma newbat.bat newname.bat nomodname.bat noperiod.txt notime.bat null old.bat o ldfiles.bat orastr.bat outmenu.txt parsedate.bat particular.bat pdfdos.bat perio d.bat period.txt PID_446170_AFIQ3Q4_RMOLA_MMY_160x600.sw f PID_446170_AFIQ3Q4_RMO LA_MMY_160x600_Parent.swf pipe.txt playsong.bat pp.bat preloader.swf preloader01 .swf preloader02.swf progressbar.bat prtbat.bat psexec.exe quote.bat renamejpg.b at renjpg.bat reno.bat replace.bat reploop.bat reveille.mp3 rmext.bat rmnum.bat rmnum2.bat runany.bat safexp.zip save screenclean.swf sendfile.bat session.txt s etvar.bat sfc SH_HISTO shakeit.gif show.bat show.txt shut.bat Sig.gif signal.txt signature signature.htm sigop.gif sleep.exe sortdir.bat sortdir.txt sound.swf s tartsig.bat str.bat str2.bat str3.txt strcat.bat striptime.bat strlen.bat succes s.bat sumnum.bat TAPS.mp3 task.txt taskkill.exe tasklist.exe Tata.jpg tehthe.bat temp.tmp temp1.txt tes3.bat tes4.bat test.bat test06.bat test07.bat test07.txt test10.bat test18.bat testextract.bat testfilnam.txt TestLog.csv testnum.bat tes tver19.bat testwhat.bat textsearch.bat timediff.bat timeinseconds.bat timest.bat tips.txt tooktime.bat try.bat try06252009.bat try07182009.bat try07302009.bat t wodate.bat uvwrap_v3.swf val.bat val20.bat valarie.bat vardir.bat vars.bat vartx t.bat vbprop.bat verp.bat volis.bat wait1.bat wait10.bat wait2.bat wait5.bat wai ttime.bat walkthetalk.swf wget.bat whatd.bat whatis.bat win.ini winder.bat windo wsupdateagent30-x86.exe wmp.bat writetofile.bat x.txt x3.bat xc.bat xcc.bat xfif ty.bat xinc.bat xlw.bat xmas.txt xplaysong.bat xsignature.htm xtry.bat xxsignatu re.htm xxtestfl.bat xxx.txt xxxmenu.bat xxxxx.bat xy.bat y y.htm yourfile.bat z. txt zeke.txt zip.bat zip2.bat ziplist.txt zzero.bat C:\batextra> |
|