[REQ] Moving files to a new subfolder

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
z3us
Posts: 86
Joined: 2008-02-19 17:36:53

[REQ] Moving files to a new subfolder

Post by z3us »

Actually I have all my videofiles in a folder. I want to move each file to a individual subfolder named with the translated title
How can I do that?
Thanks
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You can try to make something based on what I made for that user:
viewtopic.php?t=4460
z3us
Posts: 86
Joined: 2008-02-19 17:36:53

Post by z3us »

Taking into account that I use field source for path, I have this:

Code: Select all

program NewScript;
var
  source, newsource, root, folder, newfolder: string;
begin
  source := GetField(fieldSource);
  folder := ExtractFilePath(source);
  root := ExtractFilePath(Copy(folder, 1, Length(folder) - 1));
  newsource := folder + GetField(fieldTranslatedTitle) + ExtractFileExt(source);
  if MoveFile(source, newsource) then
  begin
    SetField(fieldSource, newsource);
    source := newsource;
    newfolder := root + GetField(fieldTranslatedTitle) + '_' + GetField(fieldYear);
    if MoveFile(Copy(folder, 1, Length(folder) - 1), newfolder) then
    begin
      newsource := newfolder + '\' + ExtractFileName(source);
      SetField(fieldSource, newsource);
    end;
  end;
end.
But I have a issue: I have the films in a folder named films:
c:\videos\films\1.avi
c:\videos\films\2.mkv
...
this script is renaming this folder, so:
c:\videos\1\1.avi

and what I want is to create a subfolder where the video file is:
c:\videos\films\1\1.avi

What should I change in the script?

Thanks
antp
Site Admin
Posts: 9629
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

I stupidly only put functions for files and not for folders... so the script cannot create folders with a dedicated function for that :/
What could be done is a first pass to create all the folders using
Launch('cmd.exe', '/c md ' + folderName);
where foldername contains the full path (e.g. 'c:\videos\films\1')
Then a second pass to move the files into the folders.
Problem is that both cannot be done in 1 pass, as the script will not wait that the contains of "Launch" command has finished before processing the next line.
As alternative you could put a wait time (sleep) between the launch and the move.
z3us
Posts: 86
Joined: 2008-02-19 17:36:53

Post by z3us »

I want
translated title (year)

instead of
translated title_year

How do I modify the script?
Thanks
z3us
Posts: 86
Joined: 2008-02-19 17:36:53

Post by z3us »

Sorry, it was easy
program NewScript;
var
source, newsource, root, folder, newfolder: string;
begin
source := GetField(fieldSource);
folder := ExtractFilePath(source);
root := ExtractFilePath(Copy(folder, 1, Length(folder) - 1));
newsource := folder + GetField(fieldTranslatedTitle) + ExtractFileExt(source);
if MoveFile(source, newsource) then
begin
SetField(fieldSource, newsource);
source := newsource;
newfolder := root + GetField(fieldTranslatedTitle) + ' (' + GetField(fieldYear) + ')';
if MoveFile(Copy(folder, 1, Length(folder) - 1), newfolder) then
begin
newsource := newfolder + '\' + ExtractFileName(source);
SetField(fieldSource, newsource);
end;
end;
end.
Post Reply