New
#21
Last edited by Try3; 19 Sep 2020 at 07:34.
Last edited by Try3; 19 Sep 2020 at 07:34.
In scanning, I thought he was looking for a way to determine the paths of other folders as well. Sorry. Still good general info though. Much more complete than wcript.shell.SpecialFolders.
Keith,
Yes, still good. And, as with many of your PS scripts, I've copied it into my PS notes ready for thedayweekmonthquarter when I eventually get around to studying PS properly. So, thanks yet again.
We'll only know more if dorkious responds.
Denis
I know that you never claimed that you could substitute other user folders and I'm sorry if that was implied.
What I'm trying to figure out is why it's not returning the path of the music folder ("E:\Music") and video folder ("E:\Videos") when trying to find those using your batch command. I have found that I can find the "Documents" folder using your batch script as it returns the path rather than the "REG_EXPAND_SZ" that the music batch and video batch is returning.
The only difference that I can see is that the query is using a two word search term in quotes instead of a single word.
Below is the Reg Queries I ran to see what it returns and to confirm what values I can see from the registry editor:
Below is a modified version of your script looking for the "Documents" folder to which it can successfully find the path for:
This final image I tried to find the path to the "Music" folder and I can see that during or after the "For" command is where the problem arises:
From what I can gather, being somewhat new to fully custom batch scripts, is it the "usebackq tokens=3" that is causing the issue I am running into? Or is there something else I'm missing when trying to find these two paths?
Yes. tokens=3 tells it to get the third word and you want tokens=4 to get the forth.
GetMusicFolder.bat
Code::: Purpose - Get the user's Music path even if it has been relocated and even if the path contains spaces or ampersands :: Extract the Music folder path from the Registry set UseExpresssion=Reg Query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Music" For /F "usebackq tokens=4 " %%X in (` %UseExpresssion% `) Do Set MusicFolder=%%X :: Resolve a result that contains a variable such as %UserProfile% For /F "usebackq delims=" %%X in (`Echo "%MusicFolder%"`) Do Set "MusicFolder=%%X" :: Strip quotation marks from start and end of MusicFolder Set "MusicFolder=%MusicFolder:~1,-1%" :: Always protect use of MusicFolder with quotation marks unless and until it is proven to contain no spaces or special characters such as ampersand echo MusicFolder - "%MusicFolder%" Pause to review results during testing
Notice that you did not need to change the pause command at the end. It works as it is.
- You will often find it useful to include explanatory remarks after Pause so that you can find your place within scripts when you are testing them.
Why do you want the Music folder?
- Does this form part of a larger script?
- Finding the Desktop folder is often used within larger scripts but I've never seen anybody ask about the Music folder before.
- Or is this purely a training exercise? Nothing wrong with that.
and study
For - SS64
For is such a sophisticated & powerful command that it takes a lot of studying and a lot of getting used to.
Denis
I was wanting to get all of the User folders for a larger script I'm working on and as a training exercise.
The plan was to make a "clean install" set of batch scripts to setup most of my normal folder paths on a new install of windows and then use another set of batch scripts to network transfer files from my old computer to my server or directly to a new computer.
The music folder is one that I have a lot of files in and was wanting to make sure I can cleanly move files to it using batch with the help of the code you provided. I'm also tinkering with how to update my music server with new .mp3 files from my local machine and using batch scripts to copy the files and folder structure over.
I also have scripts to copy various files between my own computers. I simplify things by having the same user names, carrying out the same user folder relocations and having exactly the same drive & folder structures on all my computers [including the same shared folder names].
Note that the batch script can only capture the Music folder of the computer it's running on. But the reg query part of the script can be altered to interogate a remote computer so you would probably find that best.
https://docs.microsoft.com/en-us/win...ands/reg-query
Reg - Edit Registry - Windows CMD - SS64.com
[This particular command is one of the very few examples of MS guides being better than SS64 guides]
I suppose that your requirements would differ significantly from mine if you only intended to transfer your files once across to the other computer [rather than the regular transfers that I do].
I imagine your music server updating might well be regular tasks.
Batch file, PowerShell guides - post #13 - TenForums
my ditty and demo for Standard passable variables [post #47] - TenForums
Manipulating variables in batch files - post #14 - TenForums
Denis
As far as the folder finding batch files go, they would be used on the computer I'm transferring files from but the reg query to find out things from a remote computer is something I didn't think about so I'll be saving that for later.
I try to have the same user names and user folder relocations as well but on a clean install you have to do that from the properties window, unless I can find out how to relocate them using batch instead.
The music server updating will be a regular task at some point once the server itself is stable [consumer desktop parts running a server, wanting to get a refurbished enterprise server at some point]
In any case thanks for the help and useful links :)
I found thatusebackq
is unnecessary for finding the relocated Desktop folder.Code:Set "+=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" For /F "tokens=3" %%# in ('Reg Query "%+%" /V Desktop') Do (Set #=%%#) For /F "delims=" %%# in ('Echo "%#%"') Do (Set "#=%%#") Set "#=%#:~1,-1%" Echo The current desktop is %#% & Pause