batch file to copy files to newly created folder with date name - batch-file

I'm making a system that our employees need to store files to that are ment to be processed. This process however deletes the source files and I want to make a backup prior to these files being processed.
The files need to be stored in an automatically created folder with name being today's date. The files vary in filetype.
The first part, creating a folder with today's date, I managed to figure out. The second part, copying files from a general folder to this newly created folder is something I can't get to work.
This is the code I have so far
#echo off
set date="%date:~-10,2%-%date:~-7,2%-%date:~-4,4%"
set "source=C:\b2g\2021\general"
set "destination=C:\b2g\2021\%date%"
mkdir "C:\b2g\2021\%date%"
robocopy "%source%" "%destination%" /mir /minage:%X%
exit /b
This is creating the folder, but is not copying any files to that folder.
any help is very kindly apreciated

Related

Create Batch script to copy specific files from one folder to another

I am attempting to copy specific files from one folder to another. The files in the source folder may have a names like:
1FT_DINRM_TASCAM_pt5GAL_TCL_cpl.wav
1FT_DINRM_TASCAM_pt5GAL_TCL_lcpl.wav
1FT_DINRM_TASCAM_pt5GAL_TCL.wav
I just want to copy the files that have cpl and lcpl in their names.
I am not sure how to implement this in the batch script that is currently at this stage:
mkdir Modified_originalClip
set "source=G:\Personal Data\Unclipped"
set "destination=G:\Personal Data\Modified_originalClip"
robocopy "%source%" "%destination%" /mov /minage:%X%
Any help to copy the specific files in the Windows 10 environment will be sincerely appreciated!

Use xcopy to backup complete folder even only one file is new

I am trying to use XCopy to backup files from an old machine to a server folder. So I set up a batch file which copies each day the new files from the machine to the backup server using the following code, (just a part of the whole code):
set /p LastSuccessfulBackup=< C:/backup/LastSuccessfulBackup.txt
set datestr=%date:~-4,4%%date:~3,2%%date:~-10,2%
xcopy "\\machine\srcfolder" "\\server\destfold\"!datestr! /s /y /i /c /d:!LastSuccessfulBackup!
So the idea is to check whether there are changed files in the srcfolder using /d and copy them to a newly generated timestamp-folder if there are changed files. It's kind of an incremental backup.
My problem is now, that I would like to have the whole folder copied and not only the changed files. Otherwise I get day by day just a backup of some few files but never the whole src-folder content.
That means that I need kind of a check, whether there are changed files and if so, copy the whole srcfolder to the backup-destination timestamp-folder.

Batch script for moving files doesn't work

I tried to create a batch script which will move a folder created on a previous day from a directory to another.
I've looked at all the trends and tried to do it myself, and I managed to do something, but it still doesn't do what I would like.
In a directory, I will always have 2 folders. Every day I need to go and copy the folder created on the previous day to the new location at 3 am in the morning. I've tried all the option with the MAXAGE, MINAGE, MAXLAD, and MINLAD but probably I don't understand how this works!
#echo off
/MINAGE:1 :: MINimum file AGE - exclude files newer than 1 days/date.
set MyLogFile=%date%
set MyLogFile=%MyLogFile:/=-%
robocopy /log+:"C:\Users\Desktop\Test\%mylogfile%.txt" /TEE C:\Users\Desktop\Test\try1\n1 C:\Users\Desktop\Test\try2\n2 /MOVE /E /MINAGE:1
robocopy /log+:"C:\Users\Desktop\Test\%mylogfile%.txt" /TEE C:\Users\Desktop\Test\try3\n3 C:\Users\Desktop\Test\try4\n4 /MOVE /E /MINAGE:1
At the moment it moves all the files from try1/n1 to try2/n2 no matter how old or new is the folder.
The expected result would be from try1/n1 in which I have 2 folders (one created yesterday and one today) to move into try2/n2 only the folder created yesterday!

Batch Script: Moving Files from One Folder to Another and Deleting Source Folder

I wish to iterate through a directory containing a dynamic amount of subdirectories (I will be reusing this code for different directories on this machine, one directory has about 160 subdirectories, another has over 1000, etc) and within those subdirectories, there are subdirectories containing folders that contain files. I'd like to move all of the files in the source folder to the destination folder and once all of the files have been moved, I'd like for the source folder to be deleted.
From
Source
(dynamic amount of subdirectories)
Site Visits
Field Notes (Destination Folder)
Levels (Source folder)
To
Source
(dynamic amount of subdirectories)
Site Visits
Field Notes
Here's the code that I have so far:
#ECHO OFF
SETLOCAL EnableExtensions
set "source=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
set "target=\\igsascewfszeus\ILWSC_Data\dataarchive\groundwater\data sites\"
for /d %%i in ("%source%\*") do (
pushd "%source%\%%~nxi\site visits\levels prior to WY2016"
robocopy "%source%\%%~nxi\site visits\levels prior to WY2016" "%target%\%%~nxi\site visits\field notes prior to WY2016" /e /copyall /move
rd "%source%\%%~nxi\site visits\levels prior to WY2016"
)
I'm new to batch scripting so, I would really appreciate if you can help me in some way. Thanks!

Batch File that will Backup My Files?

How would I go about making a batch file that empties a backup folder on my PC and then copies over the data on my USB to the folder. And then each evening my files would be backed up by simple clicking on the file. I don't have a very big grasp on how batch files work. Could somebody point me in the right direction as to what this would look like?
ROBOCOPY f:\myusb c:\myfolder /mir
It will copy from source (the usb) to target (the hd) from/to indicated folders all the new and updated files, ignore and leave all the non changed files and remove from target all the files not present in source.
XCOPY /s "C:\folder\" "F:\"
30sec on startpage/google
Will not work on W8 it seems thought
EDIT: for Win8:
ROBOCOPY /E C:\folder\ F:\folder, /E
is for copying all subfolder in the folder.

Resources