Validation 如何验证inputdialog中给定的路径?
我正在尝试验证inputdialog中给定的路径Validation 如何验证inputdialog中给定的路径?,validation,vim,input,Validation,Vim,Input,我正在尝试验证inputdialog中给定的路径 "a = path to file p.e. d:\mydoc.txt (but can be every file) let a = inputdialog(docinput) while 1 try read (a) catch /E484:/ echo "The file doesn't exist" let a = inputdialog(docinp
"a = path to file p.e. d:\mydoc.txt (but can be every file)
let a = inputdialog(docinput)
while 1
try
read (a)
catch /E484:/
echo "The file doesn't exist"
let a = inputdialog(docinput,a,"return")
if a == "return"
return
endif
endtry
endwhile
我想使用read
命令检查文件名是否存在。但似乎
read
无法读取变量。read
必须是这样的:读取d:\mydoc.txt
1) 如何读取变量
如果read
给出错误消息(E484(无法读取文件)),脚本必须返回到inputdialog。我尝试在while/endwhile循环中使用try/endtry来实现这一点,但我还没有找到如何打破循环 2) 如果文件不存在,如何将脚本返回到inputdialog?
- 必须使用
:执行
:读取
变量
中包含的文件名:a
execute "read " . a
对于作业来说是错误的工具,请改用:read
(或filereadable()
,具体取决于您要对该文件执行的操作):filewriteable()
我不明白你的第二个问题。Romaill,谢谢!我成功了。:)这也解决了我的第二个问题。顺便提一下我为读者更新了我的第二个问题。
if filereadable(expand(a))
" do something
else
" do something else
endif