addictedtofunk Posted October 18, 2006 Posted October 18, 2006 I want to copy a *.zip file that was last modified in a directory to another directory. How would i do this?
The Kandie Man Posted October 18, 2006 Posted October 18, 2006 Use the helpfile and look at FileGetTime(). Also look at FileFindFirstFile(), FileFindNextFile (), FileClose(), and lastly while loops. Here is an example on how to use them, straight from the help file: ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File:", $file) WEnd ; Close the search handle FileClose($search) Now all you have to do is feed the $file variable into the FileGetTime() function and then compare it to other values. I suggest you use an array to store the name of the file and the time $timestamp[0][0] = [name of the file] and then use something like $timestamp[0][1] = [time] to store the time. Use a > or a < statement to compare it to the array. If the time is newer than the value in the array, change the value in the array and proceed to the next file. When it completes searching in the directory, it should then stop and the remaining values in the array will be what you need to use. Then simply use the FileCopy() or FileMove() function to move the file from that directory to a directory you choose. "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire
addictedtofunk Posted October 19, 2006 Author Posted October 19, 2006 Use the helpfile and look at FileGetTime(). Also look at FileFindFirstFile(), FileFindNextFile (), FileClose(), and lastly while loops. Here is an example on how to use them, straight from the help file: ; Shows the filenames of all files in the current directory. $search = FileFindFirstFile("*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop MsgBox(4096, "File:", $file) WEnd ; Close the search handle FileClose($search) Now all you have to do is feed the $file variable into the FileGetTime() function and then compare it to other values. I suggest you use an array to store the name of the file and the time $timestamp[0][0] = [name of the file] and then use something like $timestamp[0][1] = [time] to store the time. Use a > or a < statement to compare it to the array. If the time is newer than the value in the array, change the value in the array and proceed to the next file. When it completes searching in the directory, it should then stop and the remaining values in the array will be what you need to use. Then simply use the FileCopy() or FileMove() function to move the file from that directory to a directory you choose. Sorry but i am a bit a nwebie to this, i have read up on all thse things and still dont really know what to do, can you start me off or explain in more detail.
jinxter Posted October 19, 2006 Posted October 19, 2006 you could also use the dir parameter /O:-S /D ... c:>dir *.* /O:-S /D>dir.txt the first file found is the newest. Just read first line in dir.txt and move accordingly. > there are 10 types of people in the world, those who understand binary and those who don't.
addictedtofunk Posted October 20, 2006 Author Posted October 20, 2006 you could also use the dir parameter /O:-S /D ... c:>dir *.* /O:-S /D>dir.txt the first file found is the newest. Just read first line in dir.txt and move accordingly. Unable to parse line???
jinxter Posted October 20, 2006 Posted October 20, 2006 (edited) sorry, I was just showing how to do it in a dosbox, with c:> being the prompt. try this in autoit instead. RunWait(@ComSpec & " /c dir *.* /D /O:-S>dir.txt","", @SW_HIDE) explanation: /D makes dir just show the filenames (without the date and such) /O sorts the dir in according to sortorder S (by size, smallest first) the minus sign reverse the sorting order. Edited October 20, 2006 by jinxter > there are 10 types of people in the world, those who understand binary and those who don't.
addictedtofunk Posted October 21, 2006 Author Posted October 21, 2006 sorry, I was just showing how to do it in a dosbox, with c:> being the prompt. try this in autoit instead. RunWait(@ComSpec & " /c dir *.* /D /O:-S>dir.txt","", @SW_HIDE) explanation: /D makes dir just show the filenames (without the date and such) /O sorts the dir in according to sortorder S (by size, smallest first) the minus sign reverse the sorting order. Ok so that worked but the txt file has columns in it so the first line has multiple files in it, how do i single out the first one?
jinxter Posted October 23, 2006 Posted October 23, 2006 (edited) add a /B for bare format... RunWait(@ComSpec & " /c dir *.* /B /D /O:-S>dir.txt","", @SW_HIDE) It somehow was a bit different from the output to the cmd-window. If you want to single out the first entry in a tabbed row I would search the firts line for a tab and use that in a StringLeft (), or perhaps use a StringSplit(). Hope it'll help some Edited October 23, 2006 by jinxter > there are 10 types of people in the world, those who understand binary and those who don't.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now