防止使用cmd覆盖文件(如果存在) [英] Prevent overwriting a file using cmd if exist

查看:104
本文介绍了防止使用cmd覆盖文件(如果存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在编写一个执行安装文件的.bat批处理文件.在运行安装文件之前,我先检查该目录是否存在,以避免重新安装该应用程序.

I am currently writing a .bat batch file that executes an installation file. Before it runs the installation file I check to see if the directory exists to avoid re-installing the application.

我通过使用If Not Exist filename语句来做到这一点.如果安装的文件不存在,则执行安装文件.

I do this by using a If Not Exist filename statement. If the installed file doesn't exist, I then execute the installation file.

由于某种原因,当我使用已经安装了该应用程序的应用程序对其进行测试时,它仍在尝试通过该应用程序重新安装该应用程序.

For some reason, when I test it with the application where it has been installed already, it is still trying to reinstall the application over it.

这是我的代码的片段:

cd "C:\Documents and Settings\John\Start Menu\Programs\"
pause
If NOT exist "Software Folder"\ (
 start \\filer\repo\lab\"software"\"myapp"\setup.exe
 pause
) 

SoftwareFolder"C:\Documents and Settings\John\Start Menu\Programs\".的子目录,我正在检查它是否在我的Programs文件夹中.

Where SoftwareFolder is a subdirectory of "C:\Documents and Settings\John\Start Menu\Programs\". I am checking to see if it exists in my Programs folder.

我知道我的start命令没有问题.我觉得我的CD开始命令或其参数之一有问题.

I know nothing is wrong with my start command. I have a feeling something is wrong with my beginning CD command or one of its parameters.

非常感谢,伙计们!

推荐答案

使用如果不存在"代码中文件夹的完整路径.然后,您甚至都不需要CD:

Use the FULL path to the folder in your If Not Exist code. Then you won't even have to CD anymore:

If Not Exist "C:\Documents and Settings\John\Start Menu\Programs\SoftWareFolder\"

这篇关于防止使用cmd覆盖文件(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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