如何设置批处理文件以查找文件并显示其位置?

时间:2013-05-03 06:25:13

标签: file batch-file path

我需要这个基本程序。到目前为止,我能做的是跟踪预定义文件是否存在,但不是更多。 我正在尝试这样做:

  1. 选择文件
  2. 查看是否存在
  3. 找到它的路径
  4. 将路径保存在变量或类似的
  5. 之下
  6. 显示用户的路径
  7. (执行文件,可选)
  8. 有没有办法做到这一点,脚本是什么? 如果我不清楚,请告诉我。 提前致谢

1 个答案:

答案 0 :(得分:0)

@echo off
setLocal
set /p file=choose a file: 
set /p option=do you want to execute the file?[y/n]
if "%option%" equ "y" set /p directory=directory where you want to execute the file:
if "%option%" equ "Y" set /p directory=directory where you want to execute the file:

if not exist "%directory%\" echo directory does not exist %% exit /b 3    


if not exist %file% echo file does not exists && exit /b 1
for %%F in (%file%) do ( 
  set file_atr=%%F
  set full_path=%%~fF
)
if "%file_atr::~0,1%" equ "d"  echo this is a directory && exit /b 2

echo the full path is : %full_path%
if "%option%" equ "y" (
  pushd %directory%
  call  %full_path%
  popd

)
if "%option%" equ "Y" (
  pushd %directory%
  call  %full_path%
  popd

)
endLocal