<p>i dont know if its your search but my new code</p>

<pre><code>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}
</code></pre>
Parsing information from http link to move and reorder files into categories folders
<p>To crawl and rename filenames I using this PowerShell code</p>

<pre><code>gci *.pdf | foreach { (iwr "https://arxiv.org/abs/$($_.BaseName)") -match 'primary-subject"&gt;(.*?)&lt;/span&gt;'; $matches[1] }
</code></pre>

<p>But I need to order and move them into relative <em>Subject</em> folders</p>

<p><strong>This is HTTP</strong> <a href="https://arxiv.org/list/math/1611" rel="nofollow noreferrer">LINK</a>.</p>

<p>Text file is so formatted</p>

<pre><code>[1] arXiv:1611.00024 [pdf, other]
    Symmetry, Outer Bounds, and Code Constructions: A Computer-Aided Investigation on the Fundamental Limits of Caching
    Chao Tian
    Comments: 34 pages, 7 figures; submitted to IEEE Trans. Information Theory
    Subjects: Information Theory (cs.IT)
[2]  arXiv:1611.00044 [pdf, ps, other]
    Optimal Signaling for Secure Communications over Gaussian MIMO Wiretap Channels
    Sergey Loyka, Charalambos D. Charalambous
    Comments: accepted by IEEE Trans. Info. Theory
    Subjects: Information Theory (cs.IT)
[3]  arXiv:1611.00057 [pdf, ps, other]
    Holomorphy of adjoint L functions for quasisplit A2
    Joseph Hundley
    Comments: 18 pages
    Subjects: Number Theory (math.NT)
[4]  arXiv:1611.00066 [pdf, other]
    Many Haken Heegaard splittings
    Alessandro Sisto
    Comments: 12 pages, 3 figures
    Subjects: Geometric Topology (math.GT)
[6]  arXiv:1611.00069 [pdf, other]
    On singular square metrics with vanishing Douglas curvature
    Changtao Yu, Hongmei Zhu
    Comments: 12 pages, 2 figures
    Subjects: Differential Geometry (math.DG); Metric Geometry (math.MG)
[7]  arXiv:1611.00071 [pdf, ps, other]
    Eigenvalues of rotations and braids in spherical fusion categories
    Daniel Barter, Corey Jones, Henry Tucker
    Subjects: Quantum Algebra (math.QA); Representation Theory (math.RT)
</code></pre>

<p>I need to extract <em>Subjects</em> category name from each file text block</p>

<pre><code>Subjects: Information Theory (cs.IT)
Subjects: Information Theory (cs.IT)
Subjects: Number Theory (math.NT)
Subjects: Geometric Topology (math.GT)
Subjects: Differential Geometry (math.DG)
Subjects: Quantum Algebra (math.QA)
</code></pre>

<p>I don't want include <em>second tag</em> like</p>

<pre><code>Metric Geometry (math.MG)
Representation Theory (math.RT)
</code></pre>

<p>So finally I should make this folders like this</p>

<pre><code>[folder] Information Theory (cs.IT)
[folder] Number Theory (math.NT)
[folder] Geometric Topology (math.GT)
[folder] Differential Geometry (math.DG)
[folder] Quantum Algebra (math.QA)
</code></pre>

<p>and move finally files <em>into</em> relative subject folders like this</p>

<pre><code>[folder] Information Theory (cs.IT)
    |
    |__ [file] Symmetry, Outer Bounds, and Code Constructions...
    |__ [file] Optimal Signaling for Secure Communications...

[folder] Number Theory (math.NT)
    |
    |__ [file] Holomorphy of adjoint L functions...
</code></pre>