473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Commas in Scripting.FileSystemObject

Hi This code works great unless there is a comma in the filename:

Expand|Select|Wrap|Line Numbers
  1. Dim dir, folder, files
  2. dir = "c:\ValidateFiles\"
  3. Set fso = CreateObject("Scripting.FileSystemObject")
  4. Set folder = fso.GetFolder(dir)
  5. Set files = folder.files
  6.  
  7. lstFiles.RowSourceType = "Value List"
  8. For Each file In files
  9. If Right(file.Name, 3) = "xml" Or Right(file.Name, 3) = "XML" Then
  10. lstFiles.AddItem (file.Name)
  11. End If
  12. Next
If a comma exists the file is added to the list, but stops at the first comma.

Example:

Test File 1.xml works fine.
Test, File 1.xml only add "File" to the list.

What am I missing?

Thanks,
John
Mar 25 '13 #1

✓ answered by zmbd

1) Even if the OS allows it, it is not considered best practice to use non-alphanumeric characters other than the underscore in file names, field names, table names, etc... and your problem is just such one case in point. (IMHO: Even spaces should never be used!)

2) You should not use reserved/key/token-words such as "File," "Folder," "Database," etc... as names for your variables. If you do want to use these words then you should preface (or affix) "me" or "obj" etc to the variable name.

Using reserved words will cause you issues!
Access 2007 reserved words and symbols
(...)You might also encounter errors if you use a reserved word to name a control, an object, or a variable. The error messages you receive don't necessarily tell you that a reserved word is the cause of the problem. As a result, it can be difficult to identify what needs to be changed.



-->
To directly address your issue: what you'll need to do is place the file name within quotes such as you would if the name had/has spaces within it.

IMHO: the best way is to use a string variable... and because using double quotes is a pain, I'll break my rule this time on posting code ;-) :
Expand|Select|Wrap|Line Numbers
  1. '(..>preface Code Omitted<..)
  2. Dim strADDMe as String
  3. '(..>Code Omitted<..)
  4. strAddMe = """" & objfile.Name & """" '<<< Note I prefixed obj to the variable!
  5. lstFiles.AddItem (strAddMe)
  6. '(..>Closeing Code Omitted<..)

2 2015
zmbd
5,501 Expert Mod 4TB
1) Even if the OS allows it, it is not considered best practice to use non-alphanumeric characters other than the underscore in file names, field names, table names, etc... and your problem is just such one case in point. (IMHO: Even spaces should never be used!)

2) You should not use reserved/key/token-words such as "File," "Folder," "Database," etc... as names for your variables. If you do want to use these words then you should preface (or affix) "me" or "obj" etc to the variable name.

Using reserved words will cause you issues!
Access 2007 reserved words and symbols
(...)You might also encounter errors if you use a reserved word to name a control, an object, or a variable. The error messages you receive don't necessarily tell you that a reserved word is the cause of the problem. As a result, it can be difficult to identify what needs to be changed.



-->
To directly address your issue: what you'll need to do is place the file name within quotes such as you would if the name had/has spaces within it.

IMHO: the best way is to use a string variable... and because using double quotes is a pain, I'll break my rule this time on posting code ;-) :
Expand|Select|Wrap|Line Numbers
  1. '(..>preface Code Omitted<..)
  2. Dim strADDMe as String
  3. '(..>Code Omitted<..)
  4. strAddMe = """" & objfile.Name & """" '<<< Note I prefixed obj to the variable!
  5. lstFiles.AddItem (strAddMe)
  6. '(..>Closeing Code Omitted<..)
Mar 25 '13 #2
Thank you for the quick response. I'll modify the code to incorperate your suggestions. Unfortunately I have relatively little control over the inport file names.
Thanks again,
John
Mar 25 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark | last post by:
I'm having intermittent trouble with the Scripting.FileSystemObject. Basically, I'm stress testing my ASP application and using the FSO to output lots of instrumentation/debug information to the...
0
by: Giorgio Cervati | last post by:
Hi everybody, found strange behavior in Scripting.FileSystemObject; only FileExists() method seems to work fine. All other methods cause browser to indefinitely wait for something that never come....
3
by: PB4FUN | last post by:
If I comment #2 to #5 no problems. If I uncomment #2, #4 and #5 the page hangs. Even did not reach the point to uncomment #3 So, whats wrong. Do i have to alter some serversettings, and if so,...
3
by: Wayfarer | last post by:
Hi, I've got a freebie hosting mirror of my production personal website (sounds kinda grandiose, doesn't it?) at http://journeys.webhostme.com/. At the production website I was using...
2
by: Lin Ma | last post by:
Greetings, Is it possbile to check a file exist without using Server.CreateObject("Scripting.FileSystemObject") in asp page?? The reason is our hosting company turn that function off for...
3
by: bt | last post by:
I am just beginning with asp and have gotten an error that I need some help with. I posted a pair of files to an online ASP host server. The files are in the same directory; one is readfile.asp...
2
by: Stavros | last post by:
Hi all when I execute the following VB6 code in Windows 2000 and as an Administrator, everything is working fine. Project->References->"Microsoft Scripting Runtime" and scrrun.dll is located...
5
by: VancouverMike | last post by:
Hi there, I am writing a web app using asp.net 1.1 and C#. This web app is launched in another win32 application and this app needs to pass information to my web app. But this win32 application...
1
by: pbd22 | last post by:
Hi - I have code that automatically fills tabs on a page. In some cases, a URL path won't be correct (the folder and files don't exist) and, in these cases, I want to catch these exceptions and...
1
by: ether | last post by:
Hi, I am using following function to check for a file on client it works for IE after setting browser security to low level but does not work for Firefox. please provide me information whether their...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.