Forum Discussion
Help to create a script
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_1Nov 09, 2023Copper ContributorHello 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- LeonPavesicNov 10, 2023Silver 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:\DownloadsOnce you are in the directory where you saved the script, you can run it by typing the following command:
.\scriptname.ps1For example, if you saved the script as "my_script.ps1", you would type the following command:
.\MyScript.ps1Please 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)