|
Answer» echo ( echo for /f "tokens=*" %%z in (c:\log) do ( echo copy "%%z" c:\a.bat )> log.txt
i want the batch when it execute it will copy to a log.txt that contain the above but it seem cannot is there anyway i can do ITI've got 2 ideas for you. 1) Redirect the output of your entire batch file to your log.txt. For example, if your batch file is called COPYLOG.BAT, then execute it like: Code: [Select]copylog.bat >log.txt 2) Use redirection inside your script. I THINK you have too many echo statements and one too many open parenthesis in your code so I'm not sure EXACTLY what you want to do, but I think you want something like: Code: [Select]for /f "tokens=*" %%z in (c:\log) do copy "%%z" c:\a.bat >log.txt Also note that copying multiple files to C:\a.bat will result in just the last file being copied to a.bat as all previous copies will be overwritten.
If it is the ACTUAL code you want in your log file then you could do something like: Code: [Select]echo for /f "tokens=*" %%%%z in (c:\log) do echo copy "%%%%z" c:\a.bat >log.txt Or if you want the code and you really want it on multiple lines, you can do: Code: [Select]echo for /f "tokens=*" %%%%z in (c:\log) do ( >log.txt echo copy "%%%%z" c:\a.bat) >>log.txtsry late reply yesterday got storm
i tested it and it works
but what if i want to copy out only part of the portion from the batch for example at least 5 sentences when it was execute the
1st idea didnt work but using 2nd it work but have to type too many thing is there a SHORTES way
anyway thx GuruGayyOnly a portion of the lines from your C:\log? Yes. If you want to skip the first 20 lines, you can add the "skip=20" in your for loop, like: Code: [Select]for /f "skip=20 tokens=*" %%%%z in (c:\log) do ...Is that what you were asking?
If you don't know how many lines there are, but still just want the last 5, then you can loop through the file to count the lines and calculate your SKIP=, then have a 2nd loop using your calculated value for SKIP. k i got it now thx and it works
|