Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: renaming a file and moving into another folder

by Marshall (Canon)
on Sep 21, 2011 at 17:31 UTC ( [id://927182]=note: print w/replies, xml ) Need Help??


in reply to renaming a file and moving into another folder

Update: I see that this post has gotten a down vote for no apparent reason from the voter (no reply to my post).
That is unfortunate.
If that happened because my tone may offend the OP, it was not my intent at all to offend the OP.
I see the problem of not understanding the idea of "text of filename"->(pointer) to data often with Windows students.
If there is a way to explain it better than I did, then great! Please post!

---original post continues---

Deleted perhaps inflammatory statement.

Your question demonstrates a fundamental lack of understanding of how a file system works.A file does not "exist in a directory" - NO! - that is not what happens!

As a simplification, lets say that a file is just a "block of contiguous bits/bytes on the disk". The disk is a huge block of contiguous bytes from say byte 0 to byte 2,000,000,000. A file may exist from byte 10356 to byte 22356 on the disk.

The directory entry for "c:\ksk\vista\sra.txt" would be a data structure with an association between that text name and a pointer to say byte 10356 as the "start" and this text name would also have a length of 22356-10356+1 bytes associated with it. There would be other properties associated with that text name - this is called a "directory entry" - like the telephone "white pages": name, address, etc.

So if we "rename" sra.txt to SRA_new.txt:
That means that this directory entry text name that associates "c:\ksk\vista\sra.txt" to byte 10356 on the disk changes to "c:\ksk\vista\SRA_new.txt". No data on the disk moves.

If we want to "move" the file to a different directory on the same physical disk drive/file system, no bits in the file are actually "moved"!! NO!! We just create a new entry: "C:\home\sra.txt" to point to byte 10356 and delete the entry for "c:\ksk\vista\sra.txt".
So "moving a file to a different directory on the same disk" is the same as "renaming it"!

Moving a file from one physical disk to another is different. We have to create a directory entry on the other disk, copy the bits from disk1 to disk2, delete the directory entry on disk1, etc.

I am sorry that I got long winded here. But there is NO difference in what happens to the bits on the disk between "changing the name associated with those bits" and "moving those bits to a different directory" - this is just changing the text name associated with the starting byte of the data.

  • Comment on Re: renaming a file and moving into another folder

Replies are listed 'Best First'.
Re^2: renaming a file and moving into another folder
by Anonymous Monk on Sep 21, 2011 at 18:33 UTC

    It was downvoted because it is entirely irrelavent and unhelpful to the questioner.

    No, you do not move the contents of the file. But you DO move its directory entry. And as the only way to access the contents is via its directory entry, the effect is the same.

    Picking out one commonly used but slightly misnomeric term and then using as a stick with which to beat the newbie is the very worst kind of elitism.

      Sorry that my post appeared to be unhelpful to you.

      I try to be solidly on the side of "anti-elitism". I try not to use tricky Perl syntax when writing code for new folks. I try to explain how what I write works. In this case, I agree that I sounded too "high almighty". There are limitations in this textual format and sometimes what is heard is not what I intended.

      However I have seen this misconception about a file "lives in a folder" versus "a file is just a set of bits and a pointer to those bits lives in the directory" so often that it provoked a reflex response. This misconception happens a lot even at the university level. This is not a minor point. It is the same idea like Perl reference counting.

      Hard disk I/O isn't covered very well in school. I guess I got carried away.

        I try not to use tricky Perl syntax when writing code for new folks. I try to explain how what I write works

        Post a working solution to the questioners problem, and even if they do not understand how it works, they make forward progress. And it encourages some of them to read or question how it works, and learn in the process.

        It is completely irrelevant to the users of rename what actually happens under the covers. You could go through an entirely succcessful career without ever knowing those details.

        Explaining them, especially at a level that despite your verbosity, was entirely superficial, as it does not describe what actually happens in any given file system, does not help answer the question asked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://927182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-05-21 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found