Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileSystemObject CopyFile with wildcard copies files with extensions longer than specified

Tags:

vb6

fso

In the source folder there are 3 files:

  • a.csv
  • b.csv
  • a.csv_backup

I would expect *.csv to copy a.csv and b.csv only, but it copies a.csv_backup as well.

Code:

Dim oFso As New Scripting.FileSystemObject
oFso.CopyFile "c:\temp\*.csv" "d:\temp\"
like image 842
GaneshT Avatar asked Dec 01 '25 01:12

GaneshT


1 Answers

You're running into the fact that each file has a "short name" (the old DOS 8.3 standard) for compatibility with really old software (some of which is still kicking around). Your file a.csv_backup is also known by another name (probably something like a~1.csv though it could be about anything) which only uses the first three letters of the extension. You can run dir /x to see the short names alongside each long name.

Further reading:

  • On Superuser: Windows wildcards with files having more than 3 characters extensions
  • From Raymond Chen (Developer who has worked on Windows for a very long time): Why does FindFirstFile find short names? (about the API used internally by many applications to look for files by pattern)
  • Wikipedia: 8.3 filename

In terms of a solution, you either need your backup extension to not share the first three characters of what you're searching for (so use something like .backup_csv instead), or you need to disable short names on your system (which can break old applications).