Batch Printing files to new folder as PDF's - powershell

I have a folder of 2000+ PDF files that I need to print and resave as new PDF files in a separate folder using the original file name. Is there a way to do this in powershell or using a CMD?
I have tried to select multiple files in the folder to print at the same time by right clicking and selecting the print option. However this gets stuck at the window requesting a new file name and a destination folder which I am unable to provide as each file needs to have the original file name.
// the directory to store the output.
string directory = Environment.GetFolderPath
(Environment.SpecialFolder.MyDocuments);
// initialize PrintDocument object
PrintDocument doc = new PrintDocument() {
PrinterSettings = new PrinterSettings() {
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.Print();
I would like to see the new PDF file saved as a new PDF in the destination directory folder with the same file name as the origin directory.
Origin Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\NonRedacted --> Origin File name "Random_Name.PDF"
Destination Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\Redacted --> Destination File Name "Random_Name.PDF"

Related

Flutter skip a directory from the copy file command

I'm copying files from one directory to another, but I want to exclude a directory, how can I proceed?
I tried to use the file_manager package as well but it doesn't work
var fm = FileManager(root: Directory('${externalDir.path}'));
var files = await fm.filesTree(
excludedPaths: ['/storage/emulated/0/Android/data/com.xxx.xxx/files/TEMP'],
extensions: ["mp3"],
);
in this way it should return me a list of mp3 files only, excluding the TEMP folder and its contents but this is not the case.

Flutter retrieving files from external storage

Im trying to list all the mp3 files in the Downloads folder using
Directory dir = Directory('/storage/emulated/0/Download/');
List<FileSystemEntity> listOfAllFolderAndFiles = dir.listSync(recursive: true);
print(listOfAllFolderAndFiles);
but it only prints sub-folders and not any mp3 files.

Write text to file in Flutter(Dart)

I want to be able to create a new file and write a string into it. Examples that I can find all seems to pertain to writing to an existing file.
String fileName = 'myFile.txt';
String contents = 'hello';
void writeToFile(String fileName, String contents){
File outFile = File('content://com.android.providers.media.documents/document/document/document_root/' + fileName);
outFile.writeAsString(contents);
}
This results in the following error, as expected
Unhandled Exception: FileSystemException: Cannot open file, path = 'content://com.android.providers.media.documents/document/document/document_root/myFile.txt' (OS Error: No such file or directory, errno = 2)
How can I create a new file in which I can write my contents?
Are you sure that the path exists? writeAsString does create the file if it doesn't exists, but it doesn't create the full folder structure up to the file you're trying to write to. Also, you might not have the rights to write in the path you've specified.
Anyway, you'd better use this plugin to get the folders' path instead of hard-coding them.

Word-AddIn (VSTO) doesn't get the filepath from local OneDrive Folder

I'm trying to develop an Word-AddIn where I can upload a file, or where I could make changes to the file itself. I can do that with any File on the Local NTFS Windows Filesystem. But when a File is located to any "OneDrive"-Folder it won't work, as the file-Document path starts with:
https://companyname-my.sharepoint.com/personal/name_whatever/Documents
according to the return values of:
var doc = Globals.ThisAddIn.Application.ActiveDocument;
MessageBox.Show("Document Name : " + doc.Name);
MessageBox.Show("Document Full Name : " + doc.FullName);
MessageBox.Show("Document Path : " + doc.Path);
rather than expected to be:
C:\Users\myname\OneDrive-My_Company_Name\Documents
So basically the local folder is not callable. So does anybody has already faced this kind of issue?
You can use the Save or SaveAs methods of the Document to save the document on the local folder.

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?
For example if Mirth is installed in /opt/Mirth-Connect directory and I want to read a file from /opt/Mirth-Connect/conf directory without specifying the fully qualified path name.
We are using multiple instances of Mirth for different environments which are installed on the same machine, So I can't hard code full path in channel configurations.
You can read a config file stored at a location relative to the Mirth Connect Installation directory basically in the same way as you would read any other file, i.e.:
var folder = new java.io.File("./conf");
var listOfFiles = folder.listFiles();
for (var i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
// Do what you need with the file - listOfFiles[i].getName());
}
}
The first line gives you a path relative to the mcserver.exe (in Windows env) installation.
Accordingly, folder = File(".") is a Mirth root folder.