ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Replace text months to digital months

(1/3) > >>

dcwul62:

The below is really a regular occurrence and so far I have either done nothing about it or manually corrected it.

Replacing text months (Jan* or January, Feb or February.. etc)
with -01- -02-  etc.

Example:

from
bla bla text-23june 2016.xlsx
Bla-Bla bla-bla - 2june 2016.xlsx
All bla-bla - 19 may 2016.xlsx
2nd to last bla bla 7 july 2016.xls
last bla-bla-bla-20 October 2016.xls


to:
bla bla text-23-06-2016.xlsx
Bla-Bla bla-bla - 2-06-2016.xlsx
All bla-bla - 19-05-2016.xlsx
2nd to last bla bla 7-07-2016.xls
last bla-bla-bla-20-10-2016.xls

ideal would be                            notes:
bla bla text 23-06-2016.xlsx          (-23june 2016.xlsx: removed '-' before 23, replaced june with -06-)
Bla-Bla bla-bla 02-06-2016.xlsx     (replaced \s-\s  with single space, added '0' to the 2 and rplaced june with -06-)
All bla-bla 19-05-2016.xlsx            (replaced \s-\s  with single space, replace \smay\s with -05-)
2nd to last bla bla 07-07-2016.xls  (added '0' to the 7, space-july-space with -07-)
last bla-bla-bla 20-10-2016.xls       (replaced -20 with space20 and space October space with -10-)

so
from English_full: January|February|March|April|May|June|July|August|September|October|November|December
from English_abbr: *Jan*|*Feb*|*Mar*|*Apr*|*May|*Jun*|*Jul*|*Aug*|*Sep*|*Oct*|*Nov*|*Dec*
to nmbrs : -01-|-02-|-03-|-04-|-05-|-06-|-07-|-08-|-09-|-10-|-11-|-12-

Maybe this is too complex for a single line regex and requires scripting.
Dates usually are at the filename, any type of filename, so something like:     \.(\w{3,4})

The code could be adjusted to months using local language, e.g. dutch

from Dutch_full: januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december
from Dutch_abbr: *jan*|*feb*|*mrt*|*apr*|*Mei|*jun*|*jl*|*aug*|*sep*|*okt*|*nov*|*dec*
to nmbrs : -01-|-02-|-03-|-04-|-05-|-06-|-07-|-08-|-09-|-10-|-11-|-12-

Any suggestions?

Thanks
=

Lintalist:
I don't know if you are using AutoHotkey - https://autohotkey.com/ - but if you do and/or are willing you can try this script, you only need to set your work folder at the top of the script (here c:\testing) and the run the script, it should also create a log file so you can see what has been done. ALWAYS BACKUP your data before you start testing it.


--- Code: Autohotkey ---; set working folder hereFolder:="c:\testing" ; build filelistLoop, %folder%\*.xlsx        filelist .= A_LoopFileName "`n" logfile:=folder "\" A_Now ".txt" Months:=["Jan[a-z]+","Feb[a-z]+","Ma[ar][a-z]+"        , "Apr[a-z]+","May|Mei","Jun[ie]", "Jul[iy]"        , "Aug[a-z]+", "Sep[a-z]+", "O[ck]t[a-z]+"        , "Nov[a-z]+", "Dec[a-z]+" ] loop, parse, filelist, `n, `r        {         in:=A_LoopField         for k, v in Months                {                 out:=RegExReplace(in,"i)-?\s*(\d{1,2})\s*(" v ")\s*"," $1-" SubStr("0" k,-1) "-")                 if (out <> in)                        {                         FileMove, %folder%\%in%,  %folder%\%out%                         FileAppend, %in% -> %out%`n, %logfile%                         Counter++                        }                }        } MsgBox Done, %counter% files renamed, see %logfile%

dcwul62:
Many many thanks for taking the time to create a script.
I really feel sorry to say that I am not familiar with autohotkey.
Whilst knowing the existence of autohotkey, but I would not know how it works.
I was hoping for a kind of regex solution of vb script that I could use with Directory Opus.

btw: in this example I took .xls as an extension, but it could be anything, .png, .tif, .doc, .pdf ... etc.

Again, thanks for taking the time!

=

tomos:
^ to run the script:

Download AHK and get it started -- I'm using a portable version, they also have an installer version.

Save script above to a file, and give the file an .AHK extension

Modify script as required:
* path
* replace xslx with * if you want all files
Run script file

IainB:
A useful experiential tip that I learned for document retrieval and sorting in document managementsystems: if you need/have dates in the filename, then consider putting them at the front of the filename, and in ISO format:
For example: 2016-07-22 This is the filename.xls

Thus, you can always find/sort documents by date (thus putting the date to good use), and there's no easy mistake about dates in ISO format.

Navigation

[0] Message Index

[#] Next page

Go to full version