简体   繁体   中英

Scheduled Powershell Moves to Specific Folders

Thanks for viewing my question. I was unable to find any information online in regards to my question. I also have very basic experience in this area.

PowerShell Script:

-Query folder for files (list?)

-Move file based on filename to folder with same name. (Move with pipe to query?)

-Move will also parse second part of file name to include subsequent matching folder name for destination folder.

Files will contain many separate names so the move has to be on a loop.

Ex. File - "Name 1" Scripts excutes moves file to folder with "name" then to subfolder "1".

Just to be clear there will be multiple names and numbers so multiple destination paths. Basically every file will have a different destination but the destination will correlate to the file name. If there is a language more accessible for this function please let me know.

Something like the following will get you started

$files = Get-ChildItem -File

foreach($f in $files) {
  $dirname = $f -split " " -join "\"
  New-Item -ItemType Directory -Path ".\$dirname"
  Move-Item $f $dirname
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM