具有特殊类型的GetTempFolder [英] GetTempFolder with special type

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

问题描述

使用此功能,我得到一个随机名称,但是可以用扩展名.txt结束这些名称吗?



现在它是例如ibnke0jb.dp3。

 私人 功能 GetTempFolder()作为 字符串 
Dim 文件夹作为 字符串 = Path.Combine(Path.GetTempPath,Path.GetRandomFileName)
Directory.Exists(文件夹) File.Exists(文件夹)
folder = Path.Combine(Path.GetTempPath,Path.GetRandomFileName)
循环

返回文件夹
结束 功能

解决方案

是的,返回

< pre lang =vb> Path.ChangeExtension(文件夹, txt



这可以是您修改过的代码,也可以正确地进行文件检查 -



 私有 功能 GetTempFolder() 字符串 
Dim 文件夹 As 字符串 = Path.ChangeExtension(Path.Combine(Path.GetTempPath,Path.GetRandomFileName))
执行 while Directory.Exists(文件夹) File.Exists(文件夹)
folder = Path.ChangeExtension( Path.Combine(Path.GetTempPat h,Path.GetRandomFileName))
循环

返回文件夹
结束 功能





虽然这种重复真的让我感到烦恼xD


With this function I get a random name, but is it possible to end these name''s with the extension ".txt"?

Now it is for example ibnke0jb.dp3.

Private Function GetTempFolder() As String
       Dim folder As String = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
       Do While Directory.Exists(folder) Or File.Exists(folder)
           folder = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
       Loop

       Return folder
   End Function

解决方案

Yes, return

Path.ChangeExtension( folder, "txt")


This can be your modified code to do the file checking properly too-

Private Function GetTempFolder() As String
        Dim folder As String =  Path.ChangeExtension(Path.Combine(Path.GetTempPath, Path.GetRandomFileName))
        Do While Directory.Exists(folder) Or File.Exists(folder)
            folder = Path.ChangeExtension(Path.Combine(Path.GetTempPath, Path.GetRandomFileName))
        Loop
 
        Return folder
    End Function



Though that repetition is really bugging me xD


这篇关于具有特殊类型的GetTempFolder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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