1 /* gnomevfs-ls.c - Test for open_dir(), read_dir() and close_dir() for gnome-vfs
3 Copyright (C) 2003, Red Hat
5 The Gnome Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The Gnome Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the Gnome Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
20 Author: Bastien Nocera <hadess@hadess.net>
23 #include <libgnomevfs/gnome-vfs.h>
27 static void show_data (gpointer item, gpointer no_item);
28 static void list (void);
31 type_to_string (GnomeVFSFileType type)
34 case GNOME_VFS_FILE_TYPE_UNKNOWN:
36 case GNOME_VFS_FILE_TYPE_REGULAR:
38 case GNOME_VFS_FILE_TYPE_DIRECTORY:
40 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
41 return "Symbolic Link";
42 case GNOME_VFS_FILE_TYPE_FIFO:
44 case GNOME_VFS_FILE_TYPE_SOCKET:
46 case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
47 return "Character device";
48 case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
49 return "Block device";
56 show_data (gpointer item, gpointer no_item)
58 GnomeVFSFileInfo *info;
61 info = (GnomeVFSFileInfo *) item;
63 path = g_strconcat (directory, "/", info->name, NULL);
65 g_print ("%s\t%s%s%s\t(%s, %s)\tsize %ld\tmode %04o\n",
67 GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link: " : "",
68 GNOME_VFS_FILE_INFO_SYMLINK (info) ? info->symlink_name
70 GNOME_VFS_FILE_INFO_SYMLINK (info) ? " ]" : "",
71 type_to_string (info->type),
82 GnomeVFSResult result;
83 GnomeVFSFileInfo *info;
84 GnomeVFSDirectoryHandle *handle;
86 result = gnome_vfs_directory_open (&handle, directory,
87 GNOME_VFS_FILE_INFO_GET_MIME_TYPE
88 | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
90 if (result != GNOME_VFS_OK)
92 g_print("Error opening: %s\n", gnome_vfs_result_to_string
97 info = gnome_vfs_file_info_new ();
98 while ((result = gnome_vfs_directory_read_next (handle, info)) == GNOME_VFS_OK) {
99 show_data ((gpointer) info, NULL);
102 gnome_vfs_file_info_unref (info);
104 if (result != GNOME_VFS_OK) {
105 g_print ("Error: %s\n", gnome_vfs_result_to_string (result));
111 main (int argc, char *argv[])
118 directory = g_get_current_dir ();
123 gnome_vfs_shutdown ();