1

そのため、解決策を検索するための多くの試みの結果、実行中のbatファイルのフォルダーを見つけるための100万の方法が得られましたが、私が探しているのは、batファイルに渡されるファイル名のフォルダーを見つけることです.

例:

C:\Temp\runthis.bat "C:\Blah\Ah Argh\rage.txt"

そのバットファイル内で単に「C:\Blah\Ah Argh\」という文字列を取得したいのですが、代わりに「rage.txt」の文字列を取得して作業することもできます

理由を説明するための編集:ファイルが正常にアップロードされたことを確認するために、ftpサーバーのディレクトリリストである別のtxtファイル内のファイル名を確認しようとしています。次に、成功した場合は、ファイルを元のフォルダー \uploaded\ のサブフォルダーに移動する必要がありますが、これらのフォルダーの多くがセットアップされているため、ハードコーディングできません。

ありがとう

4

2 に答える 2

3
@echo off
The file path is %~dp1
The file name is %~nx1

パラメータ修飾子は、FOR 変数の場合と同じです。

パラメーター修飾子の完全なリストについては、コマンド プロンプトから「HELP CALL」と入力してください。

于 2012-12-08T00:50:26.833 に答える
1
@echo off
if %1X==X echo Syntax: %0 "path"

rem  The for loop doesn't actually loop. You can split strings with it, but in 
rem  this case we don't. So there is only one iteration in which %%X will 
rem  contain the full path.

rem  Pass it %1, which is the first parameter. Note the quotes, which are 
rem  required if you don't add quotes around the parameter and optional (but 
rem  still valid) when you do.

for /F "delims=|" %%X in ("%1") do (

  rem  FOR LOOP variables can be used with certain modifiers, preceeded by a 
  rem  tilde. In this case I'm using d and p, which stand for drive and path,
  rem  effectively trimming the file name from the path.

  echo %%~dpX

  rem The ~n modifier selects the file name only. ~x is for extension

  echo %%~nxX
)
于 2012-12-07T23:52:20.000 に答える