I have the following file copy command.
How can I schedule this to run once a week automatically?
copy D:\SFTP*.* \location of file*.*
del D:\sftp*.* /q
exit
Thanks
Task manager, set weekly and when
del d:\data\*.* /q
xcopy "C:\data\*.*" d:\data\*.* /y
del c:\data\*.* /q
Related
How can I delete/cleanup all the folders under "Clean System Files" option in disk cleanup via powershell? The code below wasn't able to achieve what I wanted to.
(Start-Process -FilePath "$env:systemroot\system32\cleanmgr.exe" -ArgumentList "/sagerun:1" -Wait -PassThru)
Thank you,
Have you tried the autoclean option?
cleanmgr.exe /AUTOCLEAN
It will clean below folders:
C:$Windows.~BT*
C:$Windows.~LS*
C:$Windows.~WS*
C:\ESD\Download*
C:\ESD\Windows*
C:$WINDOWS.~Q*
C:$INPLACE.~TR*
C:\Windows.old*
C:\Windows\Panther
It will also write 2 log files as following:
C:\Windows\System32\LogFiles\setupcln\setupact.log
C:\Windows\System32\LogFiles\setupcln\setuperr.log
you can delete them one by one by starting the cmd in admin mode.
below is an example to delete the $windows.~BT folder
takeown /F C:\$Windows.~BT\* /R /A
icacls C:\$Windows.~BT\*.* /T /grant administrators:F
rmdir /S /Q C:\$Windows.~BT\
I am using a batch script with a powershell command.
cutout:
FOR /F "usebackq delims=" %%v IN (`powershell -noprofile -executionpolicy bypass "& { (Get-Date).AddDays(-1).DayOfYear }"`) DO set "DayOfYear=00%%v"
set DayOfYear=%DayOfYear:~-3%
set rinex_dest=E:\02_RINEX\%GNSSWEEK%\%DayOfYear%\
set rinex_dest_extern=E:\02_RINEX\%GNSSWEEK%\%DayOfYear%\extern\
IF NOT EXIST (mkdir %rinex_dest%)
IF NOT EXIST (mkdir %rinex_dest_extern%)
CD %rinex_dest%
set temp_unzip=%rinex_dest%temp_unzip\
set temp_nw=%rinex_dest%temp_nw\
set temp_extern=%rinex_dest%temp_extern\
mkdir %temp_unzip%
mkdir %temp_nw%
mkdir %temp_extern%
7z.exe e Y:\data\%Year%\%Month%\%Day%\*.zip -o%temp_unzip% *_MO.rnx -r
FOR %%i IN (%NWStationen%) DO MOVE %temp_unzip%%%i00DEU_S_%Year%%DayOfYear%*_MO.rnx %temp_nw%
FOR %%h IN (%externeStationen%) DO MOVE %temp_unzip%%%h_S_%Year%%DayOfYear%*_MO.rnx %temp_extern%
rmdir /Q /S %temp_unzip%
This works fine for me, if i run the the batchfile.
But now i try to implement the batchfile in the task scheduler (on Win Server 2019).
The batchfile runs, but the powershell command doesn`t work.
The Action in task scheduler is:
"Start program" C:\Windows\System32\CMD.exe /c"PatchtoScript\Script.bat"
Any suggestions to solve the problem?
Thank You!
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
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