Relative path doesn't work on shared directory - batch-file

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\

Related

Move a Folder and Subfolders to another Folder using Batch or VBS

I'm trying to automatically move the subfolders and files from my Dropbox folder on my F: Drive to a separate folder on the same drive, therefore emptying my Dropbox and freeing up space in it while backing up the files.
I tried this in Batch:
MOVE /-Y "F:\Dropbox\files\camera" "F:\backup\Camera\"
pause
but I keep getting Access Denied even when running as Administrator.
I also tried this in VBS:
With CreateObject("Scripting.FileSystemObject")
.MoveFile "F:\Dropbox\files\camera*", "F:\backup\Camera\"
End With
but I only got Path Not Found from that.
So pretty much I'm a bit stumped, or overlooking something obvious, But basically I just want to make a small script in vbs or batch that allows me to move all the sub-folders and files from F:\Dropbox\files\camera\ to F:\backup\camera\ so I can set it as a scheduled task and let it run each day so that it empties my Dropbox folder(and therefore my Dropbox account) of all files and folders and backs them up.
Any help would be appreciated, I have already searched a number of different options and none seems to work specifically for my purpose.
I suggest using ROBOCOPY instead of MOVE.
I have a similar backup script that uses it.
See:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
#ECHO OFF
ROBOCOPY /E /MOVE "F:\Dropbox\files\camera" "F:\backup\Camera\"
MKDIR "F:\Dropbox\files\camera"
Options:
/E : Copy Subfolders, including Empty Subfolders.
/MOVE : Move files and dirs (delete from source after copying).
Because of the /MOVE switch, I need to re-create the source directory because ROBOCOPY moves it to the destination directory. ROBOCOPY, by default, will retry the operation if it fails. See the /R:n and /W:n options to customize it. Also, the command will print a lot of info messages to the terminal, but you can customize it using the ROBOCOPY's logging options (ex. /NJH, /NJS, etc).
For the "Access Denied" error, make sure that:
You have write access to the destination folder
(Test by creating a batch file with just MKDIR "F:\backup\Camera\some_file.txt")
(Test by creating a batch file with just MKDIR "F:\backup\Camera\some_folder")
The files being moved are not being used or opened anywhere prior to running the script
(Ex. It's not opened in the Dropbox app.)

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

batch file command line start in same folder as executable on network path

I know from a desktop I can have a bat file that runs an executable with specific parameters and starts in the same path on the network where the executable exists, but how can I accomplish the same thing when calling the bat file assuming is in same folder as executable from another application?
For example:
\My-Network\app\PR8.exe /noload
I want to start specifically in \My-Network\app (same folder where PR8.exe exists) but not where it defaults to which seems to be c:\windows somehow. I can't seem to do a cd on a UNC path and I don't want to use any path letters as the application also detects as to which server it is executing from as well.
It isn't possible to set a UNC working directory for Windows batch files without network mapping drives. However, in Windows 2000 and later, you can use the PUSHD and POPD commands to change the working directory to a UNC share when running your script.
Wikipedia gives us the example of creating a shortcut to your batch file where the Target is set to the following:
%COMSPEC% /E:ON /C "PUSHD """\\My-Network\app\""" & C:\PATH\TO\BATCHFILE.BAT & POPD"
In this case the Working directory attribute of the shortcut is ignored, as the PUSHD and POPD commands will change it to the path specified.

Batch Copy and run acting strange

I have a batch file that needs to copy my EXE to desktop and run it from there.
Code:
copy client.exe %USERPROFILE%\Desktop
%USERPROFILE%\Desktop\client.exe
What seems to happen is that client.exe is indeed copied to desktop and ran but acts as if it is in the directory of the original client.exe
The problem is that as far as the batch is concerned, the current directory is wherever the batch is execute from.
If you want the current directory to be the desktop, you'd need to explicitly set it
copy client.exe %USERPROFILE%\Desktop
pushd "%USERPROFILE%\Desktop"
client.exe
popd
or
copy client.exe %USERPROFILE%\Desktop
cd "%USERPROFILE%\Desktop"
client.exe
The first temporarily switches the current directory, so it is restored to what it was when run after client.exe terminates; the second makes a permanent switch to the desktop.
If you want start an application and specify where files will be saved (Working Directory), use either
CD /D "%USERPROFILE%\Desktop"
"full_path_to_app\client.exe"
or
START "" /D"%USERPROFILE%\Desktop" "full_path_to_app\client.exe"
Copying the .exe file seems to be a needless action.

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