How can I call an environment variable in a batch script? - batch-file

I'd like to create a batch file that creates a directory symbolic link for My Pictures - in the Downloads folder...
mklink /D "%USERPROFILE%\Downloads\Pictures" "%USERPROFILE%\Pictures\Saved Pictures"
But the above doesn't work

Related

XCOPY files from directory with Batch file

In a folder I have a batch file and another folder name Themes.
I would like to be able to share this with others so looking to make the source directory independent of the location of the parent.
XCOPY /E/Y "\Themes\*.thmx" "C:\Users\%username%\AppData\Roaming\Microsoft\Templates\Document Themes\"
Running the batch file returns "File not found - *.thmx"

Create a folder with batch file in c:\Program Files(x86)\

I am trying to make an installer and i need to create a folder in Program Files (x86).
I created a batch file with the following code:
#echo off
copy /s "c:\Users\%USERNAME%\Desktop\MagicPanelInst\magicpanel" "c:\Program Files (x86)\Common Files\Adobe\CEP\extensions\"
I pretend to copy from magicpanel from the source to the already existing folder extensions in the target...
But is created in c: a new folder called Program Files (x86) with all the directories described above, instead of copy the magicpanel folder to the existing one.
Any help please?
Now it is working with the below code.
xcopy /s "c:\Users\%USERNAME%\Desktop\MagicPanelInst\magicpanel" "%programfiles(x86)%\Common Files\Adobe\CEP\extensions\magicpanel" /i
Or even better:
xcopy /s "%UserProfile%\Desktop\MagicPanelInst\magicpanel" "%CommonProgramFiles(x86)%\Adobe\CEP\extensions\magicpanel" /i
Thank you all for the help.

Relative path doesn't work on shared directory

xcopy "D:\CCStudio\rtos" panasonic /s /e
The folder panasonic and the bat file are on the same level in the directory structure, although on another machine I have access to.
When I use the bat script on my PC everything works fine. But when I put the bat script into the remote shared folder, it doesn't work as expected. The problem seems not to be the source, instead the destination address is the key in the problem. When I replace `pansonic' whit its absolute address, the script works.
So why should I specify absolute path for destination? Recall that the destination is external path. It is shared folder on another windows machine.
I currently run a bat from a shared drive to copy to another shared drive. This is what I use to get it working fine. Adjust as needed.
cd /d %~dp0
xcopy /s "D:\CCStudio\rtos" "panasonic\" /E
cd /d %~dp0 will change the directory to what ever the batch file is in allowing you to use relative paths. This script will copy the files in rtos to panasonic. Folder path will look something like this X:\Shared\Network\panasonic\RtosFiles.ini assuming RtosFiles.ini was in D:\CCStudio\rtos and the batch was run in X:\Shared\Network\

Relative network path in a .bat file

I need to run a .bat file in a network path (UNC path).
At the beginning, my bat file was something like this
cd subfolder
some file operations
When I tested it on my local computer, it worked, but when I move the file to a network directory, I have:
'\\ComputerName\SharedFolder\Resource' is an invalid current directory path. UNC paths are not supported.
Defaulting to Windows directory.
C:\Windows
I tried to use pushd command, but it didn't help:
pushd subfolder
some file operations
 
'\\ComputerName\SharedFolder\Resource' is an invalid current directory path. UNC paths are not supported.
Defaulting to Windows directory.
C:\Windows>pushd subfolder
No such directory.
I can of course write something like this
pushd \\ComputerName\SharedFolder\Resource\subfolder
but I want to use the same .bat file in several folders, so I want to use a relative path. Is it possible?
Only pushd can be used to switch to an UNC path, so first use pushd to the path of the batch file, then cd subfolder:
pushd %~dp0
cd subfolder
some file operations

XCOPY batch file

I’m looking to create a batch file that transfers all my music from my external drive to my Samsung note 3. The idea is just to click the batch file and for it to update any song on my external on my phone.
Heres what I’ve got
XCOPY "E:\Music\*.*" "Computer\SAMSUNG-SM-N900A\Phone\Music\" /e /c /r /k /y /v
The problem I see is that it’s creating a folder on my desktop with that path, the directory on my desktop being computer with the following subfolders.
I’m not sure why it won’t recognize the path, any ideas?
You can't directly copy files from windows to an android device, its a different file system. You can probably do it manually with this program:
https://android-file-manager.en.softonic.com/

Resources