NO

Author Topic: File Renaming... solving a decades old problem  (Read 785 times)

Scripter

  • Guest
File Renaming... solving a decades old problem
« on: June 10, 2016, 01:00:30 PM »
This is part of a larger project Erol (Vortex) and I have been working on, tackling a number of long standing problems with Windows.

In this case it's the ongoing bugaboo about programmatic renaming of files that has been around since the good old days of MS-DOS. 

After a lot of head scratching and experimenting, what we came up with was a simple system of 2 and 3 character macros that can be loaded into a wildcard string to rename files and groups of files. The macros are capable of very impressive transformations and many of the "evils" of bad filenames can be fixed quite easily.

The attached screen shot shows only a tiny fraction of their capabilities.

Be sure to unpack the Renamer2.zip file into an empty directory.

The Renamer algorithm  is a single function. The source is in the lib\renlib.c file. You can copy and paste or you can include the precompiled renlib32.lib or renlib64.lib files into your project. The renamer.h file gives you the prototype which is...
Code: [Select]
BOOL RenameFile(PCHAR Old, PCHAR WCard, PCHAR New)Pass the old filename (no paths) into the Old parameter, pass a macro string into the WCard parameter and point the New parameter at an empty buffer large enough to hold the new name.  The function returns 1 on success or 0 on any error.

For instant gratification click the QuickTest.bat file. It will write a number of files into a folder named test1 and then copy/rename them into test2.  Compare the results to see how handy it is.

A list of the Renamer macros is in the RenamerMacros.txt file.  (Note: If you are using the earlier version, some of the macros have changed so be sure to check the list first.)

The demo32.exe and demo64.exe programs will let you test the macros and get a feel for how they work.

The Renamer32.exe and Renamer64.exe programs are "live" utilities that will let you experiment further.  Rename, copy and move are supported, all using the Renamer algorithm. (Please note: this is supplied for demonstration purposes only and is not intended to be a daily use utility.)

If you study the source code for the utilities (namer.c, in the Utility folder) you will see how easily the Renamer algorithm integrates with FindFirstFile() and FindNextFile() loops, giving you the ability to easily update existing programs with Renamer's advanced capabilities.

So, there it is... a simple solution to a decades old problem.

« Last Edit: June 18, 2016, 09:58:02 PM by Scripter »

Offline Vortex

  • Member
  • *
  • Posts: 482
    • http://www.vortex.masmcode.com
Re: File Renaming... solving a decades old problem
« Reply #1 on: June 13, 2016, 01:23:48 PM »
Here are some examples :

Code: [Select]
Old Name : _long_file_name   .txt
Wildcard : *a*m?n
New Name :  long file name.txt

Old Name : _long_file_name   .txt
Wildcard : *a*m*a?n
New Name : longfilename.txt

Old Name : 4896-image567.jpg
Wildcard : *m?j?n
New Name : image567.jpg

Old Name : purchase document 87.doc
Wildcard : *d?f?e
New Name : purchase-document-87.doc

Old Name : UPPERCASE-FILE-NAME.xls
Wildcard : *l?n
New Name : uppercase-file-name.xls

Old Name : ~Pretty path.bin
Wildcard : *m*p?n
New Name : PrettyPath.bin

Old Name : new company presentation.ppt
Wildcard : *p?n
New Name : NewCompanyPresentation.ppt

Old Name :   extra  white spaces.txt
Wildcard : *w*d?n
New Name : extra-white-spaces.txt

Old Name : 2016-06-12-document.doc
Wildcard : ?S-?S-?S-?A-?n
New Name : Vortex-document.doc

Old Name : tHIs is  another~test.txt
Wildcard : *m*w*l*d?u?n
New Name : This-is-another-test.txt
Code it... That's all...

Scripter

  • Guest
Re: File Renaming... solving a decades old problem
« Reply #2 on: June 18, 2016, 09:59:34 PM »
A new version of the Renamer algorithm has been uploaded to the top message on this thread. You should update to it, immediately.

Please re-read the first message, it's been updated too.

Please note: a couple of macros have changed and a new test utility has been added.
« Last Edit: June 22, 2016, 05:37:28 AM by Scripter »

Offline Vortex

  • Member
  • *
  • Posts: 482
    • http://www.vortex.masmcode.com
Re: File Renaming... solving a decades old problem
« Reply #3 on: June 22, 2016, 07:00:35 PM »
Real life example to rename some complicated filenames :

Code: [Select]
dir *.cab /b

windows6.1-kb2552343-x64_51acdacad4855a2a04f35e2ac511fd3832a5d931.cab
Windows6.1-KB3020369-x64.cab
windows6.1-kb3078601-x64_785cd5e3b02e0afdac45c6d7c481ba9fd7edbdfc.cab
windows6.1-kb3087039-x64_6543ecf25746dc015c53f26ec9a80d0024f67c9c.cab
windows6.1-kb3109094-x64_570b08f22988118cfa06a014be2a7b66ab493802.cab
Windows6.1-KB3125574-v4-x64.cab
windows6.1-kb3145739-x64_85e13f931690feffe03598bf86ff429d3138dedc.cab
windows6.1-kb3161664-x64_c51e3b68c4df14c7484c3629598c9e96c0576d99.cab

Code: [Select]
Renamer64.exe *.cab ?Cx?I?I?E
RENAME

D:\64bit\
  windows6.1-kb2552343-x64.cab
  Windows6.1-KB3020369-x64.cab
  windows6.1-kb3078601-x64.cab
  windows6.1-kb3087039-x64.cab
  windows6.1-kb3109094-x64.cab
  Windows6.1-KB3125574-v4-x64.cab
  windows6.1-kb3145739-x64.cab
  windows6.1-kb3161664-x64.cab
  (8 Items)

Code: [Select]
dir *.cab /b

windows6.1-kb2552343-x64.cab
Windows6.1-KB3020369-x64.cab
windows6.1-kb3078601-x64.cab
windows6.1-kb3087039-x64.cab
windows6.1-kb3109094-x64.cab
Windows6.1-KB3125574-v4-x64.cab
windows6.1-kb3145739-x64.cab
windows6.1-kb3161664-x64.cab
Code it... That's all...