Jump to content
UBot Underground

Recommended Posts

Sometimes you scrape the web and want to create a folder on your computer with for instance the title of a post that you scraped from the web, but that title might contains characters (so called "illegal characters") that you are not allowed to use in Windows for saving files.

If so it will result in an error "Illegal characters in path" (or something similar).

 

To prevent this you should remove these characters before saving or creating files and folders.

 

Following this article http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29 it shows that the following characters are considered "illegal" when it comes to file names:

 

  • < (less than)
  • > (greater than)
  • : (colon)
  • " (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)

 

So if you want to create a folder or save a file and use text that you scraped from the web, save yourself some issues and always Set the text in a variable and $replace regular expression that variable and then finally save it.

 

Here is just an example code that has some text with illegal characters, the illegal characters get replace with nothing.

I know the folder on your desktop still contains some weird characters, but these are not illegal, and thus allowed to use.

This is just an example of course.

 

Here is the code:

set(#test, "te*st!@\"\\[\\^\\.*@-\\]\\\\/\\_-HAHA:49;6,^;*|/\\?><=", "Global")
set(#test, $replace regular expression(#test, "[@,\"^:;*|\\/?><=\\\\/]", ""), "Global")
create folder($special folder("Desktop"), #test)

Eventually a default function for this in uBot would save this extra step (for instance Save to file, Create folder, etc.) should do this automatically.

Or does anyone know a valid reason why not?

Let me know.

 

I hope this tutorial helps someone :)

 

Have a good one ;)

 

 

 

  • Like 3
Link to post
Share on other sites
  • 2 months later...

I have ubot standard edition can you explain to me exactly how i would set that up.

I get the set to variable but what is "te*st!@\"\\[\\^\\.*@-\\]\\\\/\\_-HAHA:49;6,^;*|/\\?><=" is that some kind of wild card?

 

Don't worry I figured it out but thanks for the example.

Edited by bitterbrowns
Link to post
Share on other sites
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...