Sign in to follow this  
Followers 0
addictedtofunk

Most recent file copy

4 posts in this topic

Ok so i have a directory's files in a text file. It looks like this:

Volume in drive M has no label.

Volume Serial Number is 3024-3B98

Directory of M:\Backup

PRM1021.ZIP PRM0727.ZIP PRM0427.ZIP

PRM1020.ZIP PRM0726.ZIP PRM0418.ZIP

PRM1019.ZIP PRM0725.ZIP PRM0413.ZIP

PRM1018.ZIP PRM0724.ZIP PRM0412.ZIP

PRM1017.ZIP PRM0722.ZIP PRM0410.ZIP

PRM1024.ZIP PRM0721.ZIP PRM0408.ZIP

PRM1023.ZIP PRM0720.ZIP PRM0407.ZIP

PRM1016.ZIP PRM0719.ZIP PRM0405.ZIP

PRM1014.ZIP PRM0719A.ZIP PRM0403.ZIP

PRM1013.ZIP PRM0718.ZIP PRM0401.ZIP

PRM1012.ZIP PRM0717.ZIP PRM0331.ZIP

PRM1011.ZIP PRM0715.ZIP PRM0330.ZIP

PRM1010.ZIP PRM0713.ZIP PRM0329.ZIP

PRM1009.ZIP PRM0712.ZIP PRM0328.ZIP

PRM1007.ZIP PRM0708.ZIP PRM0327.ZIP

PRM1006.ZIP PRM0706.ZIP PRM0325.ZIP

PRM1005.ZIP PRM0705.ZIP PRM0324.ZIP

PRM1004.ZIP PRM0704.ZIP PRM0322.ZIP

PRM1023ROLLOVER.ZIP PRM0703.ZIP PRM0321.ZIP

PRM1003.ZIP PRM0701.ZIP PRM0320.ZIP

PRM0929.ZIP PRM0630.ZIP PRM0318.ZIP

PRM0928.ZIP PRM0629.ZIP PRM0317.ZIP

PRM0927.ZIP PRM0628.ZIP PRM0316.ZIP

PRM0926.ZIP PRM0627.ZIP PRM0315.ZIP

PRM0925.ZIP PRM0624.ZIP PRM0314.ZIP

PRM0923.ZIP PRM0623.ZIP PRM0313.ZIP

PRM0922.ZIP PRM0622.ZIP PRM0311.ZIP

PRM0921.ZIP PRM0621.ZIP PRM0310.ZIP

PRM0920.ZIP PRM0620.ZIP PRM0308.ZIP

PRM0919.ZIP PRM0619.ZIP PRM0307.ZIP

PRM0918.ZIP PRM0617.ZIP PRM0304.ZIP

PRM0916.ZIP PRM0616.ZIP PRM0303.ZIP

PRM0915.ZIP PRM0615.ZIP PRM0302.ZIP

PRM0914.ZIP PRM0612.ZIP PRM0301.ZIP

PRM0913.ZIP PRM0610.ZIP PRM0227.ZIP

PRM0912.ZIP PRM0609.ZIP PRM0225.ZIP

PRM0911.ZIP PRM0607.ZIP PRM0224.ZIP

PRM0909.ZIP PRM0606.ZIP PRM0223.ZIP

PRM0908.ZIP PRM0603.ZIP PRM0221.ZIP

PRM0907.ZIP PRM0602.ZIP PRM0218.ZIP

PRM0906.ZIP PRM0531.ZIP PRM0216.ZIP

PRM0905.ZIP PRM0530.ZIP PRM0213.ZIP

PRM0904.ZIP PRM0529.ZIP PRM0211.ZIP

PRM0902.ZIP PRM0527.ZIP PRM0210.ZIP

PRM0901.ZIP PRM0526.ZIP PRM0204.ZIP

PRM0831.ZIP PRM0525.ZIP PRM0203.ZIP

PRM0830.ZIP PRM0524.ZIP PRM0202.ZIP

PRM0828.ZIP PRM0523.ZIP PRM0201.ZIP

PRM0826.ZIP PRM0520.ZIP PRM0130.ZIP

PRM0825.ZIP PRM0519.ZIP PRM0128.ZIP

PRM0824.ZIP PRM0519A.ZIP PRM0127.ZIP

PRM0823.ZIP PRM0518.ZIP PRM0125.ZIP

PRM0822.ZIP PRM0517.ZIP PRM0124.ZIP

PRM0821.ZIP PRM0516.ZIP PRM0123.ZIP

PRM0819.ZIP PRM0515.ZIP PRM0121.ZIP

PRM0818.ZIP PRM0513.ZIP PRM0120.ZIP

PRM0817.ZIP PRM0512.ZIP PRM0119.ZIP

PRM0816.ZIP PRM0511.ZIP PRM0118.ZIP

PRM0815.ZIP PRM0510.ZIP PRM0117.ZIP

PRM0814.ZIP PRM0509.ZIP PRM0116.ZIP

PRM0812.ZIP PRM0506.ZIP PRM0114.ZIP

PRM0811.ZIP PRM0505.ZIP PRM0113.ZIP

PRM0810.ZIP PRM0504.ZIP PRM0112.ZIP

PRM0809.ZIP PRM0426.ZIP PRM0111.ZIP

PRM0808.ZIP PRM0424.ZIP PRM0110.ZIP

PRM0807.ZIP PRM0503.ZIP PRM0107.ZIP

PRM0805.ZIP PRM0422.ZIP PRM0106.ZIP

PRM0803.ZIP PRM0421.ZIP PRM0105.ZIP

PRM0802.ZIP PRM0501.ZIP dir.txt

PRM0801.ZIP PRM0429.ZIP [.]

PRM0731.ZIP PRM0420.ZIP [..]

PRM0729.ZIP PRM0428.ZIP [Test]

PRM0728.ZIP PRM0419.ZIP

215 File(s) 1,141,877,610 bytes

3 Dir(s) 6,729,723,904 bytes free

How can i single out the most recent file(PRM1024.ZIP) and copy it to another folder. Obviously i will use

FileCopy("M:\Backup" & $file, "M:\Backup\Test" & $file)

So the only thing i need to do is make $file = the most recent file

Share this post


Link to post
Share on other sites



_FileReadToArray()+Loop+_FileGetTime()+FileCopy()


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hi,

there is surely an easier way, but : :">

#include<File.au3>
#include<array.au3>

$path = @ScriptDir
$Filter = "*.bmp"

$FileList = _FileListToArray($path, $Filter, 1)
If (Not IsArray($FileList)) And (@error = 1) Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

Global $createTime_A[UBound($FileList) ]

For $i = 0 To UBound($FileList) - 1
    $createTime_A[$i] = FileGetTime($FileList[$i], 0, 1)
Next

_sort($createTime_A, $FileList, 1)
MsgBox(64, "Most recent", $FileList[0] & " --> with : " & FileGetTime($FileList[0], 0, 1))


Func _sort(ByRef $Master_A, ByRef $Slave_A, $i_Descending = 0, $i_Base = 0, $i_Ubound = 0, $i_Dim = 2, $i_SortIndex = 0)
    If Not IsArray($Master_A) Or Not IsArray($Slave_A) Then SetError(-1)
    If UBound($Master_A) <> UBound($Slave_A) Then SetError(-2)
    Local $sort_A[UBound($Master_A) ][2]
    For $i = 0 To UBound($Master_A) - 1
        $sort_A[$i][0] = $Master_A[$i]
        $sort_A[$i][1] = $Slave_A[$i]
    Next
    _ArraySort($sort_A, $i_Descending, $i_Base, $i_Ubound, $i_Dim, $i_SortIndex)
    For $i = 0 To UBound($sort_A) - 1
        $Master_A[$i] = $sort_A[$i][0]
        $Slave_A[$i] = $sort_A[$i][1]
    Next
    Return 1
EndFunc   ;==>_sort

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

a different approach, (not neccesarily a better one)

$filename = "C:\temp\dir.txt"
RunWait(@ComSpec & " /c dir *.* /B /D /O:S>"&$filename,"", @SW_HIDE)
$file = FileOpen($filename, 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$line = FileReadLine($file)
MsgBox(0, "Newest file:", $line)
FileClose($file)
FileDelete($filename)
;copy file
FileCopy("M:\Backup\" & $line, "M:\Backup\Test\" & $line)

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0