Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i want to take the last file without check the other files from folder

Status
Not open for further replies.

testeralex

Programmer
May 21, 2008
4
US
well, i want to start in the last file in the folder, but i couldn't find the away, because always check the first to last file. I need to check the last file to first file in the folder. how can i start in the last file in the folder?
 
Check the last file for what? What code have you written so far?

It sounds like you want to check the files in reverse order - but reverse order of what (Name, file size, last modified date)

Need some actual information before we can help you out properly!

Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me

For all your testing needs: Forum1393
 
yes, i want to check the files in reverse order. because when i find the file in the folder appeared older to newer files.

i want to check the logs and i want to take the newest.
 
Using the FileSystemObject, pretty sure you can sort the files in date order - then you can just pick up the first file in the collection?



Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me

For all your testing needs: Forum1393
 
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

FolderToScan = "C:\"

Set objFolder = objFSO.GetFolder(FolderToScan)

NewestFile = ""
NewestDate = #1/1/1970#

For Each objFile In objFolder.Files
	If objFile.DateLastModified > NewestDate Then
		NewestDate = objFile.DateLastModified
		NewestFile = objFile.Name
	End If
Next

WScript.Echo NewestFile

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
thank i tried, but my problem is: i have to check 100 files in the remote machine and always i want to take the last file, because they are the newest then this action take much time.
i would like to check the files in reverse order, just take the last files first. how can i do that?
 
The solution I have given you will give you the name of the file that was last modified, therefore the newest log file.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
sorry, i have to pay, thank you. I'm going to find other option.
 
If you want to scroll through all the files, newest to oldest, you can store them in an array and then sort the array:

Code:
Option Explicit
Dim objFSO, objFile, objFolder, FolderToScan
Dim c, i, j
FolderToScan = "D:\EricData\vbs"
Set objFSO = CreateObject("Scripting.fileSystemObject") 
Set objFolder = objFSO.GetFolder(FolderToScan)

Dim arrFileName(), arrFileDateLastModified()

c = 0
For Each objFile In objFolder.Files
	c = c + 1
	
	ReDim Preserve arrFileName(c)
	arrFileName(c) = objFile.Name

	ReDim Preserve arrFileDateLastModified(c)
	arrFileDateLastModified(c) = objFile.DateLastModified 
Next

For i = 1 To c
	For j = i + 1 To c
		If arrFileDateLastModified(i) < arrFileDateLastModified(j) Then
			SwapValues arrFileName(i), arrFileName(j)
			SwapValues arrFileDateLastModified(i), arrFileDateLastModified(j)
		End If
	Next
Next

For i = 1 To c 
	Wscript.echo "File: " & arrFileName(i) & "  Last mod: " & arrFileDateLastModified(i)
Next 

Sub SwapValues(ByRef v1, ByRef v2)
	Dim vTemp
	vTemp = v1
	v1 = v2
	v2 = vTemp
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top