使用path.getrandomfilename后更改文件扩展名 [英] Change filename extension after using path.getrandomfilename
本文介绍了使用path.getrandomfilename后更改文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这是我的代码:
My.Computer.FileSystem.RenameFile(C:\\\\\\\\\\\\\\\\\ / pre> ..扩展名变为随机的,我不想要。我希望在使用代码Path.GetRandomFileName()时扩展名为.pdf。有人可以用正确的代码帮我吗?
我尝试过的事情:
Dim myFiles As String()
myFiles = IO.Directory.GetFiles(C:\ Application.exe,Path.GetExtension)
Dim newFilePath As String
For Each filepath As String in myFiles
filepath.Replace(。exe)
System.IO.File.Move(filepath,newFilePath)
Next
End Sub
End Class
解决方案
Path.GetRandomFileName() [ ^ ]返回一个字符串,所以可能是操作它的最好方法...
如果你不关心8.3格式:
string .Format( {0} .exe,Path.GetRandomFileName()。Replace( 。, string .Empty));
如果8.3格式很重要:
string .Format( {0} .exe,Path.GetRandomFileName()。Substring( 0 , 8 ));
/ *将文件格式转换为png * /
字符串newfilename,
string filename =〜 / Photo /+ lbl_ImgPath.Text.ToString(); / *从我们存储图像的特定路径获取文件名* /
string newfilename = Path.ChangeExtension(filename,。png); / *转换文件格式从jpg到png * /
So this is my code:
My.Computer.FileSystem.RenameFile("C:\j\Application.exe", Path.GetRandomFileName()).. The extension changes to something random, which I don't want. I want the extension to be .pdf while using the code Path.GetRandomFileName(). Can anybody help me with the right code, please?
What I have tried:
Dim myFiles As String() myFiles = IO.Directory.GetFiles("C:\Application.exe", Path.GetExtension") Dim newFilePath As String For Each filepath As String In myFiles filepath.Replace(".exe") System.IO.File.Move(filepath, newFilePath) Next End Sub End Class解决方案Path.GetRandomFileName()[^] returns a string, so probably the best way to manipulate it...
If you do not care for the 8.3 format:
string.Format("{0}.exe", Path.GetRandomFileName().Replace(".", string.Empty));
If the 8.3 format is important:
string.Format("{0}.exe", Path.GetRandomFileName().Substring(0, 8));
/*Convert file format to png*/
string newfilename , string filename = "~/Photo/" + lbl_ImgPath.Text.ToString();/*get filename from specific path where we store image*/ string newfilename = Path.ChangeExtension(filename, ".png");/*Convert file format from jpg to png*/
这篇关于使用path.getrandomfilename后更改文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文