Visualizzazione dei risultati da 1 a 2 su 2

Hybrid View

  1. #1

    Powershell: assegnare temporaneamente una variabile (carattere illegale) ai nomi dei files per farli coincidere con i nomi sul sito

    Per rinominare i files pdf presenti sul mio pc uso uno script che confronta i nomi locali con quelli presenti sul sito.
    Se i nomi coincidono lo script lavora e riordina i files secondo un certo criterio.

    Ad esempio, nella cartella i files sono cosi nominati

    codice:
    1611.00057
    1611.00066

    Applico lo script powershell .ps1 e i file mi vengono rinominati correttamente in

    codice:
    Holomorphy of adjoint $ L $ functions for quasisplit A2
    Many Haken Heegaard splittings
    e spostati nelle relative cartelle.

    Questo è possibile perchè sul sito i nomi appaiono cosi




    Ora.. il problema è che mi sono imbattuto in nomi con la barra /, questi sono i nomi che appaiono sul sito

    codice:
    quant-ph/9802001
    quant-ph/9802004

    I file presenti sul mio pc hanno invece questi nomi

    codice:
    quant-ph9802001
    quant-ph9802004

    Qual'è il problema ?

    Non posso assegnare la barra / perchè è un carattere illegale. Ma questa mancata corrispondenza dei nomi impedisce al mio codice di svolgere il mio lavoro.
    L'errore che mi dà è infatti

    codice:
    Errore dal server remoto: (404). Non trovato
    Per capire attraverso un'immagine: https://i.imgur.com/ZOZyMad.png


    Qualcuno ha idea di come posso modificare il mio codice ?

    Per usare il codice io uso Powershell 5 (con il 4 mi dava alcuni problemi) e le cartelle che bisogna avere sono in

    C:\temp
    C:\tempresult

    Lo script elabora i documenti in temp e poi il codice li sistema in tempresult

    Inserisco il codice nella seconda parte perchè mi dà questo errore

    codice:
    Il testo che hai inserito è troppo lungo di (13957 caratteri). Accorcialo sino a 13000 caratteri.

  2. #2
    Il codice che uso è il seguente. Da powershell uso questo comando per avviare il .ps1

    codice:
    cd C:\temp2
    .\esperanto.ps1
    codice:
    • $list1 = @"
    • quant-ph9802001
    • quant-ph9802004
    • "@
    • $list2 = @"
    • quant-ph/9802001
    • quant-ph/9802004
    • "@
    • Write-Output "Adding forward slashes"
    • $list1 -split "`r`n" | % {
    • $item = $_.Trim()
    • $newItem = $item -replace '(.*)(\d{7})', '$1/$2'
    • Write-Output $("{0} ==> {1}" -f $item, $newItem)
    • }
    • Write-Output "Removing forward slashes"
    • $list2 -split "`r`n" | % {
    • $item = $_.Trim()
    • $newItem = $item -replace '(.*)/(\d{7})', '$1$2'
    • Write-Output $("{0} ==> {1}" -f $item, $newItem)
    • }
    • Function Clean-InvalidFileNameChars {
    • param(
    • [Parameter(Mandatory=$true,
    • Position=0,
    • ValueFromPipeline=$true,
    • ValueFromPipelineByPropertyName=$true)]
    • [String]$Name
    • )
    • $invalidChars = [IO.Path]::GetInvalidFileNameChars() -join ''
    • $re = "[{0}]" -f [RegEx]::Escape($invalidChars)
    • $res=($Name -replace $re)
    • return $res.Substring(0, [math]::Min(260, $res.Length))
    • }
    • Function Clean-InvalidPathChars {
    • param(
    • [Parameter(Mandatory=$true,
    • Position=0,
    • ValueFromPipeline=$true,
    • ValueFromPipelineByPropertyName=$true)]
    • [String]$Name
    • )
    • $invalidChars = [IO.Path]::GetInvalidPathChars() -join ''
    • $re = "[{0}]" -f [RegEx]::Escape($invalidChars)
    • $res=($Name -replace $re)
    • return $res.Substring(0, [math]::Min(248, $res.Length))
    • }
    • $rootpath="c:\temp2"
    • $rootpathresult="c:\tempresult"
    • $template=@'
    • [3] arXiv:1611.00057 [pdf, ps, other]
    • Title: {title*:Holomorphy of adjoint $L$ functions for quasisplit A2}
    • Authors: Joseph Hundley
    • Comments: 18 pages
    • Subjects: {subject:Number Theory (math.NT)}
    • [4] arXiv:1611.00066 [pdf, other]
    • Title: {title*:Many Haken Heegaard splittings}
    • Authors: Alessandro Sisto
    • Comments: 12 pages, 3 figures
    • Subjects: {subject:Geometric Topology (math.GT)}
    • [5] arXiv:1611.00067 [pdf, ps, other]
    • Title: {title*:Subsumed homoclinic connections and infinitely many coexisting attractors in piecewise-linear maps}
    • Authors: David J.W. Simpson, Christopher P. Tuffley
    • Subjects: {subject:Dynamical Systems (math.DS)}
    • [21] arXiv:1611.00114 [pdf, ps, other]
    • Title: {title*:Faces of highest weight modules and the universal Weyl polyhedron}
    • Authors: Gurbir Dhillon, Apoorva Khare
    • Comments: We recall preliminaries and results from the companion paper arXiv:1606.09640
    • Subjects: {subject:Representation Theory (math.RT)}; Combinatorics (math.CO); Metric Geometry (math.MG)
    • '@
    • #extract utils data and clean
    • $listbook=gci $rootpath -File -filter *.pdf | foreach { New-Object psobject -Property @{file=$_.fullname; books= ((iwr "https://arxiv.org/abs/$($_.BaseName)").ParsedHtml.body.outerText | ConvertFrom-String -TemplateContent $template)}} | select file -ExpandProperty books | select file, @{N="Subject";E={Clean-InvalidPathChars $_.subject}}, @{N="Title";E={Clean-InvalidFileNameChars $_.title}}
    • #build dirs and copy+rename file
    • $listbook | %{$newpath="$rootpathresult\$($_.subject)"; New-Item -ItemType Directory -Path "$newpath" -Force; Copy-Item $_.file "$newpath\$($_.title).pdf" -Force}

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.