?
Solved

change file to directories and vice versa

Posted on 2004-08-12
7
Medium Priority
?
247 Views
Last Modified: 2010-04-22
Hi,
It's funny to think or say but i have a question in my mind,
is there any way to change the files to directories or vice versa by some way.like changing the in its property of
drwxr--r-- to -rwxr--r--
if it could be please suggest
0
Comment
Question by:decentswati
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Accepted Solution

by:
alikoank earned 272 total points
ID: 11782400
on some systems you can see their contents by cat command.

try typing

cat mydir > test.bin

that may or may not work on your filesystem.
0
 
LVL 23

Assisted Solution

by:brettmjohnson
brettmjohnson earned 264 total points
ID: 11784010
In most filesystems directories ARE files.  Some OS's even allow you to use
open(), read(), write(), etc to access the data.  However the directory's file
contents is highly structured and specific to the file system implementation.
So using write() to modify a directory file runs a very high risk of rendering
the filesystem unusable if you don't know what you are doing.

To aid the programmer in managing that structured information, the OS
provides abstracted access using opendir(), readdir(), etc.

0
 
LVL 6

Assisted Solution

by:de2Zotjes
de2Zotjes earned 264 total points
ID: 11787493
On unix systems the main difference between a regular file and a directory file is that you cannot use the write-systemcall on a directory file :-)

But to get back to the question: you might be able to change the properties of the directory file so it becomes a regular file, but you would destroy a large chunk of your filesystem in the process.

I can see no good reason to do this other than satisfying you curiosity (which is a good enough reason for me :-) But before you even try, make sure the filesystem you kill holds no unique data..
0
 
LVL 1

Author Comment

by:decentswati
ID: 11799591
Hi de2Zotjes,
really I think the way is to change the property of directory file to make it a regular file.give me the suggestion so that I can try it.OfCourse there is no reason or need to do that but knowing the thing will make concepts clear.Help me.

bye
decentswati
0
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 11800085
Make sure you have libext2fs on your system (ldconfig -p|grep ext2fs) It is part of the e2fsprogs collection.

After that it would be something like:
(this is pseudo-code!)

#include <ext2fs.h>

main () {
err_code = ext2fs_read_inode(fs,inode_num,&inode)
inode.i_mode = inode.i_mode | LINUX_S_IFDIR
ext2fs_write_inode(fs,inode_num, &inode)
}

Not even close to a working program but these are the funtions you would need to use.

Again: you most likely WILL f*ck up your complete file system! dump before you try this.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question