


TXTname = "C:\CHRONOLOG\DT102T*" & mdcount & ". PRNname = "C:\Data_PRN\DT102T*" & mdcount & ".prn" ' Dim Sfile As String = Dir(PathName:="C:\Data_PRN\DT102T*" & mdcount & ".prn", Attributes:=FileAttribute.Normal) 'Dim Sfile As String = "C:\DT102T*" & mdcount & ".prn" MsgBox("Folder already exist", vbInformation, )ĭim md As System.IO.DirectoryInfo = CreateDirectory(MakeDirectory)Ĭonsole.WriteLine("File/Folder created at ", System.IO.File.GetCreationTime(MakeDirectory))ĭirector圜ount = System.IO.Directory.GetFiles("C:\Data_PRN\", "*.*", IO.SearchOption.AllDirectories).Length() If System.IO.File.Exists(MakeDirectory) = True Then txt = Dim PRNname As Stringĭim MakeDirectory As String = "C:\CHRONOLOG" please help! any suggestion will be appreciated. the last 2 digit of DT102T01 up to DT102T15 will count according to the number of files inside the Data_PRN folder. I have not tested the above with the "'" removed.Can anyone help me with this? im having trouble with renaming a file. The statement by removing the leading "'" character. Thanks Excel Facts Save Often Click here to reveal answer J Johnw MrExcel MVP Joined Messages 7,568 2 Use the Name statement in a Dir function loop. It should replace the existing file (in the same folder). Once you are sure it will do what you intend, uncomment Renaming is simply adding a fixed text string 'IMG' to the existing filename. The statement that actually renames is commented out. The script above outputs what it will do with a Wscript.Echo statement. Note this renames all files with extension ".txt" in the specified folder. Wscript.Echo strOldName & " : " & strNewName StrName = Left(strName, Len(strName) - 4) & ".bak" ' Change name by changing extension to ".bak" If (Right(LCase(objFile.Name), 4) = ".txt") Then Set objFolder = objFSO.GetFolder("c:\scripts") Set objFSO = CreateObject("Scripting.FileSystemObject") Option Explicitĭim objFSO, objFolder, objFile, strNewName, strOldName In the example below I change the extension from ".txt" to ".bak". You don't say how you would rename the file. Many people would use WMI to retrieve the file, but I find the FileSystemObject to be faster.
