简体   繁体   English

在我的批处理脚本中出现变量问题

[英]Issue with a variable in my batch script

I want my script to: 我希望我的脚本:

  • Accept a variable 接受变量
  • Create a path using that variable as input 使用该变量作为输入创建路径
  • Display the path 显示路径
  • Display the contents of the directory 显示目录的内容

What is wrong with the following code? 以下代码有什么问题? The ECHO statement just prints Your directory is set to ; ECHO语句只是打印Your directory is set to ; the DIR statement works as expected. DIR声明按预期工作。

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

It's the space around the = . 这是=周围的空间。

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

Check this post . 查看这篇文章

Personally, I would do it this way: 就个人而言,我会这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM