Forum Discussion

Jason777_1's avatar
Jason777_1
Copper Contributor
Nov 09, 2023

Help to create a script

Hello,

 

I'm a newbie here and I just want to ask if anybody here could perhaps help me...

Sorry for my english....

 

Here is what I would like :

 

- Check if new contents in /Vidéothèque/A yadiser

- Check if it is file or folder

- If it is folder check if the file who are in have the same name

- If it is doing the same action than for the files who aren't in folder

- If it is file who has a name like

  Cult of Chucky (2017) Unrated MULTi VFI 2160p 10bit 4KLight DV HDR BluRay DDP 5.1 x265-QTZ.mkv

  Without.Love.1945.MULTi.1080p.WEB.H264-FW.mkv

- so create a folder with only the title like

      Cult of Chucky

      Whitout Love (whitout point)

- and put the files in the good folder

- Create in each folder a .txt with the end of the title

    -QTZ.txt

    -FW.txt

- And erase in the file the same than the .txt to have files like this

     Cult of Chucky (2017) Unrated MULTi VFI 2160p 10bit 4KLight DV HDR BluRay DDP 5.1 x265.mkv

     Without.Love.1945.MULTi.1080p.WEB.H264.mkv

- When the script see in the title of the filesome tags he put after the title of the folder specials balise like:

for 1080p > [HHD]

  ex. folder :     Without Love [HHD]

  with ex. files inside :  

                  Without.Love.1945.MULTi.1080p.WEB.H264.mkv

                  -FW.txt

for 2160p [4K]

for 4KLight [m4K]

for if they see 4K or 2160p and Light [m4K]

   Cult of Chucky [m4K]

   Cult of Chucky (2017) Unrated MULTi VFI 2160p 10bit 4KLight DV HDR BluRay DDP 5.1 x265.mkv

  -QTZ.txt

for if they see 1080p and x265 [x265]

for 720p [HD]

 

 

I hope to be clear and than anybody would be kind to help me.

 

Have a good day.

 

PS, I'm on windows10 if it could serve.

 

 

 

  • LeonPavesic's avatar
    LeonPavesic
    Silver Contributor

    Hi Jason777_1,

    here is a basic (test) PowerShell script that should do (some of the things) what you're asking for. This script is somthing you can start from.

    # Get all files in the directory
    $files = Get-ChildItem -Path "C:\Vidéothèque\A yadiser" -File -Recurse
    
    foreach ($file in $files) {
    # Extract movie name and other details from the file name
    if ($file.Name -match "(.*?)(\d{4}).*(1080p|2160p|720p|4KLight|x265).*-(\w+)\.") {
    $movieName = $Matches[1].Trim()
    $year = $Matches[2]
    $quality = $Matches[3]
    $tag = $Matches[4]
    
    # Create a new directory for the movie
    $dir = New-Item -ItemType Directory -Force -Path "C:\Vidéothèque\A yadiser\$movieName"
    
    # Move the file to the new directory
    Move-Item -Path $file.FullName -Destination $dir.FullName
    
    # Create a text file in the new directory
    $tag | Out-File "$($dir.FullName)\$tag.txt"
    
    # Rename the file
    Rename-Item -Path "$($dir.FullName)\$($file.Name)" -NewName "$movieName $year $quality.mkv"
    }
    }

    This script does the following:
    - It gets all the files in the specified directory.
    - For each file, it extracts the movie name, year, quality, and tag from the file name.
    - It creates a new directory for each movie and moves the corresponding file into it.
    - It creates a text file in the new directory with the tag as its content.
    - It renames the file to remove the tag.

     

    This script doesn't handle all your requirements (like handling folders and special cases for 4KLight, etc.).

    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.


    If the post was useful in other ways, please consider giving it Like.


    Kindest regards,


    Leon Pavesic
    (LinkedIn)

    • Jason777_1's avatar
      Jason777_1
      Copper Contributor
      Hello and thanks for your help,

      Like I say I'm a newbie and can you say me how can I try this script ?

      I take it and put in a .txt and after I change de extension in .what ?

      And does I have to give some permission somewhere ?

      Thanks

      PS, jsut if I good read, you change the name of the files like that ?
      Because if yes, it isn't what I want...

      Kindest regards, thanks
      • LeonPavesic's avatar
        LeonPavesic
        Silver Contributor

        Hi ,

        thanks for your update.

        To use the script, you will need to save it as a .ps1 file. You can open your notepad, paste the code there and save it as MyScript.ps1.

        Then, you can open a PowerShell console (as an Admin) and navigate to the directory where you saved the script.

        To do this, you can use the "cd" command. For example, if you saved the script in the "C:\Downloads" directory, you would type the following command: cd C:\Downloads 

        Once you are in the directory where you saved the script, you can run it by typing the following command:

        .\scriptname.ps1 

        For example, if you saved the script as "my_script.ps1", you would type the following command:

        .\MyScript.ps1 

         

         

        Please click Mark as Best Response & Like if my post helped you to solve your issue.
        This will help others to find the correct solution easily. It also closes the item.

        If the post was useful in other ways, please consider giving it Like.

        Kindest regards,

        Leon Pavesic
        (LinkedIn)

         

         

         

         

         

Resources