SET变量未在.BAT文件中读取 [英] SET variable not being read in .BAT file

查看:78
本文介绍了SET变量未在.BAT文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个Windows批处理文件,无法正常使用.
基本上,我在一个位置有一个文件夹,我需要将其复制到另一个文件夹,但还要重命名新的文件夹名称.

I have this Windows batch file and I cannot get to work it properly.
Basically I have a folder in one location and I need to copy it to another folder, but to also have the new folder name renamed.

@Echo off
::
set 836147398 = @Taunus_A3
:: 
Echo Copying %836147398%
xcopy "C:\Users\arrona\Desktop\Update Mods\steamapps\workshop\content\107410\836147398" "C:\TCAFiles\Games\arma3exile\TCA.Mods\%836147398%" /s/h/e/k/f/c

所以我需要将333310405的文件夹内容复制到C:\TCAFiles\Games\arma3exile\TCA.Mods\,但作为@Taunus_A3文件夹名称.

So what I need is that the folder contents of 333310405 are copied to C:\TCAFiles\Games\arma3exile\TCA.Mods\, but as @Taunus_A3 folder name.

它将复制文件夹以及所有内容,但是不会读取变量.它将回显正在复制836147398",而不回显正在复制@ Taunus_A3"

It will copy the folder over and all the contents, but it is not reading the variable. It will echo "Copying 836147398" not echoing "Copying @Taunus_A3"

推荐答案

  1. set "varname=varvalue"命令中的=符号的两侧消除空格.
  2. 避免使用前导数字命名变量.阅读命令行参数(参数):
  1. Get rid of spaces on either side of the = sign in set "varname=varvalue" command.
  2. Avoid naming variables with a leading number. Read Command Line arguments (Parameters):

尽管set "836147398=@Taunus_A3"是有效的命令,但echo %836147398%仍会显示

Although set "836147398=@Taunus_A3" is a valid command, echo %836147398% would display

  • @Taunus_A3在命令提示符下,但是
  • 批处理脚本中的
  • 36147398,因为%8被计算为提供的第8个参数(在大多数情况下,假定为空字符串),并且孤立的尾随%百分号在设计上被忽略.
  • @Taunus_A3 in command prompt, but
  • 36147398 in a batch script, because %8 is evaluated to the 8th supplied parameter (supposedly an empty string in most cases) and orphan trailing % percent sign is ignored by design.

解决方案:使用非密码前缀,例如_下划线如下:

Solution: use a non-cipher prefix, e.g. _ underscore as follows:

set "_836147398=@Taunus_A3"
echo %_836147398%

这篇关于SET变量未在.BAT文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆