Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


valid filename

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,57587
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> valid filename
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 valid filename - 3/6/2008 2:57:33 AM   
  diablo

 

Posts: 46
Score: 0
Joined: 3/4/2008
Status: offline
I want to create a textfile out of the text that was typed in the textbox "artikelTitel" butt the following character may not be in there: \ / : * " ? < > |

Dim bestand
Set filesys = CreateObject("Scripting.FileSystemObject")
'tempname = filesys.GetTempName
'Set bestand = fso.CreateTextFile("C:\DummyDTI\" & Replace(tempname, ".tmp", ".txt"), True)
Set bestand = fso.CreateTextFile("C:\DummyDTI\" & artikelTitel.value & ".txt", True)
bestand.Write(artikelTitel.value & vbcrlf & vbcrlf & artikel.value)
bestand.Close

How can I do this? an other problem that I have is the when I create a textfile on this way he won't upload this file to a ftp server in dos and when I create a random textname like you see in the code with a ' sign before.
 
 
Post #: 1
 
 RE: valid filename - 3/6/2008 3:02:35 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
So what do you want to do with invalid characters? Replace them with something else? Just remove them? Prompt the user for a different name? Why do you generate a temp file name if you are using the value of a text field for the file name?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to diablo)
 
 
Post #: 2
 
 RE: valid filename - 3/6/2008 6:59:28 PM   
  diablo

 

Posts: 46
Score: 0
Joined: 3/4/2008
Status: offline
quote:

ORIGINAL: ebgreen

So what do you want to do with invalid characters? Replace them with something else? Just remove them? Prompt the user for a different name? Why do you generate a temp file name if you are using the value of a text field for the file name?


The tempname is in comment I just want to delete these invalid characters example: "day: 1" becomes "day 1"...

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: valid filename - 3/6/2008 8:19:20 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi diablo,

the best way to delete all forbidden chars (or better: all chars not allowed) from
a string is to use a RegExp. The .Pattern should define the characters to remove
([:/ ...] or [^a-zA-Z0-9 ...]) and the .Replace method will do the work:

   sClean = oRE.Replace( sDirty, "" )

Good luck!

ehvbs

(in reply to diablo)
 
 
Post #: 4
 
 RE: valid filename - 3/6/2008 9:14:06 PM   
  diablo

 

Posts: 46
Score: 0
Joined: 3/4/2008
Status: offline
So this should work:

Set filesys = CreateObject("Scripting.FileSystemObject")

Set myRegExp = New RegExp
myRegExp.Pattern = "\/:*"?<>"
dim titelnaam
titelnaam = myRegExp.replace(artikelTitel.value, "")

Set bestand = fso.CreateTextFile("C:\DummyDTI\" & titelnaam & ".txt", True)
bestand.Write(artikelTitel.value & vbcrlf & gebruiker.value & vbcrlf & artikel.value)
bestand.Close

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: valid filename - 3/6/2008 9:23:41 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
No, I don't think so: you need [] to specify a character class and the
" has to be 'escaped' (in the VBScript way):

myRegExp.Pattern = "[\/:*""?<>]"

(in reply to diablo)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> valid filename Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts