Git Product home page Git Product logo

Comments (8)

dundee avatar dundee commented on August 15, 2024 1

It's easy to do so programatically. E.g. here is a simple Python script you can use: https://gist.github.com/dundee/97c4a609e9c2d4f7e4bb298bdde4df3a

gdu -f- | python3 abspath.py

from gdu.

dundee avatar dundee commented on August 15, 2024

The export format is compatible with the one of ncdu. The absolute path is there just once in the "header", e.g.:

[1,2,{"progname":"gdu","progver":"development","timestamp":1666468251},
[{"name":"/home/dundee/work/gdu","mtime":1666468247},

The absolute paths of all files should be fairly simple to compose programmatically then.

Does this cover your use case?

from gdu.

SonamorN avatar SonamorN commented on August 15, 2024

Thanks for the answer dundee, I saw the header, I was hoping maybe there was an argument to output the whole path as it would make my use case so much easier than trying to reconstruct the whole path.

I will see what I can do to get the whole path.

from gdu.

SonamorN avatar SonamorN commented on August 15, 2024

@dundee

Hm... if you have a scan of a whole drive with multiple levels, this becomes troublesome. Any chance a special flag to export the whole path is maybe possible?

from gdu.

dundee avatar dundee commented on August 15, 2024

What do you mean by multiple levels?

from gdu.

SonamorN avatar SonamorN commented on August 15, 2024

from gdu.

SonamorN avatar SonamorN commented on August 15, 2024

@dundee

Didn't have the time to deal with it at the moment but kept coming back to this. I am not a developer, neither I write a lot of python, although I am familiar with it.

Thanks for providing an example. Using your example, I was able to create a similar code in powershell, which I provide below, for anyone that might need this in Windows Environment.

Although using Powershell 7+, this should run on any OS that is supported by version 7 of Powershell.


[cmdletbinding()]
param(
    [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
    [string]$jsonFile
)

function  ConvertTo-FullPath {
    param($data,
        [string]$path)

    if (-not ([string]::IsNullOrEmpty($path))) {
        $path = "$($path)\$($data[0].Name)" 
    }
    else {
        $path = "$($path)$($data[0].Name)" 
    }
         
    foreach ($item in ($data | Select -Skip 1) ) {
        if ($item.GetType().BaseType.Name -eq "Array") {
            ConvertTo-FullPath -data $item -path $path
        }
        else {
            $pathLast = "$($path)\$($item.name)"
        }

        [void]$results.Add($pathLast)   
    }    
}

$results = [System.Collections.ArrayList]@()

$data = Get-Content -Raw $jsonFile | ConvertFrom-Json 

$fileInfo = Get-Item $jsonFile
$outputBaseName = $fileInfo.BaseName
$outputDirName  = $fileInfo.DirectoryName   
$outputFileName = "$($outputDirName)\$($outputBaseName).txt"

ConvertTo-FullPath -data $data[3] -path ''

$results | Out-File -FilePath $outputFileName -Encoding UTF8

Usage:

"C:\test\1.json" | C:\test\ConvertTo-FullPath.ps1

The script by default will output a txt file at the same path as the json.
It will have the same filename as the json file but with a txt extension.
The txt file will containthe fullpath of all the files.

I am usually using gdu to get all the filenames from a disk and then scan using LINQ for known filenames with CVEs, therefore having the wholepath is very helpful.

PS. There seems to be an issue with gdu or json formatting, which will cause the filepath that was picked to run gdu against to have an extra trailing backslash. This will also be present at the output. I couldn't care less about an extra backslash being therefore I am leaving it as it is.

Once again thanks for your work here.

from gdu.

dundee avatar dundee commented on August 15, 2024

Thanks for sharing!

from gdu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.