2012-03-29 20 views
1

我打得周圍並執行以下.bat爲什麼這個批處理腳本創建看似隨機的目錄?

@echo off 
mkdir %~dp0 
pause 

這創造了在該批次的位置兩個目錄:

  • 「和」
  • 「設置」(這裏面: 「Usuario」 inisde這個 「Escritorio」,inisde這個 「123」)

注:我從「123」目錄

執行批處理我想一些背景瞭解到底發生了什麼

+0

又是什麼'回聲%〜dp0'告訴你? – 2012-03-29 00:37:23

+0

@GregHewgill'「C:\ Documments and Settings \ Usuario \ Escritorio \ 123 \」'只是用於記錄,「Escritorio」表示西班牙語桌面 – ajax333221 2012-03-29 00:38:17

回答

3

mkdir命令使命令行(用空格隔開)指定的所有目錄。例如,

mkdir foo bar 

將使目錄foobar。在你的情況下,參數是C:\Documents and Settings\Usuario\Escritorio\123,相當於:

mkdir C:\Documents and Settings\Usuario\Escritorio\123 

由於mkdir不知道有什麼不同,它認爲你想創建一個名爲三個目錄:

  • C:\Documents
  • and
  • Settings\Usuario\Escritorio\123

你可以試試:

mkdir "%~dp0" 

看看雙引號是否有幫助。

+0

+1。用鼠標點擊「提交」按鈕來打我(並且你的回答比我的要好)。 :) – 2012-03-29 00:41:36

+0

謝謝!我真的很討厭隨機存儲在我的電腦上的東西(我從來沒有想過它還創建了'C:\ Documents',現在我刪除了它) – ajax333221 2012-03-29 00:41:49

+0

最後,我創建了var'set cur =「%〜 dp0「',我正在使用像這樣'mkdir%cur%bananas',是否有C:\ path \」bananas'而不是'C:\ path \ bananas'''? – ajax333221 2012-03-29 00:52:45

1

既然你用C執行它:\ Documments和設置...,但也沒能逃脫它,它是基於空格分割的路徑:

C:\Documents and Settings\... 

會分成"C:\Documents""and""Settings\..."

如果用"""%~dp0"應該工作逃避它:它會擴大到"C:\Documments and Settings\..."將不會被分拆

相關問題