Jump to content

renaming file with ASP


Recommended Posts

Hi all,A part of my daily job is to download a batch of files without file extension and I have to rename them with .txt. I've implemented a page to do so. However, there are always a few files with double extensions, ie filename.txt.txtI really have no idea where has gone wrong. It would be great if someone could help me out here. Many thanks in advance. The following is asp code i wrote.<%Dim StrVPath, StrPPathStrVPath = request.ServerVariables("PATH_INFO")StrPPath = Server.MapPath(StrVPath)Dim ObjFSO, ObjFile, ObjFolder, ObjFileItemDim ObjFolderContents, NewName, OldNameSet ObjFSO = CreateObject("Scripting.FilesystemObject")set ObjFile = ObjFSO.getFile(StrPPath)set ObjFolder = ObjFile.ParentFolderset ObjFolderContents = ObjFolder.FilesResponse.Write("Renaming")For Each ObjFileItem in ObjFolderContents newName = null oldName = null If UCase(Right(ObjFileItem.Name, 4)) <> ".ASP" Then 'Response.Write "Filename: " Response.Write "<br>" oldName = ObjFileItem.Name nameLen = Len(oldName) if nameLen = 9 then for i = 1 to nameLen if i <> 5 then 'response.write(i) 'response.write(mid(oldName,i,1)) newName = newName & mid(oldName,i,1) end if next newName = newName & ".txt" response.write("<b>" & newName) ObjFileItem.Name = newName newName = "" else oldName = oldName & ".txt" Response.Write ("<b>" & oldName) ObjFileItem.Name = oldName oldName = "" end if end ifnext%>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...