如果语句在批处理和应用程序不再被识别 [英] If statement in batch and app not recognized anymore
问题描述
我尝试访问存储在服务器上的一些Excel数据,并将这些文件复制到另一个服务器;目标路径应该与文件的名称不同。这是我的代码:
setlocal enabledelayedexpansion
net use Z:\\10.0.0.1\Statistiques
set path = Z:\
set year =%date:〜10,4%
set month =%date:〜4,2%
set day =%date: 〜7,2%
echo%date%
for / fdelims =%% a in('dir * .xlsx / b / ad%path%')do(
setname = %%〜na
set folder = Empty
如果!name!==!name:Client1 =!(
设置文件夹= Client1
)
如果!name!==!name:Client2 =!(
设置文件夹= Client2
)
复制%path %%% a \\10.0.0.2\Documents\Statistiques\!folder!\%year %% month %% day%_!name!%%〜xa
)
net use Z :/ delete
我的问题是最后的'net'作为内部或外部命令,可操作的程序或批处理文件。
在第一次使用时,驱动器正确安装;文件被正确复制,但是当我要删除驱动器我有这个错误。
可能是在我的if()语句错误?
可执行文件或包含环境变量 PATHEXT 中列出的文件扩展名的脚本。在新的命令提示符窗口设置路径
或只是设置
运行以获取显示的预定义环境变量及其当前值。 您的批处理代码包含:
\\
这将覆盖由Windows定义的 PATH 的值,因此命令处理器不能找到 net.exe
不在当前目录或驱动器的根目录 Z:
。 / p>
为 Z:\
指定为值的环境变量使用不同的名称。
对于 net 的两次出现,最好另外使用
%SystemRoot%\System32\\\
et.exe
将避免需要通过命令处理器在当前目录和 PATH 的所有目录中搜索 net。*
,直到找到具有文件的文件扩展程序在 PATHEXT 中列出。
I try to access some Excel data stored on a server and copy these files to another server ; the destination path should be different with the name of the file. Here is my code :
setlocal enabledelayedexpansion
net use Z: \\10.0.0.1\Statistiques
set path=Z:\
set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
echo %date%
for /f "delims=" %%a in ('dir *.xlsx /b /a-d "%path%" ') do (
set "name=%%~na"
set folder=Empty
if "!name!"=="!name:Client1=!" (
set folder=Client1
)
if "!name!"=="!name:Client2=!" (
set folder=Client2
)
copy "%path%%%a" "\\10.0.0.2\Documents\Statistiques\!folder!\%year%%month%%day%_!name!%%~xa"
)
net use Z: /delete
My issue is that the last 'net' is not recognized as an internal or external command, operable program or batch file.
On the first net use, the drive is correctly mount ; the files are correctly copied, but when I want remove the drive I have this error.
May be an error in my if () statement ?
PATH is an environment variable defined by Windows containing the directories in which command processor should search for executables or scripts with a file extension listed in environment variable PATHEXT. Run in a new command prompt window set path
or just set
to get the predefined environment variables displayed with their current values.
Your batch code contains:
set path=Z:\
This overrides the value of PATH defined by Windows and therefore command processor can't find net.exe
anymore as not being in current directory or in root directory of drive Z:
.
Use a different name for the environment variable which gets Z:\
assigned as value.
Best would be additionally for both occurrences of net to use
%SystemRoot%\System32\net.exe
This would avoid the need to search for net.*
by command processor in current directory and in all directories of PATH until a file is found with a file extension listed in PATHEXT.
这篇关于如果语句在批处理和应用程序不再被识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!