Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Copy only the newest file in a directory

Featured Replies

Hi,

I'm looking for a way to automate the copy of a windows backup file (BKF). My server (WIN2K3 SBS) is configured to leave 3 versions of the backup on a external harddisk so I can retrieve files that were previously deleted. I also would like to copy the latest created BKF file to another external harddisk that I can take back home with me so in case of a fire or theft I have an extra copy.

The BKF file is large (over 90 Gb) and takes a few hours to be created, this is done every night from 02:00 till 7:00 in the morning. What I would like to accomplish is that during lunch time I click on a vb script that copies the newest BKF file to another external harddisk so that a few hour later I can unplug the harddisk and take it home. Because there are 3 files of over 90 Gb the normal "xcopy *.* f:\" line will take to long to copy all the files to the harddisk.

Can somebody help me out with a simple script that will copy only the newest BKF to my external harddisk. :thumbup

Thanks,

r00ster

if you already have the 3 files on the disk, then doing

xcopy *.* f:\ /D

This will only copy the files that have been changed (it comapres the timestamp of the files then copies the most up to date)

  • Author

Yes, i've tried /d argument..

What I forgot to tell is that I sometimes skip a day or two, so then it still copies all the files, so /d will work if I'm able to do it every day (which i'm not :sneaky: ).

You can easily use this (just copy and paste into a new file newer.cmd):

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Set /A Counter=0
FOR /F "skip=2 tokens=4" %%A in ('dir %1 /o-D') DO (
IF !Counter!==0 ECHO %%A
SET Counter=!Counter!+1
)

use as

newer.cmd "drive\Path\directory"

this will simply display the filename of the most recent file in the given directory.

Just change the %1 in the FOR loop with your hardcoded path (if you wish to do so) and change the ECHO command into your xcopy one.

The following is slightly more elaborate but returns more data on the file:

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
Set /A Counter=0
FOR /F "skip=2 tokens=4" %%A in ('dir %1 /o-D') DO (
IF !Counter!==0 (
ECHO Name : %%~nA
ECHO Extension: %%~xA
ECHO Full Path: %%~fA
)
SET Counter=!Counter!+1
)

In a command prompt type FOR /? to see other possible expansions of variables.

jaclaz

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.