Variable for Documents, Pictures, Music and Video folders


prob have to use powershell in those instances... but @garlin or @pseymour would be better suited to answer that correctly

Your answer is probably the most efficient, but you can omit the "-command" since it's a trivial one-liner.
Code:
for /f "delims=" %%D in ('powershell "[Environment]::GetFolderPath('Desktop')"') do set desktopPath=%%D

shell:[whatever] is a great shortcut, but only works if you're opening Explorer windows. It's not a construct for use outside of Explorer.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
any way I can use a variable to access these folders (e.g. in a batch file)

I think dacrone's approach is well-suited to incorporating references to user folder paths in batch files.
All 5 of the common user folder paths can be retrieved this way:

for /f "delims=" %%D in ('powershell "[Environment]::GetFolderPath('Desktop')"') do set DesktopPath=%%D

for /f "delims=" %%L in ('powershell "[Environment]::GetFolderPath('MyDocuments')"') do set DocumentsPath=%%L

for /f "delims=" %%M in ('powershell "[Environment]::GetFolderPath('MyMusic')"') do set MusicPath=%%M

for /f "delims=" %%P in ('powershell "[Environment]::GetFolderPath('MyPictures')"') do set PicturesPath=%%P

for /f "delims=" %%V in ('powershell "[Environment]::GetFolderPath('MyVideo')"') do set VideoPath=%%V

:: Results
echo Desktop path is %DesktopPath%
echo Documents path is %DocumentsPath%
echo Music path is %MusicPath%
echo Pictures path is %PicturesPath%
echo Video path is %VideoPath%

Pause to examine the results

and if you were working purely in PS, you could use equivalent expressions in the form
$UserDesktop = [environment]::GetFolderPath('Desktop')

But, if you were working in VBS, you'd be limited to Desktop & Documents folder paths using this approach
UserDesktopPath = WScript.CreateObject("WScript.Shell").SpecialFolders("Desktop")
MsgBox UserDesktopPath

UserDocumentsPath = WScript.CreateObject("WScript.Shell").SpecialFolders("MyDocuments")
MsgBox UserDocumentsPath



All the best,
Denis
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
What I’m not sure of, is why some are “Local” and some not. But they all hit their intended relocated folder’s.
Local Pictures, as opposed to OneDrivePictures.

 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
Local Pictures, as opposed to OneDrivePictures
Local pictures as opposed to Pictures.
I thought I had seen an explanation of their differences ages ago but cannot find it.


Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
Not sure what you mean by just Pictures. There are various pictures folders, as listed in Brink’s tutorial. I explained the Local distinction.
 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
Some users created a MS Account directly onto OneDrive-hosted folder paths, other users will add OneDrive later.
 

My Computer My Computer

At a glance

Windows 7
OS
Windows 7
If you look in
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
you may see some 'Local' entries for some user folders.
For example, the entries
My Video
{35286a68-3c57-41a1-bbb1-0eae73d76c95} [known as "Local videos"]
both point to the same folder in my case. OneDrive has never been involved.

The list of 'local' entries includes
{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5} ThisPCDesktopFolder
{f42ee2d3-909f-4907-8871-4c22fc0bf756} Local Documents
{7d83ee9b-2244-4e70-b1f5-5393042af1e4} Local Downloads
{a0c69a99-21c8-4671-8703-7934162fcf1d} Local Music
{0ddd015d-b06c-45d5-8c4c-f59713854639} Local Pictures
{35286a68-3c57-41a1-bbb1-0eae73d76c95} Local Videos

I think KeithM once posted an explanation of the meaning of 'local' user folders but all I can find is his list of their GUIDs.


All the best,
Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
local i believe is referring to the folders inside of "My Documents"
 

My Computer My Computer

At a glance

Windows 11 Pro
OS
Windows 11 Pro
As the OP I can only say WOW to all the answers that came in in a short time. THANK YOU all!
To clarify the context a bit, I have attached an example batch. I'd be happy to use a power shell script if that makes things easier.
The batch files converts audio files in input directory using ffmpeg and outputs them to output directory.
The output path is set to "D:\RF My Videos\ffmpeg Convert\output\". Of course this does not work on a machine that has the video directory in the %userfolder%. That is why I am looking for a way to point to My Video Folder independent of how my machine is set up.

rem this batch processes all files in folder 'input' and puts the result in folder 'output'
set inext=mkv
set outext=mka
set command=-acodec copy
FOR /F "tokens=*" %%G IN ('dir /b /s *.%inext%') DO ffmpeg -i "%%G" %command% "D:\RF My Videos\ffmpeg Convert\output\%%~nG.%outext%"
pause
 
Last edited:

My Computer My Computer

At a glance

Windows 11 25H2i7-12700FCORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2...NVIDIA GeForce GTX 1050 Ti
OS
Windows 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
i7-12700F
Motherboard
MSI PRO B660-A DDR4
Memory
CORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2 x 16 GB
Graphics Card(s)
NVIDIA GeForce GTX 1050 Ti
Sound Card
onboard
Monitor(s) Displays
ASUS PA32UCX
Screen Resolution
3840x2160
Hard Drives
ADATA SP900
AVAGO MR9361-8i SCSI with 3x Exos X20
PSU
Corsair RM650X
Case
Fractal Design Define R5 Blackout Edition
Cooling
Noctua CPU and Case Fans
Keyboard
Unicomp Model M
Mouse
Logitech MX Master
Internet Speed
1Gb/s
Browser
MS Edge
Antivirus
Microsoft Defender
My vague memory is that Local Documents etc refers to the location used by File explorer's ThisPC display of 'shortcuts' to user folders
and that this can sometimes differ from the relevant user folder path itself [due to errors during changes or user profile corruption?].
The solution was to delete the Local Documents etc entries so that ThisPC would then conform to the correct user folder paths. That's why KeithM posted their GUIDs. [I think the sequence was 1 run a tutorial that removed all the 'shortcuts' from ThisPC, 2 delete all the Registry's local folder GUIDs, 3 run the same tutorial to tell ThisPC to display its 'shortcuts' again.]
But I thought the discussion included an explanation of what the point was of Windows having any Local Documents etc paths defined at all. And it's this explanation that I cannot find.


All the best,
Denis
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
I can only say WOW to all the answers that came in in a short time. THANK YOU all!
To clarify the context a bit, I have attached an example batch. I'd be happy to use a power shell script if that makes things easier.
The batch files converts audio files in input directory using ffmpeg and outputs them to output directory.
The output path is set to "D:\RF My Videos\ffmpeg Convert\output\". Of course this does not work on a machine that has the video directory in the %userfolder%.

I think you are saying that you have relocated
C:\Users\%UserName\Videos
to
D:\RF My Videos

In that case you can add a line in your batch file
for /f "delims=" %%V in ('powershell "[Environment]::GetFolderPath('MyVideo')"') do set VideoPath=%%V
and then change your output line to
FOR /F "tokens=*" %%G IN ('dir /b /s *.%inext%') DO ffmpeg -i "%%G" %command% "%VideoPath%\ffmpeg Convert\output\%%~nG.

Note that this makes use of a Powershell function but, as far as you are concerned, you are staying in your batch file. Your batch file is merely calling up that PS function.


So you will then have
rem this batch processes all files in folder 'input' and puts the result in folder 'output'
set inext=mkv
set outext=mka
set command=-acodec copy
for /f "delims=" %%V in ('powershell "[Environment]::GetFolderPath('MyVideo')"') do set VideoPath=%%V
FOR /F "tokens=*" %%G IN ('dir /b /s *.%inext%') DO ffmpeg -i "%%G" %command% "%VideoPath%\ffmpeg Convert\output\%%~nG.%outext%"
pause




Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
Last edited:

My Computer My Computer

At a glance

Windows 11 25H2i7-12700FCORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2...NVIDIA GeForce GTX 1050 Ti
OS
Windows 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
i7-12700F
Motherboard
MSI PRO B660-A DDR4
Memory
CORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2 x 16 GB
Graphics Card(s)
NVIDIA GeForce GTX 1050 Ti
Sound Card
onboard
Monitor(s) Displays
ASUS PA32UCX
Screen Resolution
3840x2160
Hard Drives
ADATA SP900
AVAGO MR9361-8i SCSI with 3x Exos X20
PSU
Corsair RM650X
Case
Fractal Design Define R5 Blackout Edition
Cooling
Noctua CPU and Case Fans
Keyboard
Unicomp Model M
Mouse
Logitech MX Master
Internet Speed
1Gb/s
Browser
MS Edge
Antivirus
Microsoft Defender
No, dacrone is.
All I did was make use of the solution dacrone posted.


Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
@Try3 No idea what you’re on about with your walls of text. It’s local as opposed to cloud. No more complex than that.
 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
No, dacrone is.
All I did was make use of the solution dacrone posted.


Denis
Thanks extended in avove post
 

My Computer My Computer

At a glance

Windows 11 25H2i7-12700FCORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2...NVIDIA GeForce GTX 1050 Ti
OS
Windows 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
i7-12700F
Motherboard
MSI PRO B660-A DDR4
Memory
CORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2 x 16 GB
Graphics Card(s)
NVIDIA GeForce GTX 1050 Ti
Sound Card
onboard
Monitor(s) Displays
ASUS PA32UCX
Screen Resolution
3840x2160
Hard Drives
ADATA SP900
AVAGO MR9361-8i SCSI with 3x Exos X20
PSU
Corsair RM650X
Case
Fractal Design Define R5 Blackout Edition
Cooling
Noctua CPU and Case Fans
Keyboard
Unicomp Model M
Mouse
Logitech MX Master
Internet Speed
1Gb/s
Browser
MS Edge
Antivirus
Microsoft Defender
Just an idea to make things simpler. Could I use an auto starting PowerShell script upon Windows startup to establish the relevant variables for the shell folders, so that they would be available to be used in any batch afterwards? This would keep the batches simpler.
 

My Computer My Computer

At a glance

Windows 11 25H2i7-12700FCORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2...NVIDIA GeForce GTX 1050 Ti
OS
Windows 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
i7-12700F
Motherboard
MSI PRO B660-A DDR4
Memory
CORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2 x 16 GB
Graphics Card(s)
NVIDIA GeForce GTX 1050 Ti
Sound Card
onboard
Monitor(s) Displays
ASUS PA32UCX
Screen Resolution
3840x2160
Hard Drives
ADATA SP900
AVAGO MR9361-8i SCSI with 3x Exos X20
PSU
Corsair RM650X
Case
Fractal Design Define R5 Blackout Edition
Cooling
Noctua CPU and Case Fans
Keyboard
Unicomp Model M
Mouse
Logitech MX Master
Internet Speed
1Gb/s
Browser
MS Edge
Antivirus
Microsoft Defender
Just an idea to make things simpler. Could I use an auto starting PowerShell script upon Windows startup to establish the relevant variables for the shell folders, so that they would be available to be used in any batch afterwards? This would keep the batches simpler.
Variable persistence / variable scope is not straightforward.

I can recall the subject cropping up when I was first studying batch files but I have not even considered it since then.
One method is, instead of setting variables with a set cmd, using setx instead so you'd be setting them as 'environmental' variables.
Is there a way to create a persistent variable in batch file by writing to itself? - SO This article warns against the setx approach.

Straightforward variables only belong to the script setting them as you can see below.
Variable persistance.webp


This would keep the batches simpler
Well, yes. But not much since setting each variable will only take one line.
for /f "delims=" %%V in ('powershell "[Environment]::GetFolderPath('MyVideo')"') do set VideoPath=%%V


All the best,
Denis
 
Last edited:

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.9168
Thanks, Dennis
I think I will leave it at the current solution. I have already copied the two changed lines to all my batches. Luckily I had the good sense to separate the extensions and the command parameters into variables a while back. The principle of listing all variables at the beginning of a progream was used in Niklaus Wirth's Pascal programming language which we learned close to 50 years ago during my studies at ETH Zürich.
So now I can just copy the two generic lines across.
(y)
 

My Computer My Computer

At a glance

Windows 11 25H2i7-12700FCORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2...NVIDIA GeForce GTX 1050 Ti
OS
Windows 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
MSI
CPU
i7-12700F
Motherboard
MSI PRO B660-A DDR4
Memory
CORSAIR Vengeance LPX - DDR4 - kit - 32 GB: 2 x 16 GB
Graphics Card(s)
NVIDIA GeForce GTX 1050 Ti
Sound Card
onboard
Monitor(s) Displays
ASUS PA32UCX
Screen Resolution
3840x2160
Hard Drives
ADATA SP900
AVAGO MR9361-8i SCSI with 3x Exos X20
PSU
Corsair RM650X
Case
Fractal Design Define R5 Blackout Edition
Cooling
Noctua CPU and Case Fans
Keyboard
Unicomp Model M
Mouse
Logitech MX Master
Internet Speed
1Gb/s
Browser
MS Edge
Antivirus
Microsoft Defender

Latest Support Threads

Back
Top Bottom