Batch File to move subfolder contents from mapped location to Server - file

I want to write a batch file to move all the content from mapped location to the server
ODM folder is already there on the server.
I tried both the code:
robocopy "\\eng1\d$\ODM" "\\200.200.200.9\c$\ODM" /s /z /move /mt:96 /log:C:\Temp\log.txt
and
xcopy /-y \\eng1\d$\ODM\*.* \\200.200.200.9\C$\ODM\ /d /c /y
pause
I am getting errors as
Invalid username or password for first code and
Invalid Drive specification for second
What is wrong with the code?

You can just run net use as also mentioned by Stephan in the comments above, to ensure it has a connection to both UNC paths, each time using username and password. (Remove domain\ if you do not use domain.
net use \\eng1\IPC$ /user:domain\user password
net use \\200.200.200.9\IPC$ /user:domain\user password
robocopy "\\eng1\d$\ODM" "\\200.200.200.9\c$\ODM" /s /z /move /mt:96 /log:C:\Temp\log.txt

Related

UNC Path not supported when trying to run batch file from a server

I'm writing a script to have preset bookmarks automatically import themselves into Google Chrome and I am trying to copy the contents of a folder from a shared server (the bookmarks file) to a computer that the server is connected to and I'm getting the following error:
'\\zapp\pc\PLI'
CMD.EXE was not started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
The command was completed successfully.
Invalid Path
0 File(s) copied
z: was deleted successfully.
Here is my script:
#echo off
net use z: \\zapp\pc
xcopy "Z:\PLI\" "c:\installers\" /e /c /i /q /h /r /y
net use z: /delete /y
goto :bookmarks
REM Imports bookmarks to the bookmark bar
REM User has to manually enable the bookmark bar and disable autofill
:bookmarks
xcopy "c:\installers\bookmarks" "c:%LOCALAPPDATA%\AppData\Local\Google\Chrome\User Data\Default\*" /Y
echo Bookmarks Copied. Use ctrl+shift+b to show the bookmarks bar and double check that all bookmarks work!
echo Turn off autofill and saved passwords in chrome://settings
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
REM Shutdown computer
echo Press any key to shutdown the computer
pause
shutdown -s -t 0
and then I'm receiving further errors about none of the files being copied, But it seems like it keeps trying to switch directories and therefore isn't finding the files that I want to copy. Is there a simple fix for this? Why does this happen?
Thanks!

Batch Script to copy folder from Server to user desktop in a network

My goal is to create a batch script to copy a folder with subfolders to user desktop with overwrite option and minimized of command prompt.
I am pushing the script through Group policy in user start up screen.
However I am getting an error when running the script locally. Not sure what I am missing in the script..
#echo off
#cls
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
echo Your Source Path:
set INPUT1=\\X.X.X.X\Test\TMS\
echo Your Destination Path:
set INPUT2=C:\Users\%Username%\Desktop\
xcopy %INPUT1% %INPUT2% /y /s
:minimized
You mentioned folder, so I am writing this assuming you want to create the TMS folder with content on the desktop.
I would try something like this inside of you minimized label. This is untested as I have no Network drives to test with.
for /f "tokens=2" %i in ('net use * "\\X.X.X.X\Test\TMS\" ^| findstr /i Drive') do set "tmpDr=%%i"
mkdir "%USERPROFILE%\Desktop\TMS" >nul
xcopy "%tmpDir%\*" "%USERPROFILE%\Desktop\TMS" /s /y
net use /d %tmpDir% >nul
Some things to note in your code. You have 2 minimized labels, you need to enclose path variables with double quotes to eliminate possible whitespace, you can drop the echo's seeing as you plan on running the script minimized. Last but not least, you do not need to specify full path to the user's desktop as %USERPROFILE% variable already exists as Drive:\Users\Username

Special Character confilct in batch file

I am new to batch files and created a batch file to back up a networked drive at work to my OneDrive folder so that I could access work files at home. Since then they have decided to install Office365 on everyones computer at work. Now instead of OneDrives folder just being called 'OneDrive' it is now called 'OneDrive - G&S Foods, Inc' My very simple batch file worked great until OneDrives name was changed. I cannot change the name back to just OneDrive, so I am trying to work around in my batch file. It seems the special characters are giving me an issue though, expecially the &. I now get the following error
Invalid number of parameters '&' is not recognized as an internal or
external command, operable program or batch file.
My Question is: What is the best way to work around the special characters issue?
Here are my current script lines:
#echo off
xcopy j:\Brandon C:\Users\bweibley\OneDrive - G&S Foods, Inc /m /e /y
xcopy J:\Joe's Folder\ChocScheduleBackUps C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps /m /e /y
Do so by enclosing the whole path in double quotes:
xcopy "j:\Brandon" "C:\Users\bweibley\OneDrive - G&S Foods, Inc" /m /e /y
You should already use double quotes if only a space is in there. So for your second line:
xcopy "J:\Joe's Folder\ChocScheduleBackUps" "C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps" /m /e /y
Try:
xcopy "j:\Brandon" "C:\Users\bweibley\OneDrive - G&S Foods, Inc" /m /e /y
xcopy "J:\Joe's Folder\ChocScheduleBackUps" "C:\Users\bweibley\OneDrive - G&S Foods, Inc\ChocScheduleBackUps" /m /e /y

.bat file autocopy - how to only copy file once?

I want a .bat file that will copy all files and folders from one folder to another folder automatically. For example:
robocopy "c:\source" "D:\target" /e /MON:1 /xc /xn /xo
However I need it so that once a file has been copied, that file will not be copied again, even if the copy has been moved to a different directory. Is there any way to do this? Is it possible for robocopy to create a log and check against that before copying the file?
If robocopy can't do it, what can?
Use additionally the option /M on your robocopy (SS64 article) command line as suggested by Stephan because this option results in copying only files with archive attribute set in source folder tree and removing archive attribute by robocopy after successful copying the file.
%SystemRoot%\System32\robocopy.exe "C:\source" "D:\target" /M /E /MON:1 /XC /XN /XO
The archive attribute is automatically set again on file modification.
You could perhaps also use xcopy (SS64 article):
%SystemRoot%\System32\xcopy.exe "C:\source" "D:\target\" /M /E /C /I /Q /G /H /R /K /Y >nul
Important for your task is again option /M for copying only files with archive attribute set in source folder tree and clearing the archive attribute after copying the file.
Note: /I works without user prompt only with target folder path ending with a backslash.
Run in a command prompt window robocopy /? respectively xcopy /? for details on the other options or read the Microsoft documentations for robocopy and xcopy.
Alright So, the easiest way to do this is to copy each
file and folder individually, to said folder.
This may not be what you are looking for, but
I hope it helps! Sadly there is no way to
copy l files folders with a single command.

directory is not empty error

I try in my batch file o delete folder(BR) with many files and subdirectories, I try the following:
if exist C:\BR (
rmdir "C:\BR" /S /q
)
but sometimes I get an error that a specific folder is not empty.these folder contains files of CSS.
what the problem??
rd /s /q DIRNAME
rmdir /s /q DIRNAME
The files that you can't delete are in use.
Close whatever program is holding them open, probably your browser, and try again.
Let me guess, your trying to delete your %TMP% folder.
EDIT: To answer zipi's question.
It will delete every file and folder that it can. So, if c:\tmp\dir2\dir3\open.txt is open, c:\tmp\emptyDir is an empty directory, and you do this:
c:\>dir c:\tmp /b /s
c:\tmp\a.txt
c:\tmp\dir2\b.txt
c:\tmp\dir2\dir3\open.txt
c:\>rd /q /s c:\tmp
c:\>dir /s /b c:\tmp
c:\tmp\dir2\dir3\open.txt
You will have deleted:
c:\tmp\a.txt
c:\tmp\dir2\b.txt
And removed:
c:\tmp\emptyDir
But still have the directories...
c:\tmp
c:\tmp\dir2
c:\tmp\dir2\dir3
...an the file:
c:\tmp\dir2\dir3\open.txt
If instead, a.txt was open, you'd only have:
c:\tmp\
and
c:\tmp\a.txt
On win7 I use a simple bat file to go around the problem:
call :rmdir "my_directory_01"
call :rmdir "my_directory_02"
pause
goto :EOF
:rmdir
if exist %1 rmdir /s /q %1
if exist %1 goto :rmdir
goto :EOF
I had a similar problem. Tried lots of different solutions, but ultimately only the following worked:
rmdir c:\<directory> /s /q
Previously using other methods in CMD I was getting the following:
The directory is not empty.
I had the same issue and the solution is very silly. Please use /Q first and the /S to resolve your issue. so command should be something like:
IF EXIST %build_folder% RD /Q /S %build_folder%
Please let me know if this solves your issue.
Regards
Anuj
To remove directory in command line, you have to remove all of files and subsolders it cointainst at the first place. The problem may occur if some of those items are read-only. /f will try to force delete them.
Try
if exists C:\BR (del "C:\BR" /f /s /q)
Here you have MS docs of the DEL command: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true
This worked for me
you will need to go to any drive where the folder is. Then right click on drive > properties > Check Scan disk or scan drive and for windows8 scan and repair
then go back to your folder and delete it
Batch - Getting "The directory is not empty" on rmdir command
In my case the failure to remove a directory using rd /Q /S and getting Directory not empty was down to file permissions. The batch job was doing a backup and removing oldest backup folder at the end to keep latest 10 backups. The normal user account only had read and execute permission on certain files in the sub folders. Running the batch file containing the rd commands under Task Scheduler with a tick in the option "run with highest privileges" enabled directory's to be removed.
You could achieve something similar as a one off if you run your batch file under cmd and choose run as administrator. In Windows 7 type CMD in the Search programs and files box, then right click on cmd.exe at the top of the popup window and click Run as Administrator. Then find and run your batch file in the cmd "black background" window.

Resources