| 1. |
Solve : Embedded variables not setting? |
|
Answer» Hello, He should reconsider his use of goto :eofWhy? Quote from: Raven19528 on April 30, 2015, 05:39:32 PM Yeah that would probably be helpful Without the needed input file(s) - we'd go crazier than we are, trying to work out what you are doing. Give us some data in input file(s) in the correct formats... The variables aren't being set because of the way you are setting them - maybe within a loop. So this is some SAMPLE text from the input files: Alpha.txt SMITH, BOB J JONES, JANE A WILLIAMS, ANDREW G ... A43.txt SMITH, BOB A43.PDF WILLAMS, ANDREW A43.PDF WHITE, JIM A43.PDF ... D75.txt SMITH, BOB D75.PDF HOBBS, JACOB D75.PDF GREEN, NORM D75.PDF ... Why am I not able to set those variables within a loop? I don't recall that ever being a problem before. Is it something where maybe I should use a call set command to set the variables? Quote from: Squashman on April 30, 2015, 08:16:57 PM Why?Because the feature is for advanced users. Because one who can not write a few lines of batch code and not know how to debug it not use goto : eof Each part of the code should be in a separate file with echo left on. He would verify wash file;'s behavior separately. Only after getting it to work right would he combine the files and user the goto : eof thing. This is the proven method for novices. BEGINNERS should not use that feature until they can write 100 lines of code sand get it right the first time. In other words, he did not use a debugging method suitable for his skill level. Not that being a beginner is a crime. But one should not use code that is to hard to debug.Okay, ran this through manually, after breaking out all the calls into separate files. Found that the additional text files weren't processing for some reason. Changed the command to for /f "tokens=1,2" %%E in ('type A43.txt') do ( Works like it should now. Run time is a little long, but it's reading these files over and over, and honestly, its doing the job for me so I don't have to, so I'm happy with that. Thank you Geek. While I'm sure I have some rust, I was doing regular batch scripts for a while, and now getting back into it for some more mundane tasks, I'm sure there is plenty I need to relearn.I am glad that worked for you and glad your replied. Having a program that works is more important than speed. Inmost cases. Batch files, by nature, are not well suited for speed optimization. If you have a need to write lots of batch files, you might consider using The Microsoft recommended advancement: PowerShell http://en.wikipedia.org/wiki/Windows_PowerShell Also see: Jump Start PowerShell Video Have fun ! Quote from: Raven19528 on May 01, 2015, 08:14:09 AM So this is some sample text from the input files: It's nice of you to provide some sample data. I know you have a solution but a comment I have from looking briefly at your code is that trim.bat will do nothing at any stage with any variable - because the data you are passing will never have leading or trailing spaces due to the way the data is passed in the call statements. Another issue is that the %2 term will always lose part of the second term in the call statements. I didn't analyse it past noting those problems - it would be really helpful to discuss what the batch script is SUPPOSED to be doing, with some examples, when you ask your question. The input data is essential of course - kudo's to you for providing some (Often, instead of input data we get an argument about how we don't need any). If you want to optimise your code for speed then give us all the info and someone may be able to offer some ideas. |
|