This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Creating List of Files in a Directory

Old posts that have not been replied to for several years.
Locked
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Creating List of Files in a Directory

Post by Weirdo »

Kind of at a dead loss here. Cant find anything on how to seriously create a text file, and add lines for each file that is in that directory.

Does anyone have any ideas/links which give information on tcl commands that will be able to do this?

Thought a bit on how i would like to do it. Basically involving probably a loop, that would write a new line, then find the next file sorted by date or alphabetical order, and insert the info for that file.

Info for that file being Name of the File <tab> Date created

IE, if the directory is reverse sorted by date, it will do them in sort of order. Most definately the most difficult idea i have ever come across. Gonna be interesting to see if i can actually write the code.

Thanks if you can help me in any way :)

Weirdo
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You should use the search feature of the forum. If I remember corectly, you should find some answers to your questions. One of them is this.
Once the game is over, the king and the pawn go back in the same box.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Ah, must have missed that one when i did my search. Thank you caesar :)

How can you get the information about the files? For example the date modified?

I am assuming the Extension is included with the name. shoudl be easy enough to create a loop to write the output to a line (i hope :P )
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Also you can see this post and this tcl I've did to add, delete and list stuff from an file.
Once the game is over, the king and the pawn go back in the same box.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Weirdo, to get information about the file, use the "file" command. There are subcommands to find out things like access time, modification time, etc. Check the tcl manual.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

TCL manual, rather than Eggdrop tcl manual? where ca i get it for lib8.4?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

www.tcl.tk has all the manuals in the documentation section
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Stdragon, thanks a lot for the little linkie to the manual, the file command is quite extensive :)

So, made some variables using the various commands, chucked them into one of the scripts i use on the channel and using the code below, it does work... bar two

the command " File atime <name> <time>" confuses me, in the help file it says this..
file atime name ?time?
Returns a decimal string giving the time at which file name was last accessed. If time is specified, it is an access time to set for the file. The time is measured in the standard POSIX fashion as seconds from a fixed starting time (often January 1, 1970). If the file doesn't exist or its access time cannot be queried or set then an error is generated. On Windows, FAT file systems do not support access time.
But what does it mean by ?time?, not sure what it is, is it a variable to put the time in?

Same problem with the "file stat name varName" . Now i understand that this creates a series of results, that need to be put into an array
VarName is treated as an array variable, and the following elements of that variable are set: atime, ctime, dev, gid, ino, mode, mtime, nlink, size, type, uid.
Yet, when i place a name of a used array, dir() in the case of this script, it gives me various errors about elements in arrays, and the fact that if i specify a variable in the brackets in dir(), it cannot be put in, i just put dir in, and it wont use it. What do i need to do to get this working?

On a lighter note, removing the references to these give me the nice little result of...
[18:06:06] <Weirdo|SimCity> !picoday
[18:06:08] -Natsuki-Chan- Pic of the Day is filesys/incoming/c23427sample7.jpg -- File information: <Directory - filesys/incoming> <Isfile - 1> <Total File - filesys/incoming/test.jpg>
[18:06:10] -Natsuki-Chan- <Modified - 1049746511> <system - native NTFS> <system volumes - C:/ D:/ E:/ F:/ G:/ H:/ I:/ J:/>
Which makes me damn happy and fills my little mind with future scripting ideas :)

Code: Select all

#	set dir(atime) [file atime $picoday time]
	set dir(dir) [file dirname $picoday]
	set dir(isfile) [file isfile $picoday]
	set dir(join) [file join $dir(main) $dir(filename2)]
	set dir(mtime) [file mtime $picoday]
#	set dir(stat) [file stat $dir()]
	set dir(system) [file system $picoday]
	set dir(volumes) [file volumes]
	puthelp "notice $nick :Pic of the Day is $picoday -- File information: <Directory - $dir(dir)> <Isfile - $dir(isfile)> <Total File - $dir(join)>"
	puthelp "notice $nick :<Modified - $dir(mtime)> <system - $dir(system)> <system volumes - $dir(volumes)>"
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

In tcl syntax, putting ?? around a variable means it's optional. E.g., you can call it either

file atime <name>

or

file atime <name> <time>

As the docs say, the first one simply returns the access time, the 2nd one sets it.

Your second problem with stats maybe arises from a similar misunderstanding. It wants you to pass the name of an array, not the array itself. So if 'dir' is your array variable, you would say

file stat $picoday dir

That command will set elements of dir, such as dir(atime), dir(ctime), dir(dev). You could get rid of your own lines that set dir(atime) and dir(mtime) because this command will do it for you.

A final tip: the times stored in dir(atime), dir(mtime), etc, are in unix timestamp format. You can convert them to a human-readable time/date using, set timestr [clock scan $dir(mtime)] (or whatever var you want). Check the clock command for tips on how to customize the string.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Well, they all work now. the Time code you suggested ended up giving me a heap of errors, so i dipped into the [clock format (variable) -format %c] option :)
[19:48:56] -Natsuki-Chan- Pic of the Day is filesys/incoming/521.jpg -- File information: <Directory - filesys/incoming> <Access Time - 09 April 2003 19:37:01> <Isfile - 1> <Total File - filesys/incoming/test.jpg>
[19:48:58] -Natsuki-Chan- <Modified - 09 April 2003 04:07:24> <Stat - 128246bytes, 33188, file, 0> <system - native NTFS> <system volumes - C:/ D:/ E:/ F:/ G:/ H:/ I:/ J:/>
[19:50:08] <Weirdo|TCL> [19:37:01] <Natsuki-Chan> [19:37] Finished dcc send 521.jpg to Cmosrunner
[19:50:18] <Weirdo|TCL> and its identical :)
[19:50:25] <Weirdo|TCL> Access time = when DCC Send finishes
The Stats script also works :)

Now, all i have to do is the actual scanning of a directory, perhaps use a while loop to write a single line at a time into a text file. This b the fun bit :P
Locked