[vox-tech] Removing Files

Tim Riley vox-tech@lists.lugod.org
20 May 2004 17:19:25 -0700


On Thu, 2004-05-20 at 12:21, Daniel Hurt wrote:
> Tim Riley wrote:
> > 
> > Try writing a C program to remove these using the unlink() system
> > call.
> > 
> 
> I tried writing a C program to solve the problem and no luck.  Here is a 
>   link to a bzipped copy of the file if you are interested in looking at it:
> 
> http://www.mcising.net/files/test.c.bz2
> 
> The program takes the current working directory and then prints the 
> contents out.  Then it tries to match any file starting with the 
> character "E" and unlinks that file ( *** BE CAREFUL if you run it, it 
> will unlink all files in the current directory that match that criteria 
> without asking!!! ). The results of running the program are ( no 
> different if run as root ):
> 
> [/usr/media/movies] # ./a.out
> .
> ..
> Evil Dead 3 - Army of Darkness (Director´s Cut).avi
> Found the File!
> Full Filename:
>     /usr/media/movies/Evil Dead 3 - Army of Darkness (Director´s Cut).avi
> Could not delete file
> Error: No such file or directory

The remove works here. Maybe there's a hidden control character in
the filename that's getting in the way. Here's some code to
display the ascii of the filename and the output I get. Does
your output match mine?

Begin code snip
		if( directory_entry->d_name[ 0 ] == 'E' ) {
			printf( "Found the File!\n" );
{
char *ptr = directory_entry->d_name;
while( *ptr )
{
	fprintf( stderr, "%c = %u\n", *ptr, *ptr );
	ptr++;
}
}

End code snip

Begin output

E = 69
v = 118
i = 105
l = 108
  = 32
D = 68
e = 101
a = 97
d = 100
  = 32
3 = 51
  = 32
- = 45
  = 32
A = 65
r = 114
m = 109
y = 121
  = 32
o = 111
f = 102
  = 32
D = 68
a = 97
r = 114
k = 107
n = 110
e = 101
s = 115
s = 115
  = 32
( = 40
D = 68
i = 105
r = 114
e = 101
c = 99
t = 116
o = 111
r = 114
´ = 4294967220
s = 115
  = 32
C = 67
u = 117
t = 116
) = 41
. = 46
a = 97
v = 118
i = 105

End output




> a.out
> test.c.bz2
> 
> Dan
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech