Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Support for Windows users
Post Reply
SoonerLater
Posts: 10
Joined: 27 Feb 2018, 22:43

Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by SoonerLater »

An example is given on this site that to (1) rename a movie file, (2) create a folder of the same name in the same location and (3) move the newly renamed file to the new folder, use this code:

../{movie}/{movie}

Image

If I have a file

\\server\share\folder\Final.Portrait.2017.1080p.NF.WEBRip.DDP.5.1.H264-CMRG.mkv

and then I drag it into Filebot (GUI, of course), then I run the above preset, Filebot (1) properly renames the file and (2) creates a folder of the same name and (3) puts the new file in the new folder. However, the new folder is one level up in the file tree from where I ran the command. So instead of ending up with:

\\server\share\folder\Final Portrait (2017)\Final Portrait (2017).mkv

which is what I want, I end up with

\\server\share\Final Portrait (2017)\Final Portrait (2017).mkv

which is not what I want.

How should I change my code to achieve the desired result?

OS: Windows 10 Pro 64 bit
Filebot: Microsoft Store purchased, but version unknown - there's no "help, about" for me to check the program version and it doesn't show up in Control Panel \ Programs.
User avatar
rednoah
The Source
Posts: 22995
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by rednoah »

You have:

Code: Select all

../{movie}/{movie}
You want:

Code: Select all

./{movie}/{movie}
Because you want to create the folder in the current folder, and not the parent folder. .. refers to the parent folder of the file being processed, while . refers to the current folder of the file being processed.


TIP: If you specify exactly what you want in your format, then you will get exactly what you want. ;)

Code: Select all

\\server\share\folder\{movie}\{movie}
TIP 2: I recommend using {plex} or {plex.tail} instead of {movie}/{movie} because that'll take care of various corner cases and special cases you may not think of until you run into certain problems.
:idea: Please read the FAQ and How to Request Help.
lemon389
Posts: 15
Joined: 24 Sep 2023, 22:25

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by lemon389 »

Hello rednoah,

I would like to request your support for a scenario similar like this.

I'm renaming a Series that is in this path:

Code: Select all

C:\Tool\A\Output\Series Name\Season\Video_name.mkv
I want this output:

Code: Select all

C:\Tool\A\Output\New Series Name\New Season\New Video_name.mkv
All the path before the Series Name changes depending on the input video.

if i use:

Groovy: Select all

../{n.upperInitial().lowerTrail()....}
Then, the output is:

Code: Select all

C:\Tool\A\Output\Series Name\New Series Name\New Season\New Video_name.mkv
I tried with one more dot to go one level above like this:

Groovy: Select all

.../{n.upperInitial().lowerTrail()....}
But, I received this error:

Format: Select all

MOVE: Cannot create parent folder: C:\Tools\A\Output\...\Series Name (2023) {tmdb-xxxxx}\Season 01: Access Denied: C:\Tools\A\Output\...
Question:
What should be the correct sintax?

Thanks!
lemon389
Posts: 15
Joined: 24 Sep 2023, 22:25

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by lemon389 »

Update:
I tried leaving it without "../" and now it works:

Format: Select all

{n.upperInitial().lowerTrail()....}
But earlier today, when I had the statements like that, it was moving the files as follows, directly into the drive root folder.

Format: Select all

C:\New Series Name\New Season\New Video_name.mkv
User avatar
rednoah
The Source
Posts: 22995
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by rednoah »

:idea: . refers to the current directory. .. refers to the parent directory. You can do ../../.. to refer to the parent of the parent of the parent and so on. See What are "." and ".." in a directory? for details.


:?: What is the real path of C:\Tool\A\Output? This is likely a made up path for illustration purposes. However, if you were to use {plex} on this example path it would likely work because Output / Complete / Downloads / etc have special "structure root folder" meaning to FileBot, and so FileBot would be inclined to reorganize files within the common structure root if the format is relative.


:idea: That said, in this case I would probably go with "take the first 4 folder levels from the original file path" logic:

Format: Select all

{ f[0..3] }
:idea: Please read the FAQ and How to Request Help.
lemon389
Posts: 15
Joined: 24 Sep 2023, 22:25

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by lemon389 »

Hello rednoah,

C:\Tool\A\Output is for illustration, but, I have different folder names, A might be changed with another name, also, Output might be changed depending on the source.

What I understood so far, is that, Filebot takes the path of the video files, and, from that point, the parent directories starts to count.
Example:

Format: Select all

C:\Tools\Series Name\Season XX\Episode_00.mkv
If I use ..//, then, the files are moved to parent directory of the video files, in this case in the Season XX folder.

I will try your suggestions, thanks a lot for your support!
User avatar
rednoah
The Source
Posts: 22995
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename File, Create Folder In Current Location, Put Newly Renamed File In New Folder

Post by rednoah »

:?: What is the real path of C:\Tool\A\Output though? (NOTE: behaviour may depend on the real file path)

lemon389 wrote: 23 Nov 2023, 15:54 What I understood so far, is that, Filebot takes the path of the video files, and, from that point, the parent directories starts to count.
If you use ../{plex} or {folder}/{plex} or ../../{plex} or {folder.dir}/{plex} and so on as format, then yes.

If you use {plex}, then maybe, depending on the current file structure and folder names. In the example above, C:\ is likely considered structure root, since Tools is not a known structure root folder.
:idea: Please read the FAQ and How to Request Help.
Post Reply