for %f in (*.lsp) do find /i "defun C:" %f>>defunC.txt
I have been using the line of code above at the Command prompt. I have many folders and it is proving very time consuming to start a command prompt in each and then to cut and paste the code to the command line. Can someone help me to turn it into a batch file which can use drag n drop of the required folders one at a time?
Thank you !!
Command Line Input Adaptation to Batch File
Moderator: DosItHelp
Re: Command Line Input Adaptation to Batch File
You could try something like that
Regards
aGerman
Code: Select all
@echo off &setlocal
pushd "%~1"||goto :eof
for %%f in (*.lsp) do find /i "defun C:" "%%f">>%~dp0defunC.txt
popd
Regards
aGerman
-
- Posts: 3
- Joined: 22 May 2010 13:20
Re: Command Line Input Adaptation to Batch File
aGerman,
Thank you! It was the second percent sign required with the variables in the batch file that I was missing. I actually had it working before your response. I don't fully understand the remainder of your batch file, but it worked for me, so I am using yours, assuming that there is good reason for the code which you included that I didn't have.
Thanks, again !!
Thank you! It was the second percent sign required with the variables in the batch file that I was missing. I actually had it working before your response. I don't fully understand the remainder of your batch file, but it worked for me, so I am using yours, assuming that there is good reason for the code which you included that I didn't have.
Thanks, again !!
Re: Command Line Input Adaptation to Batch File
SteveBubendorf wrote:[...]I don't fully understand the remainder of your batch file[...]
@echo off &setlocal
This turns off the command prompt and limits changing of the environment to the current batch window.
pushd "%~1"||goto :eof
pushd changes the working directory. In %~1 you will find the first argument (without enclosing quotes). In case you drag'n'drop a folder onto the batch file it contains the folder name. ||goto :eof means if pushd would fail then the batch processing would jump to the end of file, so it will quit.
for %%f in (*.lsp) do find /i "defun C:" "%%f">>%~dp0defunC.txt
Well, think you will know how it works. In %~dp0 you will find the drive and path of the own batch file.
popd
pushd and popd belong together. pushd changes the working directory and saves the origin directory. popd jumps back to the saved directory and flushes the memory for this value.
Hope that helps.
aGerman
-
- Posts: 3
- Joined: 22 May 2010 13:20
Re: Command Line Input Adaptation to Batch File
Thank you for the explanation! I was vaguely familiar with most of what you explained, just not enough so to have ever come up with them on my own. The "%~dp0" portion, however, I had never seen used before, and I had absolutely no idea what that portion was doing whatsoever. Thank you for taking the time to help me learn!
I am always amazed when I go to this, or most any other forum I've queried, how great people are to help beyond my wildest expectations. It seems like the "virtual world" is kinder and more helpful than the "real world" I live in.
Thanks, again!
I am always amazed when I go to this, or most any other forum I've queried, how great people are to help beyond my wildest expectations. It seems like the "virtual world" is kinder and more helpful than the "real world" I live in.
Thanks, again!