Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Abra todos los archivos en la carpeta y vuelva a guardarlos en un directorio de carpeta creado según el nombre del archivo

Hola, tengo más de 15K archivos PDF guardados en una carpeta Z:\Archivo PDF\2010

y necesitan una mejor organización. No tengo idea de cómo hacer esto, pero lo que me gustaría que sucediera es: Si el nombre del archivo es 8757854.pdf

Me gustaría crear (si aún no existe) el directorio Z:\PDF Archive\8700000-8799999\8750000-8759999\

y copie el archivo en él.

La mayoría de los nombres de archivo tienen 7 dígitos, pero hay algunos que solo tienen 6, en esa situación, me gustaría agregar un 0 al comienzo del nombre del archivo.

Entonces, si el nombre del archivo es 757854.pdf, esta sería la ruta del archivo: Z:\PDF Archive\0700000-0799999\0750000-0759999\

¡Los pensamientos y las ideas serían muy apreciados! ¡Gracias de antemano!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba lo siguiente:

 # Input and output (root) directory paths. $inPath = 'Z:\PDF Archive\2010' $outPathRoot = 'Z:\PDF Archive' # The max. number of digits in the input file names. $maxDigits = 7 Get-ChildItem -LiteralPath $inPath -Filter *.pdf | ForEach-Object { # Left-pad the number string that constitutes the base file name # with zeros to ensure a length of 7. $paddedNum = $_.BaseName.PadLeft($maxDigits, '0') # Construct the name of the subdirectories to copy the files to, # replacing the digits after the leading 2 and 3 digits first with "0" and "9", # respectively, joining the resulting strings with "-" $subDirs = foreach ($leadingDigits in $paddedNum.Substring(0, 2), $paddedNum.Substring(0, 3)) { ($leadingDigits + '0' * ($maxDigits - $leadingDigits.Length)), ($leadingDigits + '9' * ($maxDigits - $leadingDigits.Length)) -join '-' } # Create the output subdirectories, if necessary. # -Force both creates parent directories on demand and # quietly returns an existing directory, if present. $targetDir = New-Item -Type Directory -Force ($outPathRoot + '\' + ($subDirs -join '\')) # Copy the PDF file at hand to the target subdirectory. $_ | Copy-Item -Destination $targetDir.FullName }

Nota: Si agrega el parámetro común -WhatIf al comando Copy-Item , obtendrá una vista previa de las operaciones de copia, que incluirá la ruta de destino completa.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!