What is the best way to retrieve an ID from a file name? - filenames

Scenario:
Our customer is has provided us with files whose names contain an ID number that we need for indexing purposes.
.\root\dir1\a123.txt (ID is 123)
.\root\dir2\abc345.csv (ID is 345)
.\root\dir3\235.xls (ID is 235)
we know what format to expect based on the files location and extension. Our customer would like to be able to add
.\root\dir4\foo556.bar (ID is 556)
meaning we cannot write a custom method for each entry under root.
My Solution:
The solution we are thinking of is to store the formats of the file names in an XML file
<root>
<entry>
...
<format>abc###</format>
...
<entry>
<root>
when the customer want to add a new entry under root they'll have to give a directory, a file extension and a format. Then on our end implement a getID() method that is able to use the format specified in the XML to retrieve the IDs from the file name.
Question:
Has anyone else dealt with a similar situation? If so is there a better solution than the one I have provided?

Assuming the file name will always be on the form <letters><digits>.<extension>, I would use a simple regular expression to match the relevant part of the name. E.g. .*\\[a-z]*\([0-9]*\)\..* (may vary depending on the RE engine in question).

If you want a generic solution which would automatically identify all files that match, Yyou could use file globs in the shell if they are available and work for your particular case:
something like:
ls root/*/ | sed 's/^(.*)([0-9])+(.[A-Za-z][A-Za-z][A-Za-z]+)$/"\1\2\3" \2/' | xargs -n2 runMyProgramHere
if you need to do it programatically, normally directory inquiries are fairly easy in most languages, list everything in /root, of those, list everything, filter by files ending in +.+, there's your list.
in psuedo-code:
for (directory in file.getDirectoryList("/root")) {
for (name in file.getDirectoryList("/root/" + directory)) {
if (name contains a sequence of numbers followed by a dot ending with an extension) {
extract id
store filename and id
}
}
}
you can probably do this with regexes if you really want, but I tend to avoid regexes in programs unless I have a really good reason not to. They are often poorly understood and prone to breaking without good error reporting.

Related

Custom naming of Aeroo report filename in Odoo

is there any way to get the report output from Aeroo named with a custom naming pattern?
I.e., for the invoice: [year]_[invoice number]...
#Raffaele, I'd recommend taking a look here and to this forum post.
You'll need to use some basic python logic in the report_custom_filename module to create the file name you need according to your requirements.
Using the following example I can create output for a filename for Sales Order/Quotation:
${(object.name or '').replace('/','_')}_${object.state == 'draft' and 'draft' or '' +'.xls'}
That looks like this:
SO039_.xls
You can add another field from the document/report you're printing out by adding another section, for example:
${(object.client_order_ref or '').replace('/','_')}_
this will add the field client_order_ref in front of the document name like this:
[Here's your client order reference]_SO039.xls
Have a look at what fields are available in the model you're trying to get this information from (eg. in my case sale.order) and I think you'll find roughly what you need there.
I have still not figured out how to add a date/timestamp like you are requesting (eg. Year), however someone else may be able to offer some advice on this.

Synchronize modification between SWT table and TextEditor

I'm facing a problem and want to ask for a solution.
I'm working on an eclipse plugin project, in which an editor for a type of resource file is required. The resource file has similar structure like CSV file. My idea is to provide user the option to edit this type of file both in plain text format and also in an SWT table. Plain text is required for examining data and table provides more flexibility to editing such as sorting by column.
I have been able to create a MultiPageEditorPart, with one page of org.eclipse.ui.editors.text.TextEditor, and another page with a org.eclipse.swt.widgets.Table and several other widgets like search bar. The content of the resource file can be shown in the TextEditor, can also be edited and saved. On the other hand, the content can be loaded in the table too, sorting and searching all work good.
The problem is: when I edit a cell in the table, I want the change also reflected in the TextEditor, and vice versa. Since the resource file can be very large, I want the saving action happen only on the TextEditor, i.e. I don't want any modification in the table directly stored to resource file, but to mark the file dirty, but I can't figure out how. How can I for example get the content of EditorInput, check it line by line, and modify it outside TextEditor?
Or, are there more efficient ways to do this? Can anyone give any hints?
The IDocument used by the TextEditor gives you access to the document contents. Get this with something like:
IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
IDocument has many methods for accessing lines such as:
int getLineOffset(int line);
int getLineLength(int line);
and methods for modify the text:
void replace(int offset, int length, String text);

Remove sub-string from data in sql table column

I have a table that has a bunch of url's within a certain column. We no longer want a certain url within the table and instead of manually updating each data record I was curious if there is a way to remove just a certain type of url through an update query?
For instance, a data record with the following url's exists:
Presentation (PowerPoint File)<br> Presentation (Webcast)
and I want to remove the smil url so the data only shows:
Presentation (PowerPoint File)<br>
I want to remove the entire "smil" url from this string (from ), and every other smil url from the other records (the other records are similar with a different smil file name). Some of the records could have more than two urls, BUT the "smil" url is always the last one.
Preserving some of the comment history so future readers understand the decision points before implementing the solution
Does it always follow the pattern of text<br>text
there are a few times where there are two urls and they exclude the <br> and then there are a few times where it is just the smil url within the data.
You haven't clearly define what a "smil" url is. Is it one with smil in it anywhere? With the file suffix being .smil? With /smil/ in the path? some combination of these?
The problem you're going to have is that to properly solve this, you'll need to be able to have some insight into the html fragments. That's usually a .NET thing, the string matching in TSQL is likely to be insufficient for your needs. You could try taking multiple passes as it. If it follows the text<br>text pattern, you could left(myCol, charindex(mycol, '<br>')) where Mycol like '%smil%' and keep taking passes at it until you've found all the patterns.
#billinkc: I see where you are going, I was thinking if it would be possible to remove everything from the start of <a href="xxx since those "smil" links all start with that character string.
And there'd never be the case of streaming<br>foo? If so, then yeah, search for the <a href="http: using charindex/patindex (can never remember which) and then slice it out with left/substring.
#billinkc: yup that will always be the case. the "streaming" url is ALWAYS last. Ok this was easier than I thought, just needed some outside eyes. Thank you.
Given that we know we don't have to worry about anything useful existing after the smil url and that the url will always be an external, we can safely use a left/substring approach like
DECLARE #Source table
(
SourceUrl varchar(200)
)
INSERT INTO #Source
(SourceUrl)
VALUES
('Presentation (PowerPoint File)<br> Presentation (Webcast)');
-- INSPECT THIS, IF APPROPRIATE THEN
SELECT
S.SourceUrl AS Before
, CHARINDEX('<a href="http://', S.SourceUrl) AS WhereFound
, LEFT(S.SourceUrl, CHARINDEX('<a href="http://', S.SourceUrl) -1) AS After
FROM
#Source AS S
WHERE
S.SourceUrl LIKE '%smil%';
-- Only run this if you like the results of the above
UPDATE
S
SET
SourceUrl = LEFT(S.SourceUrl, CHARINDEX('<a href="http://', S.SourceUrl) -1)
FROM
#Source AS S
WHERE
S.SourceUrl LIKE '%smil%';

Tortoise SVN property substitution - fails for more than one property "group"

I'm using TortoiseSVN 1.6.12, and seeing something very strange behaviour on property substitution. I have some svn:keyword properties (configured via TSVN) like this:
Author, LastChangedBy, Date, DateLastChanged
which I've applied recursively across every file in the codeset
I then did a simple test on a text file like this
Some text
$Author$
$LastChangedBy$
$Date$
$LastChangedDate$
When I commit my changes, the Author and LastChangedBy properties are substituted but not the Date or LastChangedDate ones. I did some experimenting around combinations and it appears that either the author properties are set, or the date ones (but never both). So it must be doing some validation based on property groups. (In TSVN, you can't simply created another svn:keywords entry, you're stuck with one).
Has anyone ever encountered this and/or is there a workaround?
The problem you have is simply based on that SVN only replaces keywords which are known to SVN.
You are using the following list of keywords set:
Author, LastChangedBy, Date, DateLastChanged
but you have placeholders set in your text file:
$Author$
$LastChangedBy$
$Date$
$LastChangedDate$
the known keywords are the following:
URL, HeadURL
Author, LastChangedBy
Date, LastChangedDate
Rev, Revision
LastChangedRevision
Id
Header
The problem you have that svn:keywords must exactly represents the keywords you would like to replace with values. But be aware that keywords are case sensitive. Furthermore you have defined a keyword "DateLastChanged" which does simply not exist and will of course not be replaced by SVN, cause it's unknown by SVN. On the other hand i assume you have a typo in your svn:keywords contents. may be you can copy&past the output of
svn pl . -v filename
on command line on that file. One point i missed before have you separated the keywords with a space?

Generate unique temporary file paths

I want to generate unique file paths in Objective-C. I looked at NSTemporaryDirectory() but the closest I could get was to this and this. But in the second one they create such a file. I do not want to create it, I just want an NSString for a unique writable path... I don't need paths to folders, just files. How is this possible?
You can create file name using present system date and time ([[NSCalendarDate calendarDate] descriptionWithCalendarFormat:#"%m%d%Y%H%M%S%F"]) .... this include even milliseconds ... use returning string as unique file name ....
Read more about date formates -> http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/DatesAndTimes/Articles/LegacyNSCalendarDate.html