Newbie to powershell wonders if there is a solution

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Steve Froggatt Steve Froggatt 3 years, 5 months ago.

  • Author
    Posts
  • #11635
    Profile photo of Steve Froggatt
    Steve Froggatt
    Participant

    As mentioned in the subject line i am a newbie to powershell, only been using it a week – but love it

    I was wondering if there is either a solution to my predicament or if not, if anyone can point me in the right direction to creating one.

    i have 100's if not 1000's of files that i want to zip up (separate directories), but at the same time as zipping them, I want to create an HTML or XML file that has the link to the file in the zip file (or at least the link to the zip).

    Is this possible ?

    Thanks

  • #11637
    Profile photo of Steve Froggatt
    Steve Froggatt
    Participant

    Hi Dave

    Sorry i wasn't clear, I want to save some save files to the archive but at the same time write an HTML with the name of the file saved, this would be external to the zip, and just a means of knowing what was in the zip by opening the HTML/XML

  • #11638
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Fair enough, that's not too hard to do. PowerShell has a ConvertTo-Html cmdlet. It behaves a lot like Format-Table, except instead of displaying a table as text at the console window, it spits out a table in HTML code. What you can do is structure your code to both add to the zip file and generate an object that eventually gets piped to ConvertTo-Html. I haven't used PSCX or the Write-Zip cmdlet myself yet, but here's some sample code that can help you see what I mean:

    Get-ChildItem -Path $src -Recurse |
    ForEach-Object {
        Write-zip -InputObject $_ -outputpath $target -EntryPathRoot $src -Append
        New-Object psobject -Property @{ Path = $_.FullName }
    } |
    ConvertTo-Html |
    Out-File "c:\index.html"
    
  • #11639
    Profile photo of Steve Froggatt
    Steve Froggatt
    Participant

    That looks good thanks.... However, i now get the initial problem I had, where you gave me the solution to add -EntryPathRoot $src to the Get-ChildItem.
    When i add it this time I get a different error
    Get-ChildItem : A parameter cannot be found that matches parameter name 'EntryPathRoot'.
    At line:3 char:49
    + Get-ChildItem -Path $src -Recurse -EntryPathRoot <<<< $src | + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

  • #11640
    Profile photo of Steve Froggatt
    Steve Froggatt
    Participant

    Ignore the last message, I put -EntryPathRoot in the wrong place, and that was for Write-Zip

  • #11636
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    I'm not sure I understand your question. Are you trying to create an index file that also gets added to the zip file, or something that exists outside of the zip? If the index file is outside the archive, you can't really just click on a link and open a file inside of the zip file. When you double click a zip file in Windows Explorer, it gets extracted to a temporary directory, and that's what you're actually browsing when you open or edit things.

    Creating a link to the zip file itself is not difficult. That's just an anchor tag with an URL starting with file:///, such as < a href="file:///c:/temp/somefile.zip" > < /a > (without the spaces around the < and > symbols; I was struggling to get the forum to just post them as text, rather than creating an actual link.

You must be logged in to reply to this topic.