0

I have doc, docx and PDF files wherein the filenames consist of a unique 9 digit number followed by text.

I want to move those files to their respective folders which also consist of at least the unique 9 digit number but may have different text.

Those folders are in another folder on the hard drive but I can easily move the documents to the same parent folder if needed. The files and folder names are a combination of 123456789_Firstname_Lastname.docx. Instead of underscores, there may be spaces, or commas or no spaces at all. What will be certain though, is that the file and folder name begins with 9 numbers.

I have Python installed, Hazel, and Directory Opus and can install anything else if needed to make this process work. There are thousands of files so I'd really appreciate a solution.

1 Answer 1

1

Not a script writing service, but this (untested) PowerShell should get you started:

$DestParent = 'C:\NumberedFolders'
Get-ChildItem *.txt, *.pdf | %{
   $ID = $_.BaseName.Substring(0,8)
   $Dest = (Get-Item "$destparent\$ID*").FullName
   Move-Item -Path $_.FullName -Destination $Dest
}

Get-ChildItem

ForEach-Object

String.Substring Method

Get-Item

Move-Item

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .