2013-05-09 99 views
0

我想我的腳本:問題,在我的批處理腳本變量

  • 接受可變
  • 創建使用該變量作爲輸入
  • 顯示路徑
  • 顯示內容的路徑目錄

以下代碼有什麼問題? ECHO聲明僅打印Your directory is set to; DIR聲明按預期工作。

@ECHO OFF 
SET custompath = "C:\Users\%1" 
ECHO Your directory is set to %custompath% 
DIR %custompath% 

回答

2

這是圍繞=的空間。

@ECHO OFF 
SET custompath="C:\Users\%1" 
ECHO Your directory is set to %custompath% 
DIR %custompath% 

檢查this post

+0

怎麼沒DIR語句的工作? – 2013-05-09 21:05:26

+0

'echo DIR%custompath%' - >'DIR' 'echo DIR%custompath%' - >'DIR「C:\ Users \」' – Endoro 2013-05-09 21:19:19

+0

工作正常,只要路徑存在;) – MrCleanX 2013-05-09 21:28:24

0

就個人而言,我會做這種方式:

@ECHO OFF 
SET /P "custompath=Enter a custom windows path: " 
ECHO Showing contents of directory ^"%custompath%^" 
DIR /b "%custompath%" 
pause