I am trying to open a file path in Explorer using the .FollowHyperlink method and get errors on the strings with the "#" character. How do I format the string to make .FollowHyperlink ignore the wildcard functionality? For instance how would I format the following file path:
G:\Building\#500 Main St.\Loans\
You can use Shell for this:
Shell "C:\WINDOWS\explorer.exe ""G:\Building\#500 Main St.\Loans\""", vbNormalFocus
We can tell by looking at the documentation that the first argument is expected to be an Address which must follow the rules of a valid URI as defined in the RFC.
The hash # is a reserved symbol in the URI RFC.
You would have to URL Encode any string you pass in to it to avoid reserved symbols. There is no built-in method to URL encode strings in Access, but there is in Excel.
You can see a full discussion of URL Encode in VBA here:
How can I URL encode a string in Excel VBA?
Here is an example of your URL encoded local path:
FollowHyperlink("G%3A%5CBuilding%5C%23500%20Main%20St.%5CLoans%5C")
Related
I cant think of an OS (Linux, Windows, Unix) where this would cause an issue but maybe someone here can tell me if this approach is undesirable.
I would like to use a base64 encoded string as a filename. Something like gH9JZDP3+UEXeZz3+ng7Lw==. Is this likely to cause issues anywhere?
Edit: I will likely keep this to a max of 24 characters
Edit: It looks like I have a character that will cause issues. My function that generated my string is providing stings like: J2db3/pULejEdNiB+wZRow==
You will notice that this has a / which is going to cause issues.
According to this site the / is a valid base64 character so I will not be able to use a base64 encoded string for a filename.
No. You can not use a base64 encoded string for a filename. This is because the / character is valid for base64 strings which will cause issues with file systems.
https://base64.guru/learn/base64-characters
Alternatives:
You could use base64 and then replace unwanted characters but a better option would be to hex encode your original string using a function like bin2hex().
The official RFC 4648 states:
An alternative alphabet has been suggested that would use "~" as the 63rd character. Since the "~" character has special meaning in some file system environments, the encoding described in this section is recommended instead. The remaining unreserved URI character is ".", but some file system environments do not permit multiple "." in a filename, thus making the "." character unattractive as well.
I also found on the serverfault stackexchange I found this:
There is no such thing as a "Unix" filesystem. Nor a "Windows" filesystem come to that. Do you mean NTFS, FAT16, FAT32, ext2, ext3, ext4, etc. Each have their own limitations on valid characters in names.
Also, your question title and question refer to two totally different concepts? Do you want to know about the subset of legal characters, or do you want to know what wildcard characters can be used in both systems?
http://en.wikipedia.org/wiki/Ext3 states "all bytes except NULL and '/'" are allowed in filenames.
http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx describes the generic case for valid filenames "regardless of the filesystem". In particular, the following characters are reserved < > : " / \ | ? *
Windows also places restrictions on not using device names for files: CON, PRN, AUX, NUL, COM1, COM2, COM3, etc.
Most commands in Windows and Unix based operating systems accept * as a wildcard. Windows accepts % as a single char wildcards, whereas shells for Unix systems use ? as single char wildcard.
And this other one:
Base64 only contains A–Z, a–z, 0–9, +, / and =. So the list of characters not to be used is: all possible characters minus the ones mentioned above.
For special purposes . and _ are possible, too.
Which means that instead of the standard / base64 character, you should use _ or .; both on UNIX and Windows.
Many programming languages allow you to replace all / with _ or ., as it's only a single character and can be accomplished with a simple loop.
In Windows, you should be fine as long if you conform to the naming conventions of Windows:
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions.
As far a I know, any base64 encoded string does not contain any of the reserves characters.
The thing that is probably going to be a problem is the lengte of the file name.
I have an issue when trying to read a string from a .CSV file. When I execute the application and the text is shown in a textbox, certain characters such as "é" or "ó" are shown as a question mark symbol.
The idea is that this code reads the whole CSV file and then splits each line into variables depending on the first word of the line.
The code I'm using to read is:
Dim test() As String
test = IO.File.ReadAllLines("Libro1.csv")
Dim test_chart As String = Array.Find(vls1load, Function(x) (x.StartsWith("sample")))
Dim test_chart_div() As String = test_chart.Split(";")
variable1 = test_chart_div(1)
variable2 = test_chart_div(2)
...etc
I have also tried with:
Dim test() As String
test = IO.File.ReadAllLines("Libro1.csv", System.Text.Encoding.UTF8)
But none of them works. The .csv file is supposed to be UTF8. The "web options" that you can see when saving the file in excel show encoding UTF8. I also tried the trick of changing the file extension to HTML and opening it with the browser to see that the encoding is also correct.
Can someone advice anything else I can try?
Thanks in advance.
When an Excel file is exported using the CSV Comma Separated output format, the Encoding selected in Tools -> Web Option -> Encoding of Excel's Save As... dialog doesn't actually generate the expected result:
the Text file is saved using the Encoding relative to the current Language selected in the Excel Application, not the Unicode (UTF16-LE) or UTF-8 Encoding selected (which is ignored) nor the default Encoding determined by the current System Language.
To import the CSV file, you can use the Encoding.GetEncoding() method to specify the Name or CodePage of the Encoding used in the machine that generated the file: again, not the Encoding related to System Language, but the Encoding of the Language that the Excel Application is currently using.
CodePage 1252 (Windows-1252) and ISO-8859-1 are commonly used in Latin1 zone.
Based the symbols you're referring to, this is most probably the original encoding used.
In Windows, use the former. ISO-8859-1 is still used, mostly in old Web Pages (or Web Pages created without care for the Encoding used).
As a note, CodePage 1252 and ISO-8859-1 are not exactly the same Encoding, there are subtle differences.
If you find documentation that states the opposite, the documentation is wrong.
I am using Mule and Mule Expression Language to retrieve values form a properties file and change the contents of a connector address based on those values.
Example:
It would read test1 and test2 from the file and store in the variables ${user} and ${pw}. It would then use http://${user}:${pw}#testurl.com as the address for the connector.
Does Mule automatically escape strings when being used in an address? I would assume it doesn't and just uses the exact string provided. Is there a built in method in MEL that can be used to escape strings.
My concern is that the ${user} could contain a character that is required to be escaped to be interpreted literally, therefore causing an issue with the final url.
My solution if it can't be escaped would be to restrict the valid characters for those 2 parameters and I would like to avoid this.
MEL allows you to use standard Java method invocation so you could use any Java utility to URL encode the string such as URLEncoder - http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
For example:
#[java.net.URLEncoder.encode('${user}','UTF-8')]
I want to execute a shell command (I want to touch a file). I use system("shell command") to execute the command.
For example I want to touch the file at path /Users/username/New Folder/. Now I need to convert the NSString in a format that is conform to shell commands like /Users/username/New\ Folder.
Is there any method that does a conversion like this?
NOTE: It is NOT just replacing a whitespace with \. If you have a special character in the path like /Users/username/Folder(foo)/ the "shell path" looks like this /Users/username/Folder\(foo\)/
There is no need to convert the path, you can surround it in single quotes. Just use:
touch 'path'
You can enclose the parameters that contain spaces with " " marks.
touch "/Users/username/New Folder/"
At least this works at the shell prompt
Don't use system. It's insecure and unpredictable. Surrounding the string with quotes is not sufficient.
Use the execve style functions instead. They are simple and secure.
For various reasons, I have a bunch of static resources all with the following naming format:
xxxxx?yyyyy
where the x's are regular letter chars, and the y's numbers 0-9.
Apache is truncating the filename in the GET request at the "?" - as this is traditionally used to delinate query params - and thus reporting the followying error
file xxxx not found.
How can I get Apache to not think the y's are query args, and are actually part of the static file name?
Thanks very much for help,
Don
If you have control of how the URLs are being output, you can escape the '?' chars, This would be %3F instead of the '?'. The URL would therefore be
http://example.com/abcdef%3f99999