㈠ VB中重命名文件名
把D:\test\目录下的所有抄jpg文件重命名为pic###.jpg的代码袭:
Dim i As Integer
i = 1
Set fs = CreateObject("scripting.filesystemobject")
Set fd = fs.GetFolder("d:\test")
For Each f In fd.Files
If LCase(f.ShortName) Like "*.jpg" Then
f.Name = "pic" & Format(i, "000") & ".jpg"
i = i + 1
End If
Next
如果文件名已确定,可以用Set f=fs.GetFile("[完整路径和文件名]"),然后用f.Name="[新文件名]"
另外提问的时候要注意把已知的条件和要达到的效果说清楚,“已知文件名的若干文件”到底是什么样的文件名,有没有什么规律?是否在同一文件夹下?或者是否已将文件名存放在一个字符串数组中?不说清楚别人怎么能帮你,只能给你一个实现的思路了
㈡ VB中如何重命名文件夹
可以创建这个文件夹。
int i;
private void button1_Click(object sender, EventArgs e)
{
i++;
System.IO.DirectoryInfo FilePictures = new System.IO.DirectoryInfo(@"..\..\picture" + i);
if (!FilePictures.Exists)
{
FilePictures.Create();
}
}
㈢ VB怎么重命名文件
Name"D:新建文件夹a.txt"As"d:新建文件夹.txt"
㈣ vb 文件改名
VB改名可以用name方法
Name oldpathname As newpathname
Name 语句的语法具有以下几个部分:
oldpathname 必要参数。字符串表达式,指定已存在的文件名和位置,可以包含目录或文件夹、以及驱动器。
newpathname 必要参数。字符串表达式,指定新的文件名和位置,可以包含目录或文件夹、以及驱动器。而由 newpathname 所指定的文件名不能存在。
Name 语句重新命名文件并将其移动到一个不同的目录或文件夹中。如有必要,Name 可跨驱动器移动文件。 但当 newpathname 和 oldpathname 都在相同的驱动器中时,只能重新命名已经存在的目录或文件夹。 Name 不能创建新文件、目录或文件夹。
在一个已打开的文件上使用 Name,将会产生错误。必须在改变名称之前,先关闭打开的文件。Name 参数不能包括多字符 (*) 和单字符 (?) 的统配符。
经查阅MSDN里,VB里没有moveto方法改名,其他语言有~~下面是MoveTo 方法
MoveTo Method (Folder Object)
The MoveTo method relocates the Folder object to another folder hierarchy location.
Syntax
Set objMovedFolder = objFolder.MoveTo(folderID [, storeID ] )
objMovedFolder
On successful return, contains the moved Folder object.
objFolder
Required. This Folder object.
folderID
Required. String. The unique identifier of the new parent Folder object, that is, the Folder object under which this folder is to appear as a subfolder.
storeID
Optional. String. The unique identifier of the InfoStore object in which this folder is to appear, if different from its current InfoStore.
Remarks
All subfolders of this folder, together with all Message objects contained within this folder and its subfolders, are moved along with the folder itself.
The move operation takes effect immediately. This Folder object is no longer accessible at its former location after the MoveTo method returns.
㈤ 如何用vb修改文件名
二次补充:肯定没问题了,把其他功能都去掉了,只剩下改名和删除,如果想吧删除去掉,就去注释的那一句。
============
建一个Command1,如果需要,建立Command2。
代码如下。
============
Dim t As Integer, s As String
Private Sub Command1_Click()
Name "c:\abc\temp_" & t & ".txt" As "c:\abc\temp.txt"
Kill "c:\abc\temp.txt" '不删除的话去掉这一句
t = t + 1
If t = 151 Then End '比方说你想进行到文件150,就要写上151
End Sub
Private Sub Form_Load()
t = 121
End Sub
㈥ 在VB中如何重命名一个文件
用重命名语句,例如把C盘的格式为mp3,文件名为A的改为B:Name C:\A.mp3 As C:\B.mp3
㈦ vb窗体文件怎么重命名
VB6中执行“文件”菜单中的“Form1另存为”(Form1代表你当前窗体名称),或者在工程资源管理器窗口,右击要重命名的窗体,在弹出的快捷菜单中执行“Form1另存为”(Form1代表你当前窗体名称)。
窗体文件重命名后,一定要保存工程文件
㈧ 用VB批量重命名文件,如何实现
方法一:Dim fpPrivate Sub refilename(folderspec)Dim fs, f, f1, fc, sm, hzSet fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)Set fc = f.FilesFor Each f1 In fc
hz = Mid(f1.Name, InStrRev(f1.Name, "."))
Name f1 As fp & "20101007-" & hz
NextMsgBox "修改完成"End SubPrivate Sub Command1_Click()fp = "E:\emot\xhh\"'这里设置文件夹路径,根的需要来修改
If Right(fp, 1) <> "\" And Right(fp, 1) <> "/"
Then fp = fp & "\"Call refilename(fp)
’调用上面的自定义函数,改名End Sub........
方法二: '将f:\123\文件下的txt文件改名
Dim files() As String '用于贮存文件名
Dim length As Integer = 0 'files数组长度
Dim fileName As String = Dir$("f:\123\*.txt") '得到第一个.txt文件的文件名
'Dim g As Graphics = Me.CreateGraphics
Do While fileName <> ""
'g.DrawString(length, Font, Brushes.Red, length * 10, length * 10)
ReDim Preserve files(length)
files(length) = fileName
length = files.Length
fileName = Dir$() '得到下一个.txt文件的文件名
Loop
For i = 0 To length - 1
Dim oldfileName As String = "f:\123\" + files(i)
Dim newfileName As String = "f:\123\" + "20101007_"+ files(i)
Rename(oldfileName, newfileName) '修改文件名
Next