We need something like FileMove, the counterpart to FileCopy, but it only exists, to my knowledge, when using fso.MoveFile which does not allow the use of wildcards. I know using wildcards is risky, but I'm certain I can identify a unique file. If you know of a way to rename the file, old or current name with wildcards, to new name known in its entirety, it would really speed things up. Fortunately the first line of code, fn, identifies the precise file that needs deleting. The following code describes to copy all files from one directory to another directory using FileSystemObject in vb 6.0 This example requires a form with one CommandButton control named ‘Command1’.
At this point it's the best thing I have going. If you are not able to find this in the list than locate Scrrun.dll on your system. I then go back into the old folder and delete the old file. However, the need for wildcards over rides the time requirement.įn = Dir(myDir & Movie_Actor_Name1 & "*") ' Movie_Actor_Name1 & "*") is old name with wildcardįileCopy myDir & fn, newFolder & Replace(fn, Left(fn, InStr(fn, ".") - 1), Movie_Actor _ Name2) ' Movie_Actor_Name2 is the new, correct name or I should say had 3 problems, 1) I need to use wildcards, 2) some files (more then half) need to be renamed and 3) I would prefer to just move, not copy, because some of these fi les are movies and are large (> 1GB) to copy takes too long. Ch Dir () whatever directory these files are located in Dim stOldName as string, stNewName as string stOldName whatever syntax would go here to sense the 'next' file stNewName '200408' & mid (stOldName,7,3) & '. I don't really need to copy a file, just move it, and in certain cases rename it. Your code needs to be highlighted! I have been searching for this for days now. Answer Graham Mayor MVP Replied on JanuAssign the two names to string variables then use the following to delete and rename Dim sName1 As String Dim sName2 As String Dim fso As Object Set fso CreateObject ('Scripting.FileSystemObject') sName1 'C:PathTextFile. I realize the post is over 3 years old but I see you’re still active. Again as an observation, why do you use local names for the subs. Public Sub CopieEtRenomme (NewName As String, ext As String) : copy and. Public Sub renomme (NewName As String): rename. Re: File copying & renaming using VBA & WildCards Public Property Get nomfichier () As String : get file name.