opening excel file from cmd UNC paths screws with saving dir - excel

The Problem is an excel file on a network drive which is to be opened from a .cmd file in the same folder. As I'd rather not tamper with the registry on a machine at work, I used the pushd command to switch to the directory and open the file. Unfortunately pushd maps the path to a temporary drive letter which usually does not exist anymore when I save the excel file. Of course I could just use save-as and select the network path, yet it is rather tedious doing this on a daily basis.
Question(s):
Is there a way to circumvent the drive letter mapping and open the excel file from cmd on the network path without touching the registry?
Or, which seems more probable, is there a way to change the saving path of the excel file automatically to the required network path? I assume you could change some variable onWorkbookOpen, yet I don't know which...
Just in case, here's the batch code...
pushd \\%~P0
START excel.xlsm

Related

Robocopy "Documents" folder issue?

I have a custom script I use for backing up my hard drive to a temporary external drive. It's a simply a number of robocopy lines (without /PURGE). I've having trouble with the windows documents folder. If I have a command: "robocopy C:\users\me\documents D:\backups\somerandomdirectoryname ..", every time it's done, Windows thinks that directory is a Documents directory and even renames "somerandomdirectoryname" to "Documents". It changes the icon, and then I can not actually eject the USB drive because Windows will not let it go. What is causing Windows to do this to me? Is there something I have to exclude to make it "just a normal directory" on my external device?
Found a cure to this, use the option:
/XA:SH
which stops copying system and hidden files - which are how the special attributes of the Document directory appear to be copied. Worked for me, I only wanted the data files.

Need to monitor user downloads folder for new .xlsx files, then open Excel, save the file, and close Excel

At work I use a tool that requires me to download a .xlsx file, open it, then save it to remove the workbook protection. I'd like to create a script that automatically opens and saves any .xlsx files that are saved in the downloads folder.
I'm assuming PowerShell is the right tool to use. I found this article that explains how to do something similar, but I need help with configuring the parameters.
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1faa97e0-2288-4bb2-b8ad-283df32779d4/can-i-open-an-excel-workbook-when-files-with-a-certain-extension-are-saved-in-a-specified-folder?forum=ITCG
What I need is for the script to monitor the $env:USERPROFILE\downloads folder for any .xlsx files. Then I need it to open that file in Excel (preferably in a minimized window), save it with the same filename, then close Excel.
You can use IO.FileSystemWatcher to monitor a directory. See Start-FileSystemWatcher for an example implementation in PowerShell.

Which path can i use inside my program that will fit other computers? (that also have ubuntu)

I made a program in QT c++ that creates some files and i want them to be saved in a specific directory, i created a directory and i moved all the program there so i can use that same directory to save them, but when i write the path to save the files i have to write:
/home/"the name of my computer"/my_program/file.txt
and i want to use this same program in different computers. I also tried just writing:
my_program/file.txt
but it doesn't work.
Your relative path approach was already good, but a relative path is treated as relative to the working directory of the process and that depends on how the program is started.
E.g. if you start it from a shell, then the shell's current working directory will be the program's, if you start it from a launcher menu, it is often the user's home directory, but could be the location of the binary, etc.
So it is better to create a path based on well known base paths. such as the user's home directory, see QDir::home() or the a common location depending on type of data, see QStandardPaths
Did you try home directory path with "~/", many applications save their settings in ~/.applicationName directory

strange behavior saving a file with vim on Windows in a folder that requires elevated permission

I'm editing the apache2.conf configuration file under the 'C:\Program Files...' folder. This folder requires elevated permission ("Start program as administrator") for writing to anywhere on this folder.
Opening the file by mistake with vim without elevation - didn't show any warning. Moreover, I was able to save the file (':wq') just fine without any warning. Opening the file again with vim - showed me the modified file. However - no changes in the behavior of Apache (of course).
Trying to open the file with Notepad - show me the file was not modified.
Then, trying to open the file with vim from an elevated shell - I got the original file (just like notepad), but this time, I was able to edit the file, and save it.
I know have two versions of the file. The real file (shown by notepad, elevated shell, just 'type' and seen by apache httpd), and the file I edited and saved from an unelevated shell - stored somewhere (where???).
This is very uncomfortable, as sometime I open this file by mistake from a regular shell (even just for read).
What is going on? How do I exit this state?
I was hit by a Windows feature called "Virtual Store". Underneath the unaware application (that is, vim in this case), the OS running in compatibility mode will save the files in a folder named "Virtual Store", at this location: C:\Users\<login name>\AppData\Local\VirtualStore\.... The application will not be aware the file went there. Subsequent reads will read from that Virtual Store location.
It seems vim isn't UAC aware and it is running in compatibility mode - which could be fixed, but as for version 7.4 it hasn't.

Can't Overwrite CSV file if Open

I'm using powershell to export-csv a table. If the csv file is open anywhere on the network, the script will not overwrite the file. Is there anyway to work around this?
You would need to change how the network deals with users opening the files.
Usually, when a user (who is not an admin) opens a file on the network, you want the user to open it as read-only.
Only then, you will be able to overwrite the file using your script (with admin privs ofc)
If you do not have control over the network, the best option would be to create a different file with the same name but with revision number at the end. For example, "a.csv" would become "a001.csv" after the first edit.
Because of the nature of the solution, it will create havoc if multiple users are working on the same file.
In this case, I would suggest looking at version control softwares... But then again, it would be silly to go through all this for just editing a simple .csv file.. So, the answer is "it's complicated"

Resources