Peters Flexible RenAmiNg Kit (PFrank) Forum Index Peters Flexible RenAmiNg Kit (PFrank)
Support and Discussion Site for the PFrank File/Folder Renaming Tool (***NEW HOME PAGE*** "http://pfrank.atwebpages.com")
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to search for duplicates and rename based on a condition

 
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Regular Expressions
View previous topic :: View next topic  
Author Message
twistyoz



Joined: 07 Jul 2011
Posts: 5

PostPosted: Thu Jul 07, 2011 11:04 am    Post subject: How to search for duplicates and rename based on a condition Reply with quote

I have a large number of files that are arranged in folders that I need to move into a single folder in preparation for migration into SharePoint. While this is easy enough to achieve by typing one line into a command prompt (FOR for /r %F etc.) one of the issues that I face is that within the various subfolders are many identically named files that will get overwritten once they have been moved into a single folder. What I am hoping to achieve is to append to the beginning of a file name the first two letters of the root folder.

Here's an example of my current folder structure:
Code:

C:\TEAM
+---Diane Lane
|   +---Goals
|   |       Presentation.pptx
|   |       
|   +---Money
|   |       Budget.xlsx
|   |       Shopping List.docx
|   |       
|   \---Review
|           FY10.docx
|           
\---George Castana
    +---Goals
    |       Presentation.pptx
    |       
    +---Money
    |       Budget.xlsx
    |       Shopping List.docx
    |       
    \---Review
            FY10.docx


Here is what I would like it to look like:
Code:

C:\STAFF
+---Diane Lane
|   +---Goals
|   |       DL Presentation.pptx
|   |       
|   +---Money
|   |       DL Budget.xlsx
|   |       DL Shopping List.docx
|   |       
|   \---Review
|           DL FY10.docx
|           
\---George Castana
    +---Goals
    |       GC Presentation.pptx
    |       
    +---Money
    |       GC Budget.xlsx
    |       GC Shopping List.docx
    |       
    \---Review
            GC FY10.docx


Is it possible to set up a regex string that will do the above? The challenge with this one I guess is that some of the subfolders under a person are four or five deep and I only want them to have the initials of the person as named in the root folders.
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Thu Jul 07, 2011 7:56 pm    Post subject: Reply with quote

Hi,

Pfrank could do what you want if the files to be renamed are all the same number of subfolders away from the folders that are named after people.

If that is true, then copy the following to the renaming creator (do not copy the single quotes):

Row: 1
Search:
Replace: '*Insert Folder before*Prefix*'

Row: 2
Search: '([A-Z])(.*?) ([A-Z])(.*?)_(.*)'
Replace: '\1\3 \5'


Beforehand you would have to to do the following:
1)
uncheck the folders box in the name filter area of the main window
2)
in the options window (common filters), check "scan content of subfolders"
3)
in the options window (parent folder name insertion), set the custom format creator to: %P2Folder%
Once this is configured, Line 1 of the main window renaming creator will insert the parent folder into the filename using the folder name 2 levels above the file (which should be the folder named after a person).
4)
In the main window, set the current folder to the STAFF folder.

Press scan and see if the preview window shows the desired renaming.

Hope that helps.

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
twistyoz



Joined: 07 Jul 2011
Posts: 5

PostPosted: Fri Jul 08, 2011 12:47 am    Post subject: Reply with quote

Thanks Peter, that works well for some of the folders but only 2 deep. Is there any way that this could be modified to work regardless of the depth?

This is what the above produced:
Code:

Base Pathname                          Old Name                                   New Name
C:\Team\Staff Folders\Sally Singh   Introduction 28-03.pdf   SF Introduction 28-03.pdf
C:\Team\Staff Folders\Sally Singh\SINATH PERSONAL   FW Notification of Commencement.rtf   SS FW Notification of Commencement.rtf
C:\Team\Staff Folders\Sally Singh\REVIEWS   Sally Singh Annual Review  2010-2011.doc   SS Sally Singh Annual Review  2010-2011.doc
C:\Team\Staff Folders\Sally Singh\REVIEWS\PLANS   PRDP 2008 2009.doc   REVIEWS_PRDP 2008 2009.doc
C:\Team\Staff Folders\Sally Singh\REVIEWS\PLANS\2010-2011   AKO signoff.pdf   PP AKO signoff.pdf
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Fri Jul 08, 2011 3:00 am    Post subject: Reply with quote

OK - I think the following should work although I haven't verified.

1)
instead of row 1 inserting just the parent folder name from 2 levels up, have it insert the name from 1 level up.
2)
row 2 inserts the parent folder name from 2 levels up
3)
row 3 inserts the parent folder name from 3 levels up
4)
... and so on until you are guaranteed to have added basically the entire path to the name where each folder level is separated by an '_'.
5)
In the next row make a regex that deletes everything from the start to "Staff folder_"
6)
next row deletes everything from the first '_' to the last '_'.
This should give you the original filename prefixed by the 'person name'.
7)
next row does what I suggested for Row 2 in my first reply (i.e. makes initials out of the 'person name' that at this point would be prefixing the original filename

I might be able to try this out int he next few days or maybe you can give it a go.

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
twistyoz



Joined: 07 Jul 2011
Posts: 5

PostPosted: Fri Jul 08, 2011 7:39 am    Post subject: Reply with quote

Thanks Peter. I think that I understand your approach but am not quite sure how to implement it. On your first set of instructions I went into More -> Parent Folder Name Insertion and changed the value to %P2Folder%. How would I change this so that it increments for each line as changing the options for one appears to change it for all?
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Fri Jul 08, 2011 12:07 pm    Post subject: Reply with quote

Sorry - I didn't have it quite right.
You have to do all the parent folder insertion at once by configuring the parent folder name insertion to something like this:

%P5Folder%_%P4Folder%_%P3Folder%_%P2Folder%_%P1Folder%


Then in the main window renaming creator you only need one row to do the parent folder name insertion:

Row: 1
Search:
Replace: '*Insert Folder before*Prefix*'



Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
admin
Site Admin


Joined: 09 Mar 2007
Posts: 448
Location: Canada

PostPosted: Fri Jul 08, 2011 3:33 pm    Post subject: Reply with quote

Try this:

Row: 1
Search:
Replace: '*Insert Folder before*Prefix*'
Row: 2
Search: '(.*)Staff Folders_'
Replace:
Row: 3
Search: '_(.*)_'
Replace: '_'
Row: 4
Search: '([A-Z])(.*?) ([A-Z])(.*?)_(.*)'
Replace: '\1\3 \5'

Something like the following needs to be configured for the folder insertion option:

'%P5Folder%_%P4Folder%_%P3Folder%_%P2Folder%_%P1Folder%'

You can also play with the folder insertion options to disable warnings (for nonexistent parent folder) or to insert a null string if the parent folder does not exist.

Hope that helps.

Peter.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
twistyoz



Joined: 07 Jul 2011
Posts: 5

PostPosted: Sat Jul 09, 2011 11:50 am    Post subject: Reply with quote

Thank you for helping me with this. I won't be able to try it properly until Monday as I left the files on my laptop but I'll let you know how it goes.
Back to top
View user's profile Send private message
twistyoz



Joined: 07 Jul 2011
Posts: 5

PostPosted: Mon Jul 11, 2011 3:08 am    Post subject: Reply with quote

I tested this today and it worked perfectly. Thank you so much for this as it has saved me a lot of time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Peters Flexible RenAmiNg Kit (PFrank) Forum Index -> Regular Expressions All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own Video Sharing Site

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com