#1 2013-01-19 17:38

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

Pascal Scripts for removing files and empty folders

Hi everybody!

....first of all please excuse my bad english....

I was searching and testing for a while now, but without luck, I'm looking for 3 simple scripts.  ( I'm also not a programmer, so I don't know the syntax of Pascal language )

Let's say I'm under folder called 'Files', this folder is on desktop, in this folder are many different files and maybe one empty folder, and I need to remove some of the files with the empty folder + create a new folder called 'Audio'.

First script:
Removing of files

I found this:
'function WideDeleteFile(const FileName: WideString): Boolean;'
-how should I use this part of code if I want to delete all 'jpg,png,txt' files under active folder (so I don't need to change the root to those files every time)



Second script:
Removing of empty folders under active folder and subfolders

I found nothing to this topic



Third script:
Creating an folder under every sub folder with user defined name

I found this:
'function WideCreateDir(const Dir: WideString): Boolean;'
-if I try this: WideCreateDir(Audio); - It creates a folder named 'Audio' on the desktop and not in the active folder where I am hmm



Every help is much appreciated!
Jan

Offline

#2 2013-01-20 00:28

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

Re: Pascal Scripts for removing files and empty folders

Hi Jan, welcome to the community.

I think a file renamer is not the right tool for whole file management. Better us an dedicated file manager.

But i will give you a few hints how to work with PascalScript, maybe you will be able learn from them.

1.) read our wiki > http://www.den4b.com/wiki/ReNamer:Pascal_Script

2.) ReNamer PascalScript basics:
There are two build-in varibales; FileName and FilePath.
Use "ShowMessage(FileName);" in an script to see what they mean.

3.) function WideDeleteFile(const FileName: WideString): Boolean;'
You have to use the full path\filename.
You would use that like this:

var
 ext:string;
 
begin
  ext := WideExtractFileExt(FileName);

  if (ext = '.jpg') then
  begin
     ShowMessage(FilePath);  //show message box
     WideDeleteFile(FilePath); //delete the file
  end;
end.

4.) Removing of empty folders
I have no idea right now. This is even an hard task for file managers to handle.

5.) Creating an folder under : WideCreateDir(Audio)
Again you have to use full path to work on current folder.
You can use the function WideExtractFileDir() to get the current dir.
showmessage(WideExtractFileDir(FilePath));

You would use that somehow like
var
Parent:String;
begin
Parent := WideExtractFileDir(FilePath);
WideCreateDir(Parent + '\Audio');
end.


But then again i can't imagine why to use ReNamer to do this task.
But maybe you can find better use for ReNamer than just renaming files.


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-20 12:19

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

Re: Pascal Scripts for removing files and empty folders

Thank you Stefan for your reply!

First I thought that ReNamer is only for renaming files, but then I saw the possibility to use some pascal scripts, I thought WOW, maybe I found one piece of software which can handle all my hobby work big_smile
But I fully understand, if there is now way then there is no way. ReNamer handles now around 40% of the work, for the rest I have to use some manual labor big_smile and features like windows search, where I can search all files which I don't need and remove them in one step from all folders and subfolders. Then I have another tool which founds for me all the empty folders (something like windows search), again, in one step I get rid of them. And the rest is as I said manual labor. So I thought that maybe this software can do that for me as well. Anyway I'm really glad that the rules in ReNamer can be saved as a template for second use, so I don't need to setup the rules every single time.

If I may one question, It pop out from nowhere smile
Is there a way to rename files with variable naming like for example:

'kgjheo.jpg ; lpood36.jpg ; 78asd_dd.jpg' and so on to 'Poster1.jpg ; Poster2.jpg ; Poster3.jpg' and so on.... ( in the folder can be JUST one or more jpg files, it's various )

Do I have to use some pascal script or do I have to mix just some rules together??

Thank you!
Jan

Offline

#4 2013-01-20 12:37

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

Re: Pascal Scripts for removing files and empty folders

He Jan, please open dedicated threads for separate questions.
That is better for us all to reuse the solution and to prevent from messing-up an thread with un-sorted questions and answers.

But here we go anyway.


SELECTION:
There is no rule to skip files with dedicated, un-wanted extensions.
You have to select wanted extensions instead manually:
- Shift+U (un-mark)
- Ctrl+E (sel by ext), enter "jpg"
- Shift+M (mark selected)

(Is there an easier way? Without using PascalScript? Well, one way is to use "add files" and configure the filter beforehand)



RENAMING:

FROM:
kgjheo.jpg
lpood36.jpg
78asd_dd.jpg

TO:
Poster1.jpg
Poster2.jpg
Poster3.jpg

USE:
1) Delete: Delete from Position 1 until the End (skip extension) //remove original file name completely
2) Insert: Insert "Poster" as Prefix (skip extension) //use fixed term as new name
3) Serialize: Serialize Incremental from 1 step 1 repeat 1 as suffix (before extension) // add an serial number

OR shorter:
1) Replace: Replace using wildcards "*" with "Poster" (skip extension) //replace all of orig file name with 'Poster'
2) Serialize: Serialize Incremental from 1 step 1 repeat 1 as suffix (before extension)


HTH?


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

#5 2013-01-20 14:37

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

Re: Pascal Scripts for removing files and empty folders

Thank you very much! It works wonderful!

And next time I'll open a new topic, sorry for that.

Jan

Offline

Board footer

Powered by FluxBB