Extracting string from a file name
Hello,
I have a legacy (read: I didn't build it) SharePoint list that includes some validation when uploading files that's giving me some trouble.
Basically, our users are required to add files to a list in a certain filename format and based on the naming convention are approved/rejected and routed to the appropriate location.
One of the validations looks at a section of the file name and compares it to a folder name in the library.
For example, the file name format is XX_AAA_999_2014_05.xlsx and that matches on the folder name of /submissions/2014_05
Currently the rule says look at the last 7 characters of the folder and the 7 characters starting at position 12 of the filename and make sure they match.
The problem is the 999 in the example above is a sequential identifier to the project a file is associated with... e.g. they range from project 000 to project 999. We've now hit project 1000 so file being added for project 1000 (and beyond) fails because
the starting position has shifted one spot. (Note: we have active 3 digit projects so I cannot simply change that to be position 13... not to mention what that does to my history).
So, my task is to come up with something that can accomodate 3 or 4 digit numbers.
I'm trying to stick as closely to the original setup so I don't mess up the history so I'm looking at other methods of getting to the same data in the string. Another problem is that the file names include the extension and the extension can be 3 (pdf)
or 4 (xlsx) characters long.
I've tried this: =LEFT([Source File Name],SEARCH(".",[Source File Name])-1)
but that brings back everything in front of the period and I need just the 7 preceeding characters. Is there a way to limit the number of chars a LEFT() function returns?
In a nutshell, the 4 variations of file names are as follows of which I need to extract the
bolded section.:
ZZ_AAA_999_2014_05.xls
ZZ_AAA_999_2014_05.xlsx
ZZ_AAA_1000_2014_05.xls
ZZ_AAA_1000_2014_05.xlsx
Thanks!
Kevin
Hi,
According to your description, you might want to retrieve the string “2014_05” from the file name.
I would suggest you create a SharePoint Designer workflow and implement your logic of handling the filename.
In SharePoint Designer 2010, there are already some useful utility workflow actions which can enable users to deal with the various requirements come from the business scenarios.
For the string handling, you can consider to use the
Utility Actions:
http://msdn.microsoft.com/en-us/library/office/jj164026(v=office.15).aspx
Another two links about creating SharePoint Designer workflow for your reference:
http://office.microsoft.com/en-001/sharepoint-designer-help/introduction-to-designing-and-customizing-workflows-HA101859249.aspx
http://www.codeproject.com/Tips/415107/Create-a-Workflow-using-SharePoint-Designer
Thanks
Patrick Liang
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Patrick Liang
TechNet Community Support
Similar Messages
-
File-File - Need to extract data from source file name???
Hello Experts,
I have a unique situation. In my file to file scenario, the source file name is of the format XYZ_yymmddHHMM.dat. there is field in the target file which has to filled with the date that is there in the file name of the source file (yymmdd). How can this be achieved? Normally we do the other way round using vaiable substitution where we can name a file depending on the value in any of the target field structure.
Please help.
Regards,
YashHi,
please prepare the udf with the following code.
i mean, dynamic configuration concept.
where u get the file name, then use substring function to capture date from right side.
//write your code here
// getFileName User Defined Function
// function to create name of output file
String filename;
filename = strFile;
try {
// initialize DynamicConfiguration for create file with given name
DynamicConfiguration conf = (DynamicConfiguration) container
.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");
//create file with the specified name
conf.put(key, filename);
} catch (Exception ex) {
return filename;
warm regards
mahesh. -
I’m not even sure if the publishing service, File Naming, in Lightroom supports Regular Expressions or not?? Basically I’m trying to extract the left portion of the file name ie: everything before the underscore “_”. When I import a file I rename the file to reflect the current Image sequence number and then append the date the photo was taken; a typical file is as follows “05625_2008-01-05.dng” on export I would like the new name to be only the sequence number in this case “05625.jpg”. Ideally I would then like to append the folder name that contains the file… “05625 - FolderName.jpg.
I don’t want to go down the road of figuring out the correct syntax if regular expressions aren’t supported. Thanks in advance - CESIs the imported sequence number captured in meta data somewhere or is their somewhere that all of the available fields and there reference names can be found???
Unfortunately not anywhere available to the user (but it's still stored in at least some filed I know off).
By the way, why did you choose to put the suffix at the beginning of the name (1234_2010-08-13.jpg)? The common practice is to leave the suffix at the end. That will ensure the filenames will sort in chronological order by filename and you could have easily used the suffix when exporting files. You wouldn't have this problem now. -
Extracting strings from binary data
Hello,
I am trying to extract string from a binary file.
At the unix command line (sunos) I can just type;
strings <filename>
This is a nice way to get a list of the contents of a directory.
Is there a way in pl/sql to extract strings from binary data ? An equiv to strings on unix/linux ?
Thanks in advance.
BenHi,
If you do want to list the contents of a directory, there are other ways to do it. Here's a base implementation of a utility I wrote:
create or replace and resolve java source named "Util" as
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class Util {
public static void listFiles(String directory, oracle.sql.ARRAY[] names)
throws IOException, SQLException {
File f = new File(directory);
if(f==null)
throw new IOException("Directory: "+directory+" does not exist.");
String[] files = f.list(
new FilenameFilter() {
public boolean accept(File dir, String name) {
// List all files
return true;
Connection conn = new OracleDriver().defaultConnection();
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("VC_TAB_TYPE", conn);
names[0] = new ARRAY(descriptor, conn, files);
return;
create or replace type vc_tab_type is table of varchar2(255);
create or replace package util authid current_user as
function list_files(p_directory in varchar2)
return vc_tab_type;
end;
create or replace package body util as
procedure list_files (
p_directory in varchar2
, p_filenames out nocopy vc_tab_type
is
language java
name 'Util.listFiles(java.lang.String, oracle.sql.ARRAY[])';
function list_files(p_directory in varchar2) return vc_tab_type
is
l_filenames vc_tab_type := vc_tab_type();
begin
list_files(p_directory, l_filenames);
return l_filenames;
end;
end;
/You can then query the filesystem as follows:
1 select column_value as filename
2 from table(util.list_files('c:\windows'))
3 where column_value like '%.log'
4* and rownum <= 10
SQL> /
FILENAME
0.log
AdfsOcm.log
aspnetocm.log
bkupinst.log
certocm.log
chipset.log
cmsetacl.log
comsetup.log
DtcInstall.log
FaxSetup.log
10 rows selected.cheers,
Anthony -
How do I grab a value from a file name and load it in a field/column?
Hi,
I am loading this .txt file (OUS_RAW_NYC_05_2011.txt) into an internal table i_raw.
I want to pick out the NYC characters from the file name and fill it as value for <wa_raw>-field1 for all records.
How do I do this?
Pls advice.
Thanks!Hi Durgesh,
I am doing this in a program via SE38 and not via transformation routine.
Now I am working on this piece of code to get the value.
file_str = //rdmsbw/dev/data/output/all/OUS_RAW_HCM_05_2011.txt
I only want the characters HCM from file_str.
When I execute this code below:
MOVE file_str TO org_unit.
WRITE / org_unit+37(12).
<wa_raw>-/BIC/ZOUORGUT = org_unit.
my output is = //rdm
how do i extract out HCM?
Pls advice.
PS: also pls help me out with my another post
http://forums.sdn.sap.com/thread.jspa?threadID=2141618&tstart=0 -
How to extract data from XML file with JavaScript
HI All
I am new to this group.
Can anybody help me regarding XML.
I want to know How to extract data from XML file with JavaScript.
And also how to use API for XML
regards
NagarajuThis is a Java forum.
JavaScript is something entirely different than Java, even though the names are similar.
Try another website with forums about JavaScript.
For example here: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3 -
Is it possible in java to extract audio from video file and ...
Hi,
Is there any API in java for creating DVD video from Normal TV and extract audio from video file and convert MP3 to WMA file. What about java Media Framework and Java 3D API?
If it is notpossible in java which will be the next option. Vc++?
Please help me.
Thanking in advance.
From,
Vinod Alol
If all you want is to create a backup of some file you can do:public class Foo
public static void main(String[] args) {
Foo f = new Foo();
f.createBackup("something.xls");
public void createBackup(String inFile) {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream(inFile);
out = new FileOutputStream(inFile + ".bak");
int read;
while ((read = in.read()) > -1) {
out.write(read);
out.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
} -
Code Challange - Code for extracting content from a file in KM
Hi,
I want to extract content from a file which is in KM Repository using the Webdynpro View. I wrote the following code for the extraction. But it is throwing some exception.
Code Written:
<b>
URLConnection conn = null;
DataInputStream data = null;
String line;
StringBuffer buf = new StringBuffer();
wdContext.currentContextElement().setTextdisp("Hello");
try {
URL theURL = new URL("http://ctssap1:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/News/New%20text.txt");
conn = theURL.openConnection();
// conn.connect();
wdContext.currentContextElement().setTextdisp("Inside Try");
data = new DataInputStream(new BufferedInputStream(
conn.getInputStream()));
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
data.close();
String buffer = new String(buf);
wdContext.currentContextElement().setTextdisp(buffer);
catch (IOException e) {
wdContext.currentContextElement().setTextdisp("IO Error:" + e.getMessage());
}</b>
Exception Got:
<b>IO Error:Server returned HTTP response code: 401 for URL: http://ctssap1:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/News/New%20text.txt</b>
Can anyone help me out in this process... or please suggest some other way to extract the content.
Thanks in Advance.
Regards,
Srinivas.Hi Srinivas,
VaPath will have the path of ur document.
Check this modified code snippet which will answer ur questions and solve ur problem.
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser. getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
IResourceContext context = new ResourceContext(ep5User);
/Specify the path of ur document here./
RID pathRID = RID.getRID("/documents/file2");
IResource resource = ResourceFactory.getInstance()
.getResource(context);
InputStream in = resource.getContent().getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int bytesread = 0;
while ((bytesread = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesread);
String myData = out.toString();
/*myFile will containS the content of the document./
wdComponentAPI.getMessageManager().reportSuccess(myData);
Hope this solves ur problem.
Regards,
Sowjanya. -
Need to get a particular string from a file!!
Hi-
In a linux server,i need to pull some data from the logfiles from the dir "
/dev/bld/autosys/autosys-be/jobs/",under this dir we have so many applications like- ada-2013.06.0,bda-2013.06.0,cda-2013.06.0 etc...
Which are also directories(
ada-2013.06.0,bda-2013.06.0,cda-2013.06.0) under this each dir ,we can find a logfile.
from the logfile we need to pull some data to generate a report.
Here in the logfile we could find a request name "xyz
-sib_ada-2013.06.0" after the string "ci-" in every part of logfile,so i would like to pull this information from the logfle after that i would like to issues the command "p4 branch xyz-sib_ada-2013.06.0" to get source and target details.
if you issue the above command it looks like...
Branch:xyz-sib_ada-2013.06.0
Update: 2013/05/13 12:25:28
Access: 2013/05/31 13:48:56
user : xxx
Description:
Created by xxxx
status : unlocked
View:
//xyz-sib/fb-download-app/ada-server/mda-2013.05.0/... //xyz-sib/fb-download-app/ada-server/mda-2013.06.0/...
here i would like to pull the string as source thing as //xyz-sib/fb-download-app/ada-server/mda-2013.05.0/
target -
//xyz-sib/fb-download-app/ada-server/mda-2013.06.0/...Hi,
Its very hared to understand what you want, if i understand correctly you want to find some set of string from the files in a diretory
if yes you can do something like this
cd /dev/bld/autosys/autosys-be/jobs/
find . -type f -exec grep "<string you want to serch>" {} \; -print
It will list the file having some set of string you are serching..
HTH -
Hi ALL,
Can any one help us regarding How to fecth the Date column(or month column) from the file name specified in the path in a generalized way .
For example :
file name is :subscribers (Cost) Sep13.csv is specified in the below path
E:\Accounting\documents\subscribers (Cost) Sep13.csv
here I need to fetch the "Sep13" as a Date column in the ODI 11g in the generalized way.
Can any one help us in this case as early as possible.I would suggest using a piece of Jython code for this. Something like this...
import os
import os.path
filelist = os.listdir(E:\Accounting\documents\)
for file in filelist:
datestr = file[19:-4]
You'd need to work out what to do with datestr next... perhaps write it to a table or update an ODI variable with it.
Hope this is of some help. -
Hello guys,
I need some help. I have to remove some content of Tolerance "column" (see attach). The string which I wish to remove is "+/- 0s" and replace it with an empty string. I need to remove this for each row where "+/- 0s" appears.
Thanks
Solved!
Go to Solution.
Attachments:
sample.txt 3 KBHi Samoth,
I dont know if I understood your requirement properly, but please check the attached snippet if it helps.
If this does not satisfy your requirement, then please give some more details.
Attachments:
Remove string from txt file.png 21 KB -
API extracting keywods from text files
hi all,
i will be grateful if any of you can suggest some free java api which can be used to extract keywords from text files.
thanx in advance
mallsjava.util.regex - regular expressions API in JDK 1.4
-
Hi, extract data from xml file and insert into another exiting xml file
i am searching code to extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
1st xml file which has two lines(text1.xml)
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:PrintDataRequest xmlns:xs="http://com.unisys.com/Anid"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
<xs:Person>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
These two lines has to be inserted in the existing another xml(text 2.xml) file(at line 3 and 4)
Regards,
bubblyJadz_Core wrote:
RandomAccessFile? If you know where you want to insert it.Are you sure about this? If using this, the receiving file would have to have bytes inserted that exactly match the number of bytes replaced. I'm thinking that you'll likely have to stream through the second XML with a SAX parser and copy information (or insert new information) as you stream with an XML writer of some sort. -
Extract data from xml file and insert into another exiting xml fil
hello,
i am searching extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
Regards,
ZhuozhiIf the files are small, you can load the target file in a DOM document, insert the data from the source file and persist the DOM.
If the files are large, you probably want to use a StAX or SAX. -
Extract data from XML file to Oracle database
Dear All
Please let me know, how to extract data from XML file to Oracle database which includes texts & images.
Thanking You
Regards Lakmal MarasingheI would do it from the database, but then again, I am a database / PL/SQL guy.
IMHO the database will deliver you with more options. I don't know about "speed" between the two.
Maybe you are looking for
-
How do I unlock an iphone 5 with Sprint 15.1 at IOS 7.0.6 IMEI 99 000320 012095 0 . The SIM is in and Sprint gave me the unlock code, but what are the steps to unlock it?
-
Firefox doesn't completely close and an error message comes up
It wasn't until this current version 10 of Firefox, did I start to experience an issue that seemed odd. Every time I close out of Firefox, I am assuming I'm completely out of it, but it's still running in the background. Shortly after I close Firefox
-
Sound Breaks Up Intermittently
I have a Toshiba 40 "inch (40FT1U) HDTV on which the sound intermittently breaks up during shows. It is connected to a surround sound which blinks (as it should) when the sound is breaking up. I'm sure it's the TV, I'm just not sure why it is happeni
-
No P4040L statement account type is defined in chart of accounts 4040
Hello, I have maintained account group P & L in SPRO>Financial Accounting>General Ledger accounting>Preparation>Defined Account Group. When trying to create G/L account FS00 it throws error message No P4040L statement account type is defined in chart
-
Photoshop CS6 crashes whenever I use font tool
I've browsed the other discussion threads with the same problem, but I am very confused as I have limited computer knowledge. I've used the font tool on CS5 before and there was no problem, but now when I use CS6 it either crashes or it lags so much