7

頻繁に移動するため、ドライブ文字がわからないバッチ ファイルがあります。

例: adobe ファイルは次の場所にあります: J:\Files\New folder\USB\Adob

バッチファイルは以下から実行されます: J:\Files\New folder\USB\USBSTICK

だから私はコードを試しました:

xcopy /s /y "%~dp0\..\..\USB\Adob\*" "C:\Program Files\"

ただし、ファイルはコピーされません。どうすれば動的に取得できますか?

4

4 に答える 4

3

ドライブ文字はシナリオの相対的な部分のようです。私があなたを誤解していない限り、これはあなたにとってよりうまくいくはずです.

xcopy /s /y "%~d0\Files\New folder\USB\Adob\*" "C:\Program Files\"

使用できるその他の変数については、次の手順に従います。
CMD からfor /?、下部に入力して読み取ります。

%~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.
于 2014-07-03T08:04:30.510 に答える
0

%~dp0 の一部であるため、"\" なしで試してください。つまり、%~dp0 の内容は常に「\」で終わります。

例:

xcopy /s /y "%~dp0..\..\USB\Adob\*" "C:\Program Files\"

編集

念のため ...

            is Adob\* or Adob\*.* ??
于 2010-12-02T06:12:38.150 に答える
0

あなたの階層についての私の理解から、これもうまくいきます:

xcopy /s /y "..\Adob\*" "C:\Program Files\"

J:\Files\New folder\USB一般的なプレフィックスであり、からバッチ ファイルを実行しているため、J:\Files\New folder\USB\USBSTICK扱っているドライブ文字に関係なく動作するはずです。

于 2010-12-02T06:17:20.890 に答える
0

あなたの問題を完全に理解しているかどうかはわかりません。しかし、私が理解しているように、問題を解決する解決策がいくつかあるように思えます。

パスが常に固定されていて、ドライブ文字のみが異なる可能性がある場合は、相対パスを使用できます。

xcopy /s /y "..\Adob\*" "C:\Program Files\"

バッチ ファイルが Adob​​ と同じディレクトリに存在する USBSTICK に常に存在する場合、任意のドライブからバッチ プログラムを呼び出すと、期待どおりに機能します。

ソース パスが変化する可能性がある場合は、変化する部分をパラメーターに置き換えて、正しいパスでバッチ ファイルを呼び出します。

xcopy /s /y "%1\*" "C:\Program Files\"

正しいパスを指定すると、任意のドライブおよび場所からバッチ プログラムを呼び出すと、期待どおりに動作します。

xcopybatch J:\Files\New folder\USB\Adob
于 2013-07-30T09:08:02.967 に答える