How can I find the newest files in a specific folder and all of it's subfolders in a cmd? - batch-file

I want to keep my database updated, so every time I get the latest files from TFS I want to find the changed files (newest in date) in order to run them and not run ALL of the files.
I want to create a batch file to search, find and copy them to a temp folder so I'll be able to run only them.

A creative solution would be you can enter dir results into a text file and then whichever language you are using just do string slicing which can give u date, memory and name of the file. This is command- dir/a>file replace file with the text file. if u want the text to be entered into the file in append mode then dir/a>>file

Related

CMD how to write merged text file name on first line

I have created cmd batch file to run several R script and each script have their own log files in same folder like below :
coc_prod_xgb.log
ds_prod_xgb.log
ccpa_prod_xgb.log
pletb_prod_xgb.log
and many more
Then I merge all text files into 1 log file
copy *.log all_log.log
The problem is sometimes there are errors on different jobs, so I need to know on which log this error occurs. Currently I have to open each log file one by one, because in the merged log file, I can't identify which log file that has this error.
How to modify above copy code so it will write file names on the 1st row then the next row will be log information and append the same process to next file
I can't find any option for cmd copy code to write file name, so i find another solution from this question.
Easiest way to add a text to the beginning of another text file in Command Line (Windows)
so it serve my needs, eventhough i have to write each block of code for each log file. but only for 1 time effort

Winrar, "-or" overwrites file in archive instead of adding number to name if exists

After Googling and "researching" for over 3 hours to no avail, i have turned here to possibly get some help to my issue. Either if its possible or not to some extent.
This is a bit messy i know, but i'm fairly new to this.
What im trying to do.
I want to Backup a File which adds it to a archive folder With a Timestamp to it. YYYY-MM-DD Which then contains the File
2021-03-09.rar
File01.db
Then it takes the created file and adds it to a Backup.rar
Backup.rar
2021-03-09.rar
File01.db
Now i got this to work, My only problem here is that it instead overwrites the current existing File "2021-03-09.rar" in the Archive "Backup.rar" with the new one, instead of adding a number to the new backup that i added.
This is how i want/it should do;
Backup01: 2021-03-09.rar
Backup02: 2021-03-09-01.rar
Backup03: 2021-03-09-02.rar
Backup04: 2021-03-09-03.rar > and so on.
Code/what i have tried
I have tried using the commands "M" and "U" but same result, i tried using -or as well, which should rename files automatically if a file with the same name exists, but it doesnt work and the file(2021-03-09.rar) in my archive(Backup.rar) gets overwritten instead with the new backup(2021-03-09.rar).
Code:
"%ProgramFiles%\WinRAR\rar.exe" a -agYYYY-MM-DD -cfg -ep1 -m5 -r -y "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\File01db"
"%ProgramFiles%\WinRAR\rar.exe" a -or -ep "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\*"
While i know its not the smartest way to add a rar file to another rar file, its what i decided to do, it might be smarter to just have the bat file create a folder that it then adds to the archive or if it creates a folder in winrar and then adds the file to the folder in the archie, but it seemed to advanced.
Use YYYYMMDD and add an archive number, where the archive number is a numeric value starting from 1.
That will generate unique names even when the YYYY-MM-DD-NN format mask is used more than once in the same day.
WinRAR a -agYYYY-MM-DD-NN backup
WinRAR searches for already existing archives with that generated name and if found, increments the archive number to generate an unused name.
Refer to WinRAR, Help. Help topics and search for '-ag'

Using cmd to move files with a specific filename mask

I am trying to use a simple windows cmd command to move a set of .csv files from one directory to another.
I know that this can be easily achieved through:
MOVE "*.csv" "D:/lorik_home"
The issue comes when I want to only move some specific files with a filename mask, for instance, I want to move all files which are in the .csv extension and start with the name: lorik_files_. I already tried using:
MOVE "lorik_files_*.csv" "D:/lorik_home"
This works when there is only one file of the format: lorik_files_20112233_09_33_33.csv, but when there are two files with the masks such as:
lorik_files_20112233_09_33_33.csv
lorik_files_20112233_10_23_42.csv
I get an error such as:
A duplicate file name exists, or the file cannot be found.
I need a hand for capturing those filename prefix masks, conditioned by .csv extension at the end.

Using a batch file to copy multiple files with the same name, and past into new folder with differing names

I have a long list of files that are auto-produced every month. they'll all have the same file name, with a sequential file extension like this:file.001, file.002, file.003
Each file has differing information, despite having the same name. What I need to do is copy them from their home directory and paste them into a new directory with names that reflect their purpose, and as text files, like this: Budget.txt, Expense.txt, Retention.txt
Is it possible to do this with a batch file? I've been unable to find a method that works. Any help would be appreciated.
EDIT: I've tried that solution, and it works as far as it goes. the frustrating thing is that the extensions are not always the same, but always sequentially numbered.

using batch command file copy on daily basis

I need to copy files from one machine to my local disc using batch commands.
My files contain the date in dd-mm-yyyy format. But in case if i am using this:
-%date:/=-%
it is interpreted as "day" and then date which is not really associated with my file name at the source end.
Once I click my bat file it will copy one folder say "xyz dd-mm-yyy" I want to copy only today's folder as on my source machine saved last 7 days folder.
EDIT: my folder name on source machine is Site_info 11-07-2011 and tomorrow one more folder will get added to the same machine with name site_info 12-07-2011. I want to run the bat file machine where it will copy only today's folder.
EDIT2: Thanks for kind support still i am not able to achieve my target.If possible please provide the commands for following situation
My machine path :c:\Documents and Settings\user1\Desktop\SITE_INFO\Site_info 12-07-2011 where Site_info 12-07-2011 will change to site_info 13-07-2011
Source address :- \97.253.72.127\Cdma Site_info\Site_info 12-07-2011 Tomorrow one more folder will get add on this path with dated like \97.253.72.127\Cdma Site_info\Site_info 13-07-2011
If you mean that there's the 'day of week' part preceding the date and you want to get rid of that part, then you'll probably need an additional variable. First you'll cut off the day of week, then replace / with -, like you are already doing. It might be something like this:
…
SET "dateonly=%date:~4%"
SET "dateonly=%dateonly:/=-"
…
COPY \\computer\share\path\whatever-%dateonly%.ext drive:\path\%dateonly%\
…
You could try to puzzle the date the way you want it:
set mydate=%date:~-10,2%-%date:~-7,2%-%date:~-4%
xcopy /E /I "Site_info %mydate%" "Copy\Site_info %mydate%"

Resources