| 1. |
Solve : display file name and label name in batchfile? |
|
Answer» Is there a way to returning the name of the current label that is running in a batchfile onscreen (or to a log). And is it possible to have a batchfile write it's own name to a logfile? This would save on hardcoding. for batch name use %0 C:\>label Volume in drive C: is Free Volume Serial Number is F4A3-D6B3 Volume label (ENTER for none)? Delete current volume label (Y/N)? ^C C:\> ( I have used computers since 1968 and have never had need for the label information. )Quote from: gpl on August 24, 2009, 05:23:28 AM If you have not used Shift, then %0 refers to the batch name :Used Shift? You mean like the Shift Key on the keyboard? What does it do? Quote from: gpl on August 24, 2009, 05:23:28 AM good editors would allow you to create a macro that locates each labelYEAH yeah, rub it in. Thank you gpl. dramklukkelQuote from: dramklukkel on August 26, 2009, 12:52:09 AM Used Shift? You mean like the Shift Key on the keyboard? What does it do? The SHIFT command in a batch file, which shifts the parameters %1 %2 %3 ETC down by one each time it is used. So %1 becomes %0 and %2 becomes %1 and so on. %0 is normally the command line used to start the batch (i.e. its name and sometimes its drive letter path as well DEPENDING on how it is invoked) but if SHIFT is used then it is lost because it is replaced by the contents of %1 %2 %3 etc (if there are any) or a blank (if there are not) Quote from: billrich on August 25, 2009, 12:09:19 PM ( I have used computers since 1968 and have never had need for the label information. ) Thanks for your reply Billrich, The 'LABEL' in this case is not the drive label, but he label where GOTO refers to. Returning the name of that label helps you debugging. When reading a log you can see what route the program has followed, what labels it has passed/skipped, or sometimes if it has crashed. In my example the labels were called :Test1, :Test2 and :End. You are right about the drive label. I can find no use for it except for easy reading. grt dramklukkel.Thanks you all for your valuable input. I appreciate it. grt, dramklukkelQuote from: oldun on August 25, 2009, 01:22:05 AM You could do it by assigning a variable for the current label. I see, but this means I have to assign every single label. That way I might as well hardcode it and skip the variable. Code: [Select]@echo off :Test1 ECHO Label = Test1 >> c:\temp\mylog.txt Wich is basically what I was doing allready. My intention was to not having to write out every label. Thus not risking errors while typing or failers after renaming labels. Rather I'd have a single line that I can copy over and over, without having to think about it. Oh dear, I'm spoiled. greetings, Dramklukkel. Quote That way I might as well hardcode it and skip the variable. Even better code it so you don't use gotos & labels. It is possible, and I see you already understand this... if [test] (something1) else (something2). Extend it to... if [test] ( something1 something2 ) else ( something3 something4 ) |
|