2008-12-05 16 views
21

विंडोज बैच फ़ाइल के अंदर मैं यह जानना चाहता हूं कि इस बैच फ़ाइल का पूर्णतः योग्य पथ नाम क्या है।चल रहे बैच फ़ाइल का फ़ाइल नाम ढूंढना

मैंने% 0 की कोशिश की लेकिन यह केवल मुझे टाइप किया गया आदेश देता है (उदाहरण के लिए केवल पथ या एक्सटेंशन के बिना फ़ाइल नाम)।

+0

मैं काफी समझ में नहीं आता कि तुम क्या पूछ रहे हैं। % 0 वह है जिसे आपने स्क्रिप्ट लॉन्च करने के लिए टाइप किया था। क्या स्क्रिप्ट एक और लॉन्च कर रही है? क्या यह किसी दूसरे से जुड़ा हुआ है? अधिक जानकारी कृपया। – jim

+0

यदि आप सिर्फ% 0 का उपयोग करते हैं तो आपको पूरी तरह से योग्य पथ नाम नहीं मिलेगा। किसी अन्य अनुप्रयोगों से आपकी बैच फ़ाइल को रेफर करने के लिए% 0 पर्याप्त नहीं है। – Martin

उत्तर

23
echo %~f0 

काम करता है पाने के लिए सक्षम होना चाहिए।

7

% सीडी% वर्तमान निर्देशिका देता है।

% ~ dp0 आप निर्देशिका लिपि में है दे देंगे

IE:। ग में स्क्रिप्ट: \ फ़ोल्डर, मैं इसे ग से फोन: \ otherfolder

% सीडी% = C: \ otherfolder

% ~ dp0 = c: \ फ़ोल्डर

(मैं 99% यकीन है कि मैं उन सही तरीके दौर है, लेकिन एटीएम पर जाँच करने के लिए खिड़कियां नहीं मिला हूँ)।

संपादित करें: और वहाँ से, एक आप पहले से ही मिल गया है का उपयोग करते हुए, तुम मेरे लिए बैच फ़ाइल नाम

30

आपकी जानकारी के लिए,

आप कमांड फैली हुई है, जो विन 2000 से पहले मौजूद नहीं है सक्षम करने की आवश्यकता होगी (मैं नहीं जानता कि NT4)

देखें: cmd.exe /?

/E:ON Enable command extensions (see below) 
/E:OFF Disable command extensions (see below) 

कमांड एक्सटेंशन विंडोज़ पर डिफ़ॉल्ट रूप से सक्षम है।

एक और मदद जो मैं पढ़ने का सुझाव देता हूं वह है फोर कमांड। इसमें उन ध्वज के लिए पूर्ण अर्थ है।

देखें: के लिए /?

In addition, substitution of FOR variable references has been enhanced. 
You can now use the following optional syntax: 

    %~I   - expands %I removing any surrounding quotes (") 
    %~fI  - expands %I to a fully qualified path name 
    %~dI  - expands %I to a drive letter only 
    %~pI  - expands %I to a path only 
    %~nI  - expands %I to a file name only 
    %~xI  - expands %I to a file extension only 
    %~sI  - expanded path contains short names only 
    %~aI  - expands %I to file attributes of file 
    %~tI  - expands %I to date/time of file 
    %~zI  - expands %I to size of file 
    %~$PATH:I - searches the directories listed in the PATH 
        environment variable and expands %I to the 
        fully qualified name of the first one found. 
        If the environment variable name is not 
        defined or the file is not found by the 
        search, then this modifier expands to the 
        empty string 

The modifiers can be combined to get compound results: 

    %~dpI  - expands %I to a drive letter and path only 
    %~nxI  - expands %I to a file name and extension only 
    %~fsI  - expands %I to a full path name with short names only 
    %~dp$PATH:I - searches the directories listed in the PATH 
        environment variable for %I and expands to the 
        drive letter and path of the first one found. 
    %~ftzaI  - expands %I to a DIR like output line 

In the above examples %I and PATH can be replaced by other valid 
values. The %~ syntax is terminated by a valid FOR variable name. 
Picking upper case variable names like %I makes it more readable and 
avoids confusion with the modifiers, which are not case sensitive. 
+0

बस मुझे 0 – waza123

1

"% ~ f0"

"% ~ dpnx0"

ऊपर की या तो पूरी तरह से योग्य पथ देता है। पथ में रिक्त स्थान होने पर इसे डबल कोट्स में संलग्न करें।

0

फोन स्क्रिप्ट: "FIRST.BAT":

call second.bat %0 parameter-a parameter-b 

नामक स्क्रिप्ट: "SECOND.BAT":

echo The name of this called script should be "SECOND", proof: %~n0 
echo The 1st parameter passed should be "FIRST", proof: %1 shift 
echo The name of the calling script should be "FIRST", proof: %~n0 
echo The 1st parameter should be "parameter-a", proof: %1 
+0

के साथ प्रतिस्थापित करें, मुझे उम्मीद है कि मेरे स्वरूपण सुधार लगभग सही थे। – zx485

संबंधित मुद्दे