Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files with spaces

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
Is there any ways to prevent files with spaces when it is filtering files?

Thank you in advance
 
Private Sub Form_Load()
If Me.csvUpload Then
File1.Pattern = "*.csv"
Me.Caption = "CSV File Upload"
Else
File1.Pattern = "*.tcl;*.htm;*.html;*.jpeg;*.gif;*.swf;*.txt;*.pdf;*.css;*.xml;*.png;*.tar;*.tgz"
End If
End Sub

In this code, it takes only those files as above.
If file name is like "copy file1 a.html", I do not want to see this file when I do upload files.
How can I do that??

Thank you in advance
 
I'm not 100% sure I understand what you are doing but you could possibly use InStr() to see if the file name has a " " in it and if so skip the file in the upload????

Harleyquinn

---------------------------------
For tsunami relief donations
 
Yes...that's what I am trying.
If the file name has " ", skip the file in the upload..

 
File1.Pattern = "*.tcl;*.htm;*.html;*.jpeg;*.gif;*.swf;*.txt;*.pdf;*.css;*.xml;*.png;*.tar;*.tgz"

I have more than one file. how to apply your idea on it?
 
Private Sub Form_Load()

Dim objFSO As New FileSystemObject
Dim objFile As File

For Each objFile In objFSO.GetFolder(App.Path & "\").Files
If InStr(1, objFile.Name, " ", vbBinaryCompare) = 0 Then
Combo1.AddItem objFile.Name
End If
Next objFile

Set objFSO = Nothing
Set objFile = Nothing

End Sub
 
I suspect you are using the FileListBox control. There aren't any methods that I am aware of to remove files with spaces in their name from being listed.

Of course, there are smarted guys than me in here. Maybe they have a better idea.

The only way around this problem that I can think of would be to use a *regular* list box and fill the list box manually, using the method that vladk suggests.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Total agreement, I have been looking at it along the same lines. You may have to use an OR statement or something along those lines to only include files with the extention you are after.

Harleyquinn

---------------------------------
For tsunami relief donations
 
This is what I wrote..

If InStr(1, "*.html", " ", vbBinaryCompare) = 0 Then
File1.Pattern = "*.tcl;*.htm;*.html;*.jpeg;*.gif;*.swf;*.txt;*.pdf;*.css;*.xml;*.png;*.tar;*.tgz"
End If

well I tried this way..but it did not work..so..
 
So.. don't use that file list box. Use regular one and manage it via code. Look at my example. Set reference to Microsoft Scripting Runtime first and you will gain almost unlimited control over your files and directories.
 
This works for me..

Private Sub File1_Click()
If (InStr(1, File1.FileName, " ", vbTextCompare) <> 0) Then
File1.Selected(File1.ListIndex) = False
End If
End sub
 
>I do not want to see this file when I do upload files...
 
Although it prevents from highlighting, it also prevents from using arrow up/down - the navigating inside File1: the scrolling chocks on the unwanted files.
 
Yes...I did not want to see the files with spaces..
So...I think vladk's idea was good...
But it was difficult to change my current code using your idea...

So, Instead of not showing the files with spaces, I use that way..

Thank you for all your help

 
belig,

It is my pleasure. Your solution is very slick and efficient anyway!

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top