Logic for Directory System

Asked

Viewed 100 times

1

I have a directory system in the bank

ex table directory:

id
parentDirID

Parent dir means q is a subdirectory.

What would the function of "copy" directories look like in the system? move directories would just update the parentDirID, so it would just change places by logic. And to copy a directory with Subdirectories? Because if I generate a new directory with a different id, the old one’s subdirectories won’t point to the new one, and I can’t create the same id either because it would be wrong. What is the solution? inserir a descrição da imagem aqui

  • Put the code/template to one to see how you’re doing and better understand what the problem is. Maybe your problem is something else. Maybe you are modeling wrong, a directory should not depend on the location of your father.

  • @bigown ,but that’s exactly how the system is here. If the parentDir is null, then it’s root, if it has something it’s child of the same.

  • I keep saying you need to put more information from your code/template.

  • @bigown just posted a print, the same is just a table for the directory, the rest is files, but in relation to files it is all right to copy and move, because it does not depend on children, but for the directory I could only move.

  • This doesn’t show what you’re putting up. I don’t know what information goes there. I don’t know what that is REFERENCIA. In my mind change the PARENT of a directory should not invalidate the directories that point to that directory as its PARENT. I don’t see why I would do this. But if you’re doing it you need to show it. It’s the last attempt to get relevant information before I give up.

  • pq the Parent points to the DIRECTORY then when I copy a directory I add a new one and the same goes with a new ID so the references to this new one are invalid.. Reference also do not know came.

Show 1 more comment

1 answer

1


A copied directory is a new directory, so you need a new Id. This goes for children too - a new directory will also be created for each child, so each child needs a new Id.

Original table content (indentation is for highlighting subdirectories):

id 1 - pastaA - parentDirID: null
    id 2 - pastaB - parentDirID: 1
        id 3 - pastaC - parentDirID: 2

id 4 - pastaD - parentDirID: null
    id 5 - pastaE - parentDirID: 4
        id 6 - pastaF - parentDirID: 5

Now we will copy the pastaE down from pastaB.

New directories will be generated pastaE and pastaF, therefore new Ids. Table content after copy:

id 1 - pastaA - parentDirID: null
    id 2 - pastaB - parentDirID: 1
        id 3 - pastaC - parentDirID: 2
        id 7 - pastaE - parentDirID: 2
            id 8 - pastaF - parentDirID: 7

id 4 - pastaD - parentDirID: null
    id 5 - pastaE - parentDirID: 4
        id 6 - pastaF - parentDirID: 5

Completion

To the move a directory, just changes its Parent ID.

To the copy a directory, a directory new is created, so you need a new ID. A new directory is also created for each subdirectory, and each of these new subdirectories points to your Parent ID for the newly created parent ID.

As for the files, new ones will also be created in a copy, so they will also receive new Ids and new Ids.

Another modeling option

Your current modeling can be quite difficult to maintain. I would do so:

Diretorios
id - caminho 
 1 - pastaA
 2 - pastaA/pastaB
 3 - pastaA/pastaB/pastaC

Arquivos
id - id_diretorio
 1 - 1
 2 - 1
 3 - 2

It’s simpler - no hierarchy of records, will save a lot of code and simplify reading the table content.

  • In the case here I will have to apply the current model, because the system is almost finished, so I apply a recursive function to solve this and that’s it. vlw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.