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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read and manipulate directories and files?

Status
Not open for further replies.

LilTCLer

Programmer
Nov 27, 2007
37
US
I can't figure out how to read the contents of a directory that includes other directories and files.

For example, here is what I want to do.

1. cd to a particular directory.
2. read contents of the directories within, and manipulate the dir names so I can "grab" the 3 directories with the latest timestamps.
3. In each of the three dorectories above, I then will do a file exists for a particular file within.

My issue is trying to read and parse the contents of a particular directory.

Any ideas where to start?
 
Hi
[ul]
[li]get the list of directories with [tt]glob[/tt][/li]
[li]walk over the list with [tt]foreach[/tt] and for each[ul]
[li]get the modification time with [tt]file[/tt][/li]
[li]push the time-name pair in a second list with [tt]lappend[/tt][/li][/ul][/li]
[li]sort that second list with [tt]lsort[/tt][/li]
[li]walk over the first 3 elements of the sorted list with [tt]for[/tt] and for each[ul]
[li]extract the given element with [tt]lindex[/tt][/li]
[li]check if the searched file exist with [tt]file[/tt][/li][/ul][/li]
[/ul]


Feherke.
 
mtime (modify time), is returned in decimal for example:

FP6_0_BZ020_20090915 - 1253047000
FP6_0_BZ021_20090916 - 1253107209
FP6_0_BZ022_20090917 - 1253182442
FP6_0_BZ023_20090918 - 1253272139
FP6_0_BZ024_20090919 - 1253368601
FP6_0_BZ025_20090920 - 1253438610
FP6_0_BZ026_20090921 - 1253542557
FP6_0_BZ027_20090922 - 1253641722

is there a way to convert this to date, time, etc?
 
Hi

LilTCLer said:
mtime (modify time), is returned in decimal for example: [gray](...)[/gray] is there a way to convert this to date, time, etc?
Is there any reason to convert it ? For sorting numeric is the best and you need them only for sorting. Or am I wrong ?

To answer your question, [tt]clock[/tt] can be used to convert the Unix time into formatted string.

Feherke.
 
I may need to be able to search for a specific date and time later on in the script.
 
Hi

Got it. Then you indeed will need [tt]clock[/tt]. However I would think at converting the searched date & time into Unix time. Of course, which approach is better may depend on the task.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top