I am hoping someone could help me with this.
I am trying to use a batch file to get the file path of a users desktop due to some people having OneDrive enabled and syncing their desktop.
I found a way to get the path via [Environment]::GetFolderPath([Environment+SpecialFolder]::Desktop) but how would I apply that to a variable to use later? I have next to no experience in this field.
Batch Script - Variables - There are two types of variables in batch files. One is for parameters which can be passed when the batch file is called and the other is done via the set command.
www.tutorialspoint.com
When I put this in a batch file and run it:
Code:
@echo off
set mypath=%cd%
echo %mypath%
TIMEOUT /T 5
It spits out the directory of my batch file. But when I replace cd with your variable information it just spits out the name of the variable. You're variable isn't correct.
This is more or less how I initially tried to do it, and it works. The problem comes when people are using OneDrive and syncing their desktop as the path to the desktop changes.
Can't you just check to see if %USERPROFILE%"\OneDrive - YourOrganization\Desktop" exists? If it does that's the directory and if not use %USERPROFILE%\Desktop
I did try START "MSAccess.exe" %UserProfile%\OneDrive - Company Name\Desktop\ReelTime.accdb, but all that seems to do is open the onedrive folder and doesnt launch the application.
Just wondering what the big picture is? While back I had to use batch scripts as part of a Task Scheduler task to open Access databases, run a macro and then spit out reports and close. Just trying to make sure you fully automate whatever it is you are doing.
I have had so many problems with OneDrive hijacking Desktop paths and folders.
Sorry, I'm not asserting that it is anyone else's fault (including OneDrive), as I'm sure I could eventually master every nuance of it.
But dang is it annoying as ***
Even on my laptop I'm constantly saving stuff to "Desktop" as it appears on the left side tree, then finding it's not really on my Desktop, it's on some secondary Desktop that OneDrive made for me. Other times it appears they are totally in synch.
I feel that things have gone downhill since Windows began emphasizing the heck out of Libraries.
Just give us simple folders and paths please! And I like a free 5 GB of OneDrive, but for the love of God, stop commandeering all of our familiar paths to confuse the living blank out of everyone.
Just because I haven't taken the time to figure it all out doesn't mean they're wrong .... it just gives me an idea of how much negative impact it probably has on many other people who are less motivated and less knowledgeable and kind of depending on the concept of a single, clear, obvious Desktop !
OneDrive is nice but it does create a headache when dealing with paths and figuring out where things went. I ended up getting this to work by making a batch file specifically for OneDrive users. Not the best workaround I am sure, but it worked lol.
I'm not sure why you are using OneDrive to distribute the FE since it sounds like people are working on a LAN. I'm assuming we are talking about an FE. Is that correct?
Where is the BE? Isn't there a shared server you could use so you have a standard UNC reference?
If you are somehow using OD to distribute the FK, you have to ensure that only YOU have update access to the folder with the FK because you'll have a real mess on your hand if OD saves a copy of the FE that has been modified by a user and that now becomes the "master".
I thought this might be a good test for A.I. While this is obviously air code and may not work, it could spur an idea among humans
I have the same issue in python and I don't want to hardcode a long path with OneDrive, I was thinking a relative path might work. Anyway, ignore the "relative path" bit.
Me: I'm having trouble because OneDrive is in the path with some users but not with others.
A.I. If your Access database file is stored in a path that includes OneDrive for some users but not others, you may encounter issues with referencing files or folders using a relative path, since the path to the OneDrive folder can vary depending on the user's configuration.
One solution to this problem is to use a combination of the Environ function and string manipulation functions to construct the path to the file or folder based on the user's environment variables.
For example, you could use the following code to construct the path to a file named "MyFile.txt" located in a subdirectory named "MyFolder" of the parent directory of the user's OneDrive folder:
A.I. In this code, the Environ function is used to retrieve the value of the OneDrive environment variable, which contains the path to the user's OneDrive folder. The path is then manipulated using the Left and InStrRev functions to remove the "OneDrive" folder from the path and obtain the parent directory. Finally, the full path to the file is constructed by appending the relative path to the parent directory.
This approach should work regardless of whether the user's OneDrive folder is included in the path or not.
Code:
Dim oneDrivePath As String
Dim filePath As String
' Get the path to the OneDrive folder
oneDrivePath = Environ("OneDrive")
' Remove the "OneDrive" folder from the path to get the parent directory
oneDrivePath = Left(oneDrivePath, InStrRev(oneDrivePath, "\") - 1)
' Construct the full path to the file
filePath = oneDrivePath & "\MyFolder\MyFile.txt"
I'm not sure why you are using OneDrive to distribute the FE since it sounds like people are working on a LAN. I'm assuming we are talking about an FE. Is that correct?
Where is the BE? Isn't there a shared server you could use so you have a standard UNC reference?
If you are somehow using OD to distribute the FK, you have to ensure that only YOU have update access to the folder with the FK because you'll have a real mess on your hand if OD saves a copy of the FE that has been modified by a user and that now becomes the "master".
The backend is stored on a shared drive on a file server. I was not using OneDrive to distribute the FE, but some of my users use OneDrive to backup their computer and OneDrive alters/highjacks the file path to the desktop, documents and pictures which meant the path to their desktop was no longer C:\username\desktop so the batch file I had created to get the FE from the shared drive on the server and copy it to their desktop didnt work.
I have fixed it by making a file specifically for those who use OneDrive. I did have to "seed" the first copy of the FE onto their computer though for some odd reason. I am still tinkering with a nice clean way of doing this but in the midterm, this has been working nicely.
I don't use the Desktop for local PC's. I have my batch file create a folder on the c: drive and download the master copy to that folder and run it from there. There is no error raised if the folder already exists so the batch file works for both new and existing users. I let the users chose where to put the batch file. I suggest the desktop but I don't force the issue. Forcing a file to the desktop is like the old days when every program that got installed thought it was the ONLY program in the universe and changed its environment which broke other applications.