String problem when executing a VBScript from within a batch file - string

I have a batch that I am running at the end of an installer process so that the end-users have as minimal an input as possible.
Everything with the .exe and the batch file are functioning grand. I have got a generic VBScript that performs the function of finding a string and replacing it. I have tested it on a simple string in the batch file and it works fine as below to activate the VBScript and make it perform the find and replacement.
Find_And_Replace.vbs "46233.xml" "DuchessLoco_1" "DuchessLoco_10"
The problem comes that I want the strings to Find and Replace to be far more detailed and it cannot read the characters that I'm typing in to the quotation marks.
I gather this may be because the batch itself understands certain characters that need escaping and then the VBScript will require other ones escaping in a different way. This is where my understanding is letting me down - but I am loathe to make the vbs file more bespoke as it being generic suits the fact I will have multiple different uses for it with multiple different installers over time. Below is an example of the string that I want to Find and modify. The VBScript is executing but not finding hence replacing the string likely due to my errors.
c:"deltaString">DuchessLoco_1</Name>
I have put this in my code as:
"c:\"deltaString\">DuchessLoco_1</Name>"
and this is the string that is failing to be found by the VBScript- I shall later need to move on to using more complex characters such as Tab and New line, so if it isn't possible via this method I will have to rethink my approach to the problem.

Related

How can Python be forced to use raw string equivalent of variable-stored paths on Windows?

It might seem that this question has been asked hundreds of times, but reading every variant of it, it's clear it has never been fully answered, at least not in the context I am experiencing.
I have a filename variable that is being obtained through a dialog (in Blender), and I need to both use the file name and iterate over its directory. The problem is that Python cannot properly convert the backslashes to forward slashes.
Here is the filename: 'D:\scans\testing\2021_12_01_14_41_38\frame_00000.json'
Storing this in a variable yields 'D:\scans\testing\x821_12_01_14_41_38\x0crame_00000.json'.
In other words, once the dialog passes the filename to the variable, nothing more can be done with it. The file itself may be opened, but attempting any other operation on it automatically converts the escape characters.
Here are some other approaches I have tried:
Attempting a find replace using filename.replace('\\','/') yields 'D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json'.
Using pathlib.Path(filename) yields a WindowsPath object:
WindowsPath('D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json')
All I need is the directory and the file separated, but even os.path.basename yields
'testing\x821_12_01_14_41_38\x0crame_00000.json'.
Even trying repr(filename) is to no avail. It yields "'D:\\scans\\testing\x821_12_01_14_41_38\x0crame_00000.json'"
re.sub('\\\\','/',filename) yields 'D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json'
It's mind boggling that such a simple operation on Windows is so complicated, as I have done it millions of times on Linux (yes, I know). Unfortunately, I cannot use the raw string method (r'string') because this is a variable, not a string. I have seen crazy ideas out there such as r'{}'.format(variable), but that doesn't work for obvious reasons.
I could list hundreds of other failed attempts, including abspath, relpath, and find / replace, and they all lead nowhere. Surely, there is a way to take a full-path filename from a dialog in Windows (in this case, Blender) and split the directory and filename apart?
If you have any ideas how I might work around this problem, please share.
You can try removing the inverted commas form the string while using the variable which has the string stored in it.
I was trying to find file size where file path was chosen by user:
import os
take input on file path
file_path = input("Enter file path without inverted commas:")
prints the size of the file in bytes
print(os.path.getsize(file_path))
Note:
When I copied the path it was copied like this:
"D:\Dev\repo\t1_old\task.py"
So I had to remove the inverted commas, only then the os.path.getsize(file_path) worked.
If I did not remove inverted commas while entering the file path, it gives an error

Removing all special characters from a string that cannot be used inside the command line (python)

I'm making a tk application in which I have to execute a command line application (MP4Box) from python, using subprocess.check_call().
The filename (used in the command) is retrieved from youtube and hence has all types of special characters. I want to remove all characters that can't be used as filenames in the Operating system also btw (i want the implementation would work across multiple platforms)
I tried the solution over here
. windows seems accept the filename but but it returns an error with subproces.check_call().
I tried manually removing the special char from filename and it works good after that. so it isnt a problem with the command.
EDIT:
For eg, i tested for this video. The solution in above link won't remove 'รค' and cause a problem in the command line.
I eventually found the correct answer. Ascii did the trick :)
''.join([t for t in <filenmae> if t.isalnum()]).encode('ascii', 'ignore'))

Search substring in binary file

friends! Please, help me with my issue. I have an application which processes data and generates output files (different formats, but mostly images). In every generated file that application puts it's watermark - string, that looks like "03-24-5532 [some cyrillic text]".
And every time I use that application, I need to edit each file in photoshop to replace watermark string with required one and it takes a lot of time.
Is this possible to search that substring in application binary data files (using Hex Editor or something else) and replace? Which is the better way to solve this problem?

Serialized Printing Method

I am looking for a method by which I can print one document, and have a field that is incremented on each copy printed. I currently run linux, so bash in concert with several programs might be the way to go, but I'm just not sure where to start.
I have a document that is used for our business that currently is hand stamped for serialization... We would like to simply print them but cant find a method by which to increment a specific field. I would like to use either a PDF or an ODF/ODT for the document.
Thanks for any help you can give!
How is the document produced at the first place?
If you master that process, you could certainly add serialization at that level. For instance if using LibreOffice you could do that in LibreOffice. If using a text formatter (like LaTeX, Lout, ....) just emit the formatting instructions (e.g. the .tex or .lout source file) with some unique counting (perhaps simpler to do in some scripting language like Python or Ocaml).
Then run the relevant tool to get a .pdf file.

Using different program office extension

I have a program that can access a database with a whole bunch of articles.
Due to copyright, I can't access the database straight from my program, but I have a different program that can access it, and it's legitimate to copy small bits from the articles.
Because my friends and I quote a lot from these articles, I thought it would be useful if we could find an add-in for Word that will copy the requested part from an article.
Is there any add-in for Word that would let me use the program that I mentioned above so that I can access the database from within Word?
I would like to program this add-in myself, if possible.
Without further information about which operating system, and version of Word you are using, I can offer only a general outline.
1) It seems to me that you want to make a Word macro using Word Basic, or Visual Basic.
2) When you want to call your program which is external to Word, you need to use the shell command as outlined here from Microsoft's webpage.
I hope that helps you get started writing your macro!
CHEERS
Well its a wrokaround but you can use an automation tool which can run a sequence of actions on a given GUI like Winrunner or TestQuest to semulate the usage of the program, i assume these tools can get an input from a given xml or text file and log outputs in log text file.
If you have the output in a text file you will be able to parse the file using any programmign language and get the information you need and write it to eord or whatever format using OLE objects.

Resources