VBScript set IconLocation with commas in the file path name - vbscript

So I created this program that loops though all the lnk files in its folder and inserts an environmental variable into both the shortcut's target path and icon path. The problem is some of these target icons have a comma in the name, so when I use .IconLocation the file path cuts off after the comma and assumes the rest of the string is the icon index. Hence my question is how do you use .IconLocation and have a comma in the file path without it cutting of the rest of the string after the comma?

Related

SHParseDisplayName fails with ERROR_FILE_NOT_FOUND when passed existing directory whose name ends with a space character

I'm developing a file manager application, and noticed that some functions don't work with an existing folder that ends with a space symbol. E. g. "E:\1 \". This isn't specific to this particular folder, but indeed to any one with a space as the last character of the folder's name. For such folders, SHParseDisplayName returns ERROR_FILE_NOT_FOUND.
I'm calling SHParseDisplayName like so from C++:
ITEMIDLIST* idPtr = nullptr;
const auto result = SHParseDisplayName(L"E:\\1 \\", nullptr, &idPtr, 0, nullptr);
The documentation doesn't specify any edge cases, nor any ways in which the input path should be pre-processed. Regardless, I tried decorating it with quotes:
SHParseDisplayName(L"\"E:\\1 \\\"", nullptr, &idPtr, 0, nullptr);
And supplying a UNC path:
SHParseDisplayName(L"\\\\?\\E:\\1 \\", nullptr, &idPtr, 0, nullptr);
Both of which results in E_INVALIDARG.
Of note: SHParseDisplayName does work properly for items nested inside such a folder, e. g. L"E:\\1 \\some_internal_folder\\", just not the folder whose name ends with a space itself.
Is there any workaround? Windows Explorer seems to work just fine with such folders (as one would expect).
Also, SHParseDisplayName isn't the only Windows API function that fails for such folders. Another example of the same behavior is ILCreateFromPathW.
File and Folder names that begin or end with the ASCII Space (0x20)
will be saved without these characters. File and Folder names that end
with the ASCII Period (0x2E) character will also be saved without this
character. All other trailing or leading whitespace characters are
retained.
The Win32 API (CreateFile, FindFirstFile, etc.) uses a direct method
to enumerate the files and folders on a local or remote file system.
All files and folders are discoverable regardless of the inclusion or
location of whitespace characters.
Refer to "Support for Whitespace characters in File and Folder names"
And blog "MS-DOS also allowed spaces in file names, although vanishingly few programs knew how to access them.
So for existing files/folders with space at the end of names, either use Win32 API (CreateFile, FindFirstFile, etc.) or replace them with a new name without trailing or leading whitespace characters.

Regular expression in file path

I need to enter regular expression in a file path name inside tfileinputdelimited
I have a file watcher that is looking inside a directory for new files to be added. I want the new files have similar word for example file 1 is called apple1.csv and the other file that will be added at another time is called apple2.csv I want a way in order to tell talend to extract the file that contains the word apple, regardless of whats before or after.
Right now I have:
twaitforfile -> tflowtoiterate -> tfileinputdelimited -> tmap -> tdboutput
I believe tfileinputdelimited should have a regular expression as right now I selected a specific file
For the twaitforfile component, in the File Mask field specify the following: "*apple*.csv". This should grab only the files that have the word apple in them.
To dynamically grab these files base on their file names through tfileinputdelimited, you can use the FILENAME global parameter of the twaitforfile to achieve this:

Create a new Word document without invoking Word

I want to write a VBScript that will create a new Word document in the current directory. I've tried this sort of thing:
Set word = CreateObject("Word.Application")
Set document = word.Documents.Add()
document.SaveAs(filename)
It basically works, but I want to do it without invoking the Word application.
When I right-click in a File Explorer window, I get a pop-up menu that includes a "New" option from which I can select "Microsoft Word Document". This creates a new Word document in the current directory without invoking the Word application, and this is the action that I would like to perform in my VBScript.
Does anyone know how I can write that?
As a workaround, my existing VBScript copies an existing blank Word file to the current directory. This works pretty well. The one drawback is that the newly created file has the creation time and/or last-modified time of the original file. How can I "touch" the newly created file (again, without invoking Word) so that it appears to have been created "right now"?
What the New → Microsoft Word Document context menu entry does is basically a combination of your workaround and the answer Robin Mackenzie provided.
New document creation via the Explorer context menu is governed by these registry keys:
HKCR\.doc\Word.Document.8\ShellNew (Word 97/2003 documents)
HKCR\.docx\Word.Document.12\ShellNew (OOXML documents)
…
If the keys contain a string value FileName and the directory %windir%\ShellNew contains a file winword8.doc (for Word 97/2003 documents) and winword12.docx (for OOXML documents) the new document will be created as a copy of that file.
If no matching file exists in %windir%\ShellNew or the registry key contains an empty string value NullFile instead of the value FileName, new files will be created as a zero-length files (basically empty ANSI text file). Word automatically converts these files when opening them.
If the registry key contains neither a value FileName nor a value NullFile no context menu entry is displayed for the given file type.
If your script just needs to create a new empty document without any particular content or formatting I'd go with the approach Robin suggested. Otherwise stick with your current method of copying a template file.
You can try this which creates an empty text file and changes the extension to .docx. It's not a 'proper' empty docx file, but it will open as a blank new Word document.
Dim objFSO, strDoc, objFile
' create object to interact with file system
Set objFSO = CreateObject("Scripting.FileSystemObject")
'name of word doc to create
strDoc = "D:\test.docx"
' create blank file and close
Set objFile = objFSo.CreateTextFile(strDoc)
objFile.Close
' clean up
Set objFile = Nothing
Set objFSO = Nothing

QT: Escape slash / in saving location on a mac

I have HTML input I am supposed to extract 2 Strings of, build a document title string of type <string 1> / <string 2, create a PDF from the source on the users mac desktop and name it as described.
I do know that a slash in a document name is not such a brilliant idea but this is what I am asked to do.
Problem is: the forward slash is interpreted as a folder on the mac and not as part of the documents name which means QPainter fails to print to PDF because it interpretes string1 / being a folder that doesn't exist.
BTW when omitting the / my code is working fine.
How am I supposed to escape the /?
Here's the string building logic:
QString docTitle;
docTitle.append(string1);
docTitle.append(" / ");
docTitle.append(string2);
On OS X, the name of a file at the level of the APIs is different from the display name that is shown to the user in the Finder, open and save panels, etc.
At the level of the APIs, file names simply can't contain slashes. They are reserved for separating names within a path. There's no form of escaping or quoting to allow it.
However, you can create a file whose name will be displayed with a slash in the UI.
Basically, the slash (/) and colon (:) characters swap roles. The display names of files can't include a colon, because it's reserved. (This is a holdover of the old HFS file system used in Classic Mac OS.) So, one aspect of the conversion from names-in-the-APIs to display names is to convert from colons to slashes. Thus, if you want a file whose display name has a slash, you actually use a colon.
A file whose name as per the APIs is "Important legal document 06:13:2015.pdf" will be displayed in the UI as "Important legal document 06/13/2015.pdf". Likewise, if a user names a file in a save dialog or in the Finder as "Important legal document 06/13/2015.pdf", it will end up with a name which, when observed via the APIs, will be "Important legal document 06:13:2015.pdf".

SetCurrentDirectory to a path with dot at the end

Win32 SetCurrentDirectory() function failing to change current directory to a path with dot at the end, resulting GetLastError 2 (The system cannot find the file specified.).
What's wrong?
File names are not allowed to end in dots, and the behaviour is not guaranteed if they do.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
Do not end a file or directory name with a space or a period. Although
the underlying file system may support such names, the Windows shell
and user interface does not.

Resources