Having some trouble. Trying to copy some files from a network share to the local user profile for a user on XP. I'm getting an "invalid drive specification" message when I try to run my .bat script.
Any suggestions would be helpful. Below is my script:
#echo off &setlocal
if exist "%userprofile%\SapWorkDir\" xcopy "\\serverip\folder\" "%userprofile%\SapWorkDir\" /i /q /s /y /z &&
echo New folder 1 copied successfully || echo copied NOT successfully
Related
I'm using xcopy command in Windows to deploy to a server. I use the switch /w that lets xcopy wait for user confirmation, before it executes (displays "Press any key to begin copying file(s)"). I also use a bunch of other switches, to only copy the files that I need (full command below).
Can I somehow make xcopy check which files will be copied, display them on the screen and then wait for my confirmation? That will help identify if something is up, before I execute the command and fumble the server with the wrong files.
The /l switch should do it according to the docs (Displays a list of files that are to be copied.), but nothing shows up except the "Press any key..."? Does the other switches I use prohibit the /l switch...? After I press a key, the files are listed, but also immediately copied.
My command:
cmd /k xcopy "../03_App/" "[some path to the destination server]" /v /w /f /d /e /s /z /y
I am currently migrating from a Unix FS to a Windows FS and i need to copy user folders.
I have created a robocopy script that is very simple with a few kinks here and there.
My script:
#echo off
set /p username=Enter Username to start copying files:
echo %username%
takeown /f \UNIXFS\users$%username%* /r /D N
timeout /t 3
robocopy \UNIXFS\users$%username% \WINDOWSFS\Production$%username% /S /E /B /Z /ZB /MT:64 /V /TEE /ETA /TS /R:5 /W:1 /BYTES /X /DEBUG /LOG:C:\Robocopy%username%.log
timeout /t 3
icacls \WINDOWSFS\Production$%username%* /grant:r domain%username%:(OI)(CI)F /T
pause
I have an input section asking me which user i would like to start copying files from and too.
i take owner ship from the user as the current domain admin, copy the files and give the user full permissions on the folder.
But the ownership is still for the domain admin and not the user chosen by the inputted user.
Therefor i have created a separate single command line bat file that will take the ownership of the folder when i log in to the users account.
Take ownership script to run on for the migrated user:
takeown /F \WindowsFS\Production$%username%* /r /D Y
is there a way i can combine these two script as one and just run this as a single script.
I have tried to just combine them both together but the last takeown command like just give the user that runs the script ownership, when you have to do this for a lot of users you don't want to manually input or run the takeown script one by one on all machines.
This is my current code
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\" /Y /H /E /F /I
exit
I need the code to do something like:
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (4-21-18).MDB" /Y /H /E /F /I
exit
I need to back up the files every 2 weeks in the task scheduler and I need the script to automatically add the date of the back-up. Also, I have looked at the list of commands (e.g. /Y /H /E) and I cannot find one that describes non-overwriting in the destination folder. I need the back-ups to pile up and not get deleted every time the code runs.
You can add %date%
If you want to create folders with the date and put the file in it,
use like this to join the date to a foldername (D:\myFolder15-04-2020):
xcopy /y /q /s "c:\myFolder\*" "D:\myFolder"%date%"\"
or a folder name with just the date: (D:\15-05-2020)
xcopy /y /q /s "c:\myFolder\*" "D:\"%date%"\"
If you want to put the files in the same folder and change the file name use:
xcopy /y /q /s "c:\myFolder\*" "D:\myFolder\"%date%".MDB*"
The trick is:
"\" at the end of the command means a folder name
"*" at the end of the command means a file name
You can do this. Maybe exist better solutions but it will be working and Additionally, this is an approach for more than one file.
XCOPY /Y /H /E /F /I C:\Users\Asus\Desktop\Test\*.MDB
rem get date, make if file name friendly
FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%i-%%j-%%k-%%l
set MDB=*.%d%.MDB
ren *.MDB %mdb%
move C:\Users\Asus\Desktop\Test\*.MDB C:\Users\Asus\Google Drive\Test\
Hope this help.
You can create a bat file, get the current date in a variable and have this variable as part of the file name.
This bat file works:
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate
set MyDate=%%x
set today=%MyDate:~4,2%-%MyDate:~6,2%-%MyDate:~2,2%
mkdir "C:\Users\Asus\Google Drive\Test (%today%).MDB"
xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (%today%).MDB" /Y /H /E /F /I
exit
This code first saves the current date in "MyDate" variable.
Then the desired date format is saved in "today" variable.
Finally the content of the "today" variable is used as part of the file name that is passed in "xcopy" as an argument.
Mkdir makes sure that the directory is first created before xcopy is used.
This prevents the xcopy question <F = file, D= directory>? that pops out.
If a path refers to a file or directory that does not exist, xcopy considers it reasonable to first ask you what it is. Alternatively you could add a '\' in the end of the directory path to indicate that it is a directory.
It works! "echo F|" to auto confirm that you copy a file in the cmd prompt.
call set currentDate=%date:/=-%
call set currentDate=%currentDate:~-10%
echo F|xcopy "C:\Users\Asus\Desktop\Test\Test.MDB" "C:\Users\Asus\Google Drive\Test (%currentDate%).MDB" /Y /H /E /F
exit
I am trying to copy one folder and its contents to multiple user directories which vary depending on the username. The directory under each user will remain constant.
Here is an example of what I am trying to achieve:
xcopy "C:\OF" "C:\Users\*\AppData\Roaming" /O /X /E /H /K /S
I am trying to use a wildcard because the username is different, but xcopy apparently cannot use wildcards any longer?
The directory of "C:\OF" will have files and other nested directories and I want to place those under the "Roaming" directory.
Thank you for any help and explanation of what I am doing wrong.
Put this in a batch file:
#ECHO OFF
FOR /d %%I IN (C:\Users\*) DO (
XCOPY "C:\OF" "%%I\AppData\Roaming"/O /X /E /H /K /S
)
That should do want you want. I didn't validate your XCOPY switches because I stopped using XCOPY years ago in favor of ROBOCOPY.
This will do the trick.
#echo off
for /d %%x in (C:\Users\*) do xcopy "C:\OF" "%%x\AppData\Roaming\OF\*" /d /e
pause
EXIT
Hi I am brand new to batch file coding. I've been teaching myself Excel VBA for the past few months and StackOverflow was a very helpful site for me. Here is what I am trying to accomplish.
My company works a lot with IP video surveillance servers. Before we work on servers we like to take a snapshot of the log and configuration files for the various programs we use in case something goes wrong. I would like to get this down to a BAT file that resides on the technician's USB stick with an autorun file that will execute the BAT file when the USB is plugged into the machine. The program would go out to the various files and copy them to the file path: \hostname\date\time\originalfoldername\thisfile.xml I have been pulling code from various sites and here's what I've come up with so far to get me to the filepath: \date\time\originalfoldername\thisfile.xml
#echo off
rem COPYIT.BAT transfers all files in all subdirectories of
rem the source drive or directory (%1) to the destination rem drive or directory (%2)
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%\%ldt:~8,2%%ldt:~10,2%
echo %ldt%
xcopy "C:\ProgramData\Milestone\XProtect Recording Server" "\"%ldt%"\XProtect Recording Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Management Server" "\"%ldt%"\XProtect Management Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Management Client" "\"%ldt%"\XProtect Management Client\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Event Server" "\"%ldt%"\XProtect Event Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Log Server" "\"%ldt%"\XProtect Log Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Data Collector Server" "\"%ldt%"\XProtect Data Collector Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Report Web Server" "\"%ldt%"\XProtect Report Web Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Service Channel Server" "\"%ldt%"\XProtect Service Channel Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Smart Client" "\"%ldt%"\XProtect Smart Client\" /s /e
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit
:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
:exit
I have also found the code for the hostname but I can't figure out how to put them together. Here is that code:
FOR /F "usebackq" %%i IN (`hostname`) DO SET MYVAR=%%i
ECHO %MYVAR%
Can someone help? Thanks.