有效的文件名 [英] Valid file name

查看:109
本文介绍了有效的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个简单的函数来测试一个字符串是否是一个有效的文件名(即

不包含非法字符等),而不是长篇大论?

谢谢


杰克罗素

解决方案

嗨杰克,


只需检查一下file.exists


如果文件存在,如果路径无效则它是一个有效的路径。


- 或者打开文件 - 用文件对话框提示用户。


希望这有帮助


亚当


Jack Russell写道:


是否有一个简单的函数来测试字符串是否是有效的文件名(即

不包含非法字符等)除了做很长的事情吗?


谢谢


Jack Russell


Adamz5写道:


嗨杰克,


S.暗示检查文件是否存在


如果文件存在则如果路径无效则它是有效路径。


- 或者打开文件 - 用文件对话框提示用户。


希望这有帮助


Adam


Jack Russell写道:


>>是否有一个简单的函数来测试一个字符串是否是一个有效的文件名(即
不包含非法字符等)除了做很长的事情之外?

谢谢Jack Russell




我试过文件存在(发布之前)名称无效 - a / b.txt和

它没有抛出异常(令我惊讶)


杰克


试试这个


问候


Adam


Imports System.IO


Public Class Form1


Private Sub Button1_Click (ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click

''Dim f As File


If File.Exists(" ; c:\ a / b.txt")然后

MsgBox(" validpath")

Else

MsgBox(" invalidpath")

结束如果


结束次级

结束班级


Is there a simple function to test if a string is a valid file name (i.e
does not contain illegal characters etc) other than doing it the long way?

Thanks

Jack Russell

解决方案

Hi Jack,

Simply do a check to see if file.exists

if file exists it is a valid path if not path was invalid.

--Or to open a file -- prompt the user with a file dialogue box.

hope this helps

Adam

Jack Russell wrote:

Is there a simple function to test if a string is a valid file name (i.e
does not contain illegal characters etc) other than doing it the long way?

Thanks

Jack Russell


Adamz5 wrote:

Hi Jack,

Simply do a check to see if file.exists

if file exists it is a valid path if not path was invalid.

--Or to open a file -- prompt the user with a file dialogue box.

hope this helps

Adam

Jack Russell wrote:

>>Is there a simple function to test if a string is a valid file name (i.e
does not contain illegal characters etc) other than doing it the long way?

Thanks

Jack Russell


I tried file exists (before posting) with an invalid name - a/b.txt and
it did not throw an exception (much to my surprise)

Jack


try this

regards

Adam

Imports System.IO

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'' Dim f As File

If File.Exists("c:\a/b.txt ") Then
MsgBox("validpath")
Else
MsgBox("invalidpath")
End If

End Sub
End Class


这篇关于有效的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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