Sponsored Content
Top Forums Programming Finding largest file in current directory? Post 66344 by Perderabo on Sunday 13th of March 2005 12:03:58 PM
Old 03-13-2005
Quote:
Originally Posted by AusTex
Shouldn't something like this work for filesize? It doesn't print the correct size.
Code:
 struct stat statbuffer;
struct dirent *entry;
if(S_ISREG(statbuffer.st_size){
int i = sizeof(entry->d_name);
printf("%d\n", i);}

Any help would be greatly appreciated.
You use S_ISREG on the st_mode entry just as your earlier code showed. You can't use it on anything else. Once you know you have a file, just display statbuffer.st_size. st_size is the size.

The sizeof operator just gives you the size of the variable...you can't do stuff like x=sizeof("Earth") to find out how big the Earth is.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to see all file in a current directory

Hi, I am unable to see all files in a current directory when use "ls -lrt" command it is giving error message as below ( I think this current directory is having about 500 files) <CONTROL /home/ckanth/sri>ls -lrt UX:ls: ERROR: Out of memory: Insufficient or invalid memory But when i... (3 Replies)
Discussion started by: srikanthus2002
3 Replies

2. Shell Programming and Scripting

finding largest directories in a filesystem

I'm trying to come up with a way of finding largest directories in a filesystem (let's say filesystems is running ot of space and I need to find what is consuming all the space). If a directory is a single filesystem, then it's easy, I just run "du -sk *| sort -nr". But the problem is, if some... (8 Replies)
Discussion started by: GKnight
8 Replies

3. Shell Programming and Scripting

finding 0 byte files in current directory only

Hi Gurus, I have a directory A, which has some 0 byte files in it. This directory also has a subdirectory B which also has some 0 byte files in it. The problem: I only need to find out the names of the 0 byte files in the directory A. I'm using the following command find . -name *.zip... (6 Replies)
Discussion started by: ramky79
6 Replies

4. UNIX for Dummies Questions & Answers

finding largest files (not directories)?

hello all. i would like to be able to find the names of all files on a remote machine using ssh. i only want the names of files, not directories so far i'm stuck at "du -a | sort -n" also, is it possible to write them to a file on my machine? i know how to write it to a file on that... (2 Replies)
Discussion started by: user19190989
2 Replies

5. UNIX for Dummies Questions & Answers

How to find the list of 5 largest file in current directory?

Hello, How to find the list of 5 largest(size wise) file in current directory?i tried using ls -l | sort -t " " -r +5 -6 -n | head -5 but this is not giving correct output as ls -l command gives 1 extra line of output that is how many total files are there!so by running the above... (4 Replies)
Discussion started by: salman4u
4 Replies

6. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

7. UNIX for Dummies Questions & Answers

Best way to find largest files in a directory

What is the best way to find the largest files in a directory? I used du -k|sort -rn |less. I got a results for this. But if I used the following command , I got another result...a different order in the same directory. Why is that? ls -la |awk '{print $5," ",$9}' sort -rn|less. I saw that... (6 Replies)
Discussion started by: Pouchie1
6 Replies

8. Shell Programming and Scripting

To Find the largest file in the given directory.

Hi Experts, 1. In unix how to list the largest file in given directory. The answer will in single line statement. 2. I have Sun solaris live CD .I try to compile sample c program using "CC compiler".But its shows "cc command not found". Please help on this. Thanks in advance.... (4 Replies)
Discussion started by: kkl
4 Replies

9. Shell Programming and Scripting

Finding 4 current files having specific File Name pattern

Hi All, I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length. 1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number... (6 Replies)
Discussion started by: lancesunny
6 Replies

10. UNIX for Beginners Questions & Answers

Finding largest files takes too long

Good evening. because the folder has thousand of files it takes too long and have some trouble to get the largest files and then compress files or delete it, for instance find . -size +10000000c -exec ls -ld {} \; |sort -k5n | grep -v .gz The above commad took an hour and i have to cancel... (10 Replies)
Discussion started by: alexcol
10 Replies
create-native-map(1)					      General Commands Manual					      create-native-map(1)

NAME
create-native-map - C/C# Mapping Creator SYNOPSIS
create-native-map [OPTIONS]* ASSEMBLY-FILE-NAME OUPUT-PREFIX OPTIONS
--autoconf-header=HEADER HEADER is a header file name in the syntax typically used with the C #include statement, e.g. #include <stdio.h> or #include "local.h" . An Autoconf-formatted macro is generated from the include name, and a #include directive is wrapped within a #ifdef block for the Autoconf macro within the generated .c file. For example, --autoconf-header=<stdio.h> would generate the code: #ifndef HAVE_STDIO_H #include <stdio.h> #endif /* ndef HAVE_STDIO_H */ --autoconf-member=MEMBER Specify that any access to MEMBER should be wrapped within a #ifdef HAVE_MEMBER block. MEMBER can be either a field-name or a class-name . field-name combination. For example, given the C# declaration: [Mono.Unix.Native.Map ("struct dirent")] struct Dirent { public long d_off; } then --autoconf-member=d_off would generate the code similar to: int ToDirent (struct dirent *from, struct Dirent *to) { #ifdef HAVE_STRUCT_DIRENT_D_OFF to->d_off = from->d_off; #endif /* ndef HAVE_STRUCT_DIRENT_D_OFF */ } --exclude-native-symbol=SYMBOL SYMBOL is a [DllImport] -marked method that should not have a prototype generated for it. --impl-header=HEADER Insert a #include statement within the generated .c file for HEADER . For example, --impl-header=<stdlib.h> generates #include <stdlib.h> --impl-macro=MACRO Insert a #define statement within the generated .c file. MACRO can contain a = to separate the macro name from the macro value. For example, --impl-macro=FOO=42 generates #define FOO 42 --library=LIBRARY Create prototypes for [DllImport] -marked methods which reference the native library LIBRARY into the generated .h file. --public-header=HEADER Insert a #include statement within the generated .h file for HEADER . For example, --public-header=<stdlib.h> generates #include <stdlib.h> --public-macro=MACRO Insert a #define statement within the generated .h file. MACRO can contain a = to separate the macro name from the macro value. For example, --public-macro=FOO=42 generates #define FOO 42 --rename-member=FROM=TO This is used when FROM is a C macro, and thus must be altered in order to be used sanely. All generated references to the managed representation will use TO instead of FROM . For example, given the C# declaration: [Mono.Unix.Native.Map ("struct stat")] struct Stat { public long st_atime; } and the argument --rename-member=st_atime=st_atime_ , the generated .h file would contain: struct Stat { gint64 st_atime_; }; (note the altered field name), while the generated .c file would contain: ToStat (struct stat *from, struct Stat *to) { to->st_atime_ = from->st_atime; } --rename-namespace=FROM=TO By default, the C "namespace" (symbol prefix) is the C# namespace; types within the C# namespace Mono.Unix.Native would be in the C "namespace" Mono_Unix_Native . Use --rename-namespace to modify the default, e.g. --rename-namespace=Mono.Unix.Native=Mono_Posix . DESCRIPTION
create-native-map is a program for a specific scenario: keeping code which is tightly coupled between C and C# in sync with each other, based upon the C# types. Platform Invoke is only useful if the managed code knows the exact types and layout of all unmanaged structures it uses. This is usually the case on Windows, but it is not the case on Unix. For example, struct stat makes use of types with sizes that will vary from platform to platform (or even based on the compiler macros defined!). For example, off_t is usually a signed 32-bit integer on ILP32 platforms, but may be a signed 64-bit integer on LP64 platforms, but may also be a 64-bit signed integer on ILP32 platforms if the _FILE_OFFSET_BITS macro has the value 64. In short, everything is flexible within Unix, and managed code can't deal with such flexibility. Thus, the niche for create-native-map : assume a fixed ABI that managed code can target, and generate code to "thunk" the managed represen- tations to the corresponding native representations. This needs to be done for everything that can vary between platforms and compiler flags, from enumeration values ( SIGBUS has the value 10 on FreeBSD but 7 on Linux) to structure members (how big is off_t ?). create-native-map will inspect ASSEMBLY-FILE-NAME and output the following files: OUTPUT-PREFIX.h Contains enumeration values, class and structure declarations, delegate declarations, and [DllImport] -marked methods (from the library specified by --library ) within the assembly ASSEMBLY-FILE-NAME . OUTPUT-PREFIX.c Contains the implementation of enumeration and structure conversion functions. OUTPUT-PREFIX.cs Contains a partial class NativeConvert containing enumeration translation methods. OUTPUT-PREFIX.xml Generates ECMA XML documentation stubs for the enumeration translation methods in OUTPUT-PREFIX.cs . create-native-map primarily looks for MapAttribute -decorated types, and makes use of two MapAttribute properties: NativeType Contains the corresponding C type. Only useful if applied to classes, structures, and fields. SuppressFlags When specified on an enumeration member of a [Flags] -decorated enumeration type, disables the normal code generator support for bit-masking enumeration types. This is useful when bitmask and non-bitmask information is stored within the same type, and bitmask checking shouldn't be used for the non-bitmask values. Example: Mono.Unix.Native.FilePermissions.S_IFREG , which is not a bitmask value, while most of FilePermissions consists of bitmask values ( FilePermissions.S_IRUSR , FilePermissions.S_IWUSR , etc.). The MapAttribute attribute can be specified on classes, structures, delegates, fields, and enumerations. Delegates Code generation for delegates ignores the MapAttribute.NativeType property, and generates a function pointer typedef that best matches the delegate declaration into the .h file. For example, namespace Foo { [Map] delegate string MyCallback (string s); } generates the typedef : typedef char* (*Foo_MyCallback) (const char *s); Classes and Structures A [Map] -decorated class or structure will get a C structure declaration within the .h file: [Map] struct Foo { public int i; } becomes struct Foo { public int i; }; If the MapAttribute.NativeType property is set, then conversion functions will be declared within the .h file and created within the .c file: namespace Foo { [Map ("struct stat")] struct Stat { public uint st_uid; } } becomes /* The .h file */ struct Foo_Stat { unsigned int st_uid; }; int Foo_FromStat (struct Foo_Stat *from, struct stat *to); int Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to); /* The .c file */ int Foo_FromStat (struct Foo_Stat *from, struct stat *to) { memset (to, 0, sizeof(*to); to->st_uid = from->st_uid; return 0; } int Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to) { memset (to, 0, sizeof(*to); to->st_uid = from->st_uid; return 0; } Fields If a field (1) has the MapAttribute attribute, and (2) has the MapAttribute.NativeType property set, then the specified native type will be used for overflow checking. For example: namespace Foo { [Map ("struct stat")] struct Stat { [Map ("off_t")] public long st_size; } } generates /* The .h file */ struct Foo_Stat { gint64 st_size; }; int Foo_FromStat (struct Foo_Stat *from, struct stat *to); int Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to); /* The .c file */ int Foo_FromStat (struct Foo_Stat *from, struct stat *to) { _cnm_return_val_if_overflow (off_t, from->st_size, -1); memset (to, 0, sizeof(*to); to->st_size = from->st_size; return 0; } int Foo_ToStat (struct stat *to, sxtruct Foo_Stat *to) { _cnm_return_val_if_overflow (gint64, from->st_size, -1); memset (to, 0, sizeof(*to); to->st_size = from->st_size; return 0; } This is useful for better error checking within the conversion functions. MapAttribute.NativeType is required for this as there is no other way to know what the native type is (without parsing the system header files...). Enumerations Generates a C enumeration and macros for each of the members within the enumeration. To and From functions are also declared in the .h file and implemented in the .c file. For example, namespace Foo { [Map] enum Errno { EINVAL } } would generate the following in the .h file: enum Foo_Errno { Foo_Errno_EINVAL = 0, #define Foo_Errno_EINVAL Foo_Errno_EINVAL }; int Foo_FromErrno (int from, int *to); int Foo_ToErrno (int from, int *to); and generates the following in the the .c file: int Foo_FromErrno (int from, int *to) { *to = 0; if (from == Foo_Errno_EPERM) #ifdef EINVAL {*to = EINVAL;} #else {errno = EINVAL; return -1;} #endif return 0; } int Foo_ToErrno (int from, int *to) { *to = 0; #ifdef EINVAL if (from == EINVAL) {*to = Foo_Errno_EPERM; return 0;} #endif return -1; } Different code will be generated if the managed enum is a [Flags] -decorated enumeration (to account for bitwise flags), but this is the basic idea. MAILING LISTS
Visit http://lists.ximian.com/mailman/listinfo/mono-devel-list for details. WEB SITE
Visit http://www.mono-project.com for details create-native-map(1)
All times are GMT -4. The time now is 04:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy