Computing.Net > Forums > Disk Operating System > script to copy the newest file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

script to copy the newest file

Reply to Message Icon

Name: zeroboot
Date: September 4, 2003 at 10:08:45 Pacific
OS: win2k
CPU/Ram: P4/1GB
Comment:

how can i use a script to copy the newest file in a directory? i.e. I have a number of files with similar names (SCAN1,SCAN2,etc) the highest index is the newest file and there can be a maximum of 150 of these files. I dont want to copy all of them because they are fairly large and at some point there could be 150 of these files, but I just want the most recent one.
Thanks,

J



Sponsored Link
Ads by Google

Response Number 1
Name: JackG
Date: September 4, 2003 at 10:22:53 Pacific
Reply:

Something along the line of doing a DIR SCAN* /o-d /b with the output redirected to a temp file or pipe. Then use batch commands to strip the first entry in the list and use it, as it will be oldest dated file.


0

Response Number 2
Name: Brian HANLON
Date: September 5, 2003 at 11:35:01 Pacific
Reply:

This will do EXACTLY what you're after, here's the README from the D/L:


THE HANDY DANDY ANALOGX NEWMOVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Have you ever needed to move only certain files out of a directory, based on their last modified date? Or have you wanted to move all the files out of a given directory, except for the latest three? If so, then you've finally got a utility to do just that (a not much else)!

AnalogX NewMove is about as straight-forward as any commandline utility ever is; from the command prompt you can type the name by itself to get a list of options:

F:\tools\newmove> newmove

AnalogX NewMove version 1.00 (Release)
The latest version can always be found at URL:
http://www.analogx.com/

Usage:   NEWMOVE [options]
Options:
  /TARGET [path]   Destination for files
  /SOURCE [path]   Source for files (def: current)
  /COUNT [number]   Number of files to leave (def: 1)
  /JUSTCOPY   Copies the files (does not move)
  /MOVEOLD   Move older files first (default)
  /MOVENEW   Move newer files first

Here's a brief description of each option:

  TARGET   This is the path where you want the files to be copied to. It supports both relative (..\) paths or literal paths (C:\). I would recommend using literal whenever possible to eliminate any possible ambiguity, unless you are comfortable with using relative paths.

  SOURCE   This is the directory it is going to be working in. If no source directory is specified, then it will use the current mounted path.

  COUNT   This is the number of files to actually leave, so if you told it to move newer files first, with a count of 5, it would leave the five OLDEST files. In contrast, if it was set to move the older files first, it would leave the five NEWEST files.

  JUSTCOPY   Use the COPY command instead of MOVE, leaving the source files intact where they are. By default the program uses MOVE.

  MOVEOLD   This specifies the order in which files are copied; the directory is sorted with the older files first, and it copies from older moving towards newer.

  MOVENEW   Exactly the same as MOVEOLD, except the files are sorted with newer files first, and it copies from newer moving towards older.

Pretty simple, eh? So here is a quick example of one of the more common uses of this utility.

Let's say you have a directory which stores log files for something like IIS (set to create a new file each day), and you perform analysis using Analog of the last week (7 days) of activity. Now, you don't want Analog to process the log files for anything prior to 7 days (sure, you can set this in Analog's config file, but it still reads through the log files, which takes time). Here's the command to tell it to move anything that's older than 7 days:

NEWMOVE /TARGET C:\logs\archive /COUNT 7 /MOVEOLD

This assumes it's executed in the directory where the logs exist, it then reads the directory, sorts it with the older files first, and moves all but 7 files into the directory C:\logs\archive.


Direct link to details & D/L page is in "HomePage" above.
Works like a charm!

Baldy.



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: script to copy the newest file

How to copy the whole disk? Thanks www.computing.net/answers/dos/how-to-copy-the-whole-disk-thanks/6384.html

Script to copy and create Unique name www.computing.net/answers/dos/script-to-copy-and-create-unique-name/10735.html

how to copy files using date www.computing.net/answers/dos/how-to-copy-files-using-date/12582.html