List file shares from TAR file

  • How can I list just the directories from a TAR file, then extract just 1 file share from that TAR file.

    Thanks.

  • What command are you using for tar?  If you are using the native tar built into windows 10, then you would run:

    tar -tf <archive name>

    which will give you the contents of the tar, as is indicated in the documentation for tar.  tar /? will give you all of the commands supported by tar and how to use them.

    That being said, a tar file doesn't contain "file shares" - it contains files.  Plain old files.  So if you want to use the above and get DIRECTORY information only, you would need to take the output of the above and parse it in Powershell to strip off the file name.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

  • Thanks for info,  have output in .txt file now. What syntax for the P/S script to strip a distinct list of folders?

    Thx.

  • I think it depends on your source.  I am assuming this is still the TAR source, in which case you would just need to treat it like a bunch of strings.  So, the script isn't too hard to work with, but you end up with something like this:

    $tarFiles = tar -cf <input file>
    foreach ($tarFile in $tarFiles) {
    if ($tarFile.trimstart("./") -notmatch "\.") {
    $tarFile
    }
    }

    That should give you a distinct list of folders and exclude all files.  Basically, what it is doing is storing the results of the tar -cf into a variable which will be an array of strings.  Next, we are looping through the array to find the path that does not contain a . in it.  To do so, we first need to strip off the leading ./ characters (technically, just need to remove the ., but no harm in grabbing the / as well).  Then we are finding all files that still contain a . character and excluding them with the NOT MATCH.

    Mind you, this approach has a flaw.  I am assuming you have no folders with a . in the folder name.  What I mean is if you had a path like "./test/test.CSVFiles/", this would get excluded in my approach.  Now, if you know that each folder only contains .jpg files (for example), you could tweak the above to do a notmach on "\.jpg".  The \ is an escape character for the ., otherwise the match treats the . as any character (I believe... been a while since I read the docs on that).

    I suppose a good question to ask would be "what are you trying to accomplish?"

    EDIT - also, in Powershell my approach is to avoid writing to disk unless I have to.  I would much rather have things in memory as it is easier to work with.  So I wouldn't write the results to file until your variable contains the subset of data you are actually wanting.  Mind you, once you have it in a file, you can use other tools to analyze the data such as Excel.  With that text file, you could use Excel to grab the last character and toss it into a column.  Then filter it out to only show you "/" and you would have all of the directories.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

  • Thanks for ALL the info.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply