-2

looking for some help please - I have no experience in code writing so have been looking for a question/answer that is close but..... My huge movie database lives on NAS drive "Video Y", each movie in its own subdirectory; it has multiple video file types, most being .avi, and I wanted to convert all the .avi to .mp4 (some devices will not play .avi"). So I filtered out all the .avi files and put them in one new directory "0 temp holder for avi", so I could use VideoProc to convert; this converted and placed the .mp4 files in one new directory "00 temp holder MP4".

Now I want to move the .mp4 files back in their own original sub directory which still contains various files related to the movie like .srt etc. I think the simplest way for me is lining up the files in alphabetical order and the directories in the same order, (as directory names and file names are not necessarily exactly the same), checking for mismatches and correcting as needed, and using some code to move the first file to first directory, and iterate from there. But I'm still stumped and not sure to go about it. I put under the Windows10 and Powershell tag, but someone may assist with more accurate tags please. Directory layout

prolecs
  • 1
  • 1
  • Can you post the actual directories they're in? Such as where they're are, and where you want to move them to? – Abraham Zinala Feb 02 '21 at 01:43
  • If you can visually describe it, we may be able to help. Such as. Videos in C:\ need to go to D;\ – Abraham Zinala Feb 02 '21 at 02:03
  • hope the link works - I can't directly attach images – prolecs Feb 02 '21 at 02:12
  • so you want all the .mp4's back into "8mm 2005 directory?" – Abraham Zinala Feb 02 '21 at 02:15
  • No. Each .mp4 file on the right, has a corresponding directory on the left. I have not lined up all directories and files as yet, their may be some differences that I will have to adjust before running any script to shuffle the files into the directory. The avi to mp4 conversions are still happening – prolecs Feb 02 '21 at 03:44
  • And I forgot, there are additional directories on the left that did not have avi files so did not require conversion (ie there is no mp4 file to go in those directories. More complicated than I thought !! – prolecs Feb 02 '21 at 03:56
  • Just know, I get being ne, but SO has rules we are to follow: [Provide MRE](https://stackoverflow.com/help/minimal-reproducible-example) --- [How to ask](https://stackoverflow.com/help/how-to-ask) --- [Don't ask](https://stackoverflow.com/help/dont-ask) --- [Proper Topic](https://stackoverflow.com/help/on-topic) --- [Why not upload images of code/errors?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question). Use `Get-ChildItem` to find what you want, then `Move-Item` to make your move or just use Robocopy.exe, it's built into Windows.. – postanote Feb 02 '21 at 04:47
  • 2
    See Youtube for beginner training. [Beginning PowerShell](https://www.youtube.com/results?search_query=beginning+powershell). [PowerShell file and folder management](https://www.youtube.com/results?search_query=powershell+file+and+folder+management) – postanote Feb 02 '21 at 04:48

1 Answers1

0

Shown below at the beginning of the PowerShell script, the $arrVideoFolders variable is to load all the folders names into an array.

The $arrFolder variable is for the filenames of all your video files in a separate array.

Shown below,

$arrVideoFolders = Get-ChildItem (Folders for the videos) | 
       Where-Object {$_.PSIsContainer} | 
       Foreach-Object {$_.Name}

$arrFolder = Get-ChildItem (Video file names) | 
       Where-Object {$_.PSIsContainer} | 
       Foreach-Object {$_.Name}

To give the logic of how i would write the rest of the PowerShell script.

Afterwards a foreach loop would be used to go through all folders, and foreach folder a second nested foreach loop would loop through your video files. An if statement would test, the video name is like, your folder name. This is because your video files names are similar, once found you can do a copy and paste, or cut and paste.

For testing maybe use folders, and simple empty text files instead of copying large files, and test in different folders.

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5