#1 2013-01-20 16:22

alcestneige
Member
Registered: 2013-01-19
Posts: 28

Move a file with specific extension into a Subfolder - Pascal

Hi all!

I would like to move a file in one folder with specific extension to a subfolder in the same folder.

Basically I have a folder called 'Hero', in this folder I have a file called 'Hero.srt' and 'Hero.avi', and I would like to create under folder 'Hero' an subfolder called 'Subtitles' and move the 'Hero.srt' into it.


So I have:

Hero
     Hero.avi
     Hero.srt

And I would like to get:

Hero
    Hero.avi
   Subtitles
      Hero.srt


I'm not a programmer, but I'l try to put things together and I was able to put this code together, but there is some kind of problem with it on the second line (reported by ReNamer).

var
 FileName:WideString;
 
begin
  FileName := WideExtractFileExt(FileName);
  
if (FileName = '.srt') then
  begin
  FileName := 'Subtitles\' + FileName;
  end;
  
end.

If anybody is willing to fix the code for me I would be really happy.

Any reaction is much appreciated!
Thank you!
Jan

Last edited by alcestneige (2013-01-20 16:24)

Offline

#2 2013-01-20 21:24

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Move a file with specific extension into a Subfolder - Pascal

As i wrote in the other thread; ReNamer's PascalScript has two build-in vars: FileName and FilePath.
So you can't reuse this strings for your own vars.

Use this script on two or three files to see what they hold:

begin
  // Add your code here
  ShowMessage(FileName);
  ShowMessage(FilePath);
end.

- - -

Jan wrote> "FileName := 'Subtitles\' + FileName;"

I don't know (not tested) if this relative path will work.
If not, remember my hint about how to extract 'Parent' folder.


- - -

Jan wrote> "but there is some kind of problem with it on the second line (reported by ReNamer)."

You can press Ctrl+C on that error dialog to paste the error message here, so we get an glue what you have seen.


.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2013-01-21 11:57

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Move a file with specific extension into a Subfolder - Pascal

As Stefan has suggested, FileName is a reserved variable name which is used internally by ReNamer. The error has occurred because you tried to redeclare that reserved variable.

Your attempt was very close, good work for a non-programmer. So here is a slightly adjusted code which should do what you wanted:

var
  Extension: WideString;
begin
  Extension := WideExtractFileExt(FileName);
  if (Extension = '.srt') then
  begin
    FileName := 'Subtitles\' + FileName;
  end;
end.

Offline

#4 2013-01-21 18:53

alcestneige
Member
Registered: 2013-01-19
Posts: 28

Re: Move a file with specific extension into a Subfolder - Pascal

Thank you Stefan and den4b, it works wonderful!

Offline

Board footer

Powered by FluxBB