|
Answer» Hello, I have the following DOS CMD file. I"m trying to figure out the FOR statement. I don't get what the DO CALL %0 and %%I are doing. From what I can TELL the /F will loop through all the occurrences of a file that's identified within the parenthesis. However, there's only 1 file that matches w*.sql. Yet it loops through the code twice. I'm guessing that the %0 and %%I have something to do with it. Can you help?
@ECHO OFF :; The percent followed by a numeric value, beginning with one, allows USERS to :; add variables within a batch file. :; When the first variable is not blank, go to the ADDV header IF NOT "%1"=="" GOTO ADDV :; Declare Variables SET WorkspaceVAR= :; /B = Bare list of results /O:D = Sort Order by Date and Time :; For /F = Loop against a set of files FOR /F %%I IN ('DIR w*.sql /B /O:D') DO CALL %0 %%I :; Set Variables :ADDV SET WorkspaceVAR=%WorkspaceVAR%%1 :; Rename the current file to SET Prior1WorkspaceVAR=Prior1_%WorkspaceVAR% DEL Prior1workspaceVAR ren %WorkspaceVAR% %Prior1WorkspaceVAR% :; Get the current Workspace :; Export the SAINTSUSANNA workspace. This is where the UserNames are stored. :; I'm not sure if the WWV_FLOW_FND_USER is included here. java oracle.apex.APEXExport -db localhost:1521:XE -user APEX_040100 -password felix262 -expWorkspace :; Export the Library application. java oracle.apex.APEXExport -db localhost:1521:XE -user APEX_040100 -password felix262 -applicationid 104CALL %0 %%I
%0 is the batch file itself, so it is calling itself.
This is weird code. Did you write it yourself?Hi Salmon,
No, I found it somewhere, and I can't remember where.
Ultimately, what I'm looking to do is get the filename that matches the pattern w*.sql, which should have only one occurrence, and place that filename into a variable so that I can do copies, renames, and other things that I'm familiar with. I am just not exactly certain of how to get a file that matches a pattern and place it into a variable. If you have a better way, I'd be very grateful.
BostonBudThat is a very long and unnecessary code if all you are trying to accomplish is getting the filename into a variable. Try this: Code: [Select]for /f "tokens=*" %%a in ('dir /s /b /o:d w*.sql') do set var=%%a One THING to note is that this hopefully is running in a bottom level folder. If not, you may get other occurances inadvertently. Also, the reason that the /s switch is used is because using both /s and /b switches allows you to get FULLY qualified pathnames. /b will only give you the name and extension of a file, so especially if you are planning on manipulating and moving information to other places in the system, using the fully qualified pathname is the best way to ensure you are pulling from the correct file.Quote from: Raven19528 on March 23, 2012, 12:26:30 PM Also, the reason that the /s switch is used is because using both /s and /b switches allows you to get fully qualified pathnames. You can get this by using dir /b and set var=%%~dpnxa
Hello Raven and Salmon Trout. Your suggestions worked perfectly. Thanks very much for your help.
|