Loop through sub-directories
Hi,
I want to loop through the sub-directories of one given folder. How to correct the following problems?
dir = args[0];
try
string [] dirlvl2Ent = Directory.GetDirectories(dir);
for (string dirlvl2 in dirlvl2Ent)
Error 1 ; expected F:\App8\Program.cs 50 37 ProcessSWFile
Error 2 ; expected F:\App8\Program.cs 50 40 ProcessSWFile
Error 3 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement F:\App8\Program.cs 50 40 ProcessSWFile
Many Thanks & Best Regards, Hua Min
for should be foreach.
string [] dirlvl2Ent = Directory.GetDirectories(dir);
foreach(string dirlvl2 in dirlvl2Ent)
jdweng
Similar Messages
-
ANT task to interate through sub directories
I want to execute the same ANT target over a number of subdirectories. I also need to "pass" or set and environment variable which is the sub-directory name and pass it to the ANT target. I have researched the documentation, but have found no task that will do this. Any suggestions, short of writing my own ANT task?
thanks
DonOK, so I wrote my own task, but I am having a bit of a problem:
creating an Ant task which loops through subdirectories and then calls an Ant target ? this is easy enough through the project.executeTarget method. I pass the subdirectory name as a property to the ?called? target. This I do through the project.setProperty method.
Yet the target only has the original value of the property and not the modified value. I am assuming that this is because once a target and its tasks are loaded, the properties are then fixed ? immutable.
So my strategy is to ?refresh? the target before my task executes the target. I was thinking to create a new target, do a shallow copy of info, copy to the project and then execute the new target. Thoughts? Other ideas?
Here is the sample ANT build code:
<target name="build" >
<IterateDirectoryTask RootDirectory="." ExecuteTarget="TestTarget"/>
</target>
<target name="TestTarget" >
<echo message="Hello from TestTarget" />
<echo message=" subdirectory = ${subdirectory}" />
</target> And here is the TASK:
public class IterateDirectoryTask extends Task {
private String _rootDirectory;
private String _executeTargetName;
public void setRootDirectory(String aDirectoryName) {
_rootDirectory = aDirectoryName;
public void setExecuteTarget(String aTargetName) {
_executeTargetName = aTargetName;
public void execute() throws BuildException {
if (_executeTargetName == null) {
throw new BuildException("ExecuteTarget must be specified");
File lRootDirectory = new File(_rootDirectory);
if (!lRootDirectory.isDirectory()) {
throw new BuildException("'"+_rootDirectory+"' is not a directory");
File[] lFiles = lRootDirectory.listFiles();
for (int i=0; i < lFiles.length; i++) {
if (lFiles.isDirectory()) {
project.setProperty("subdirectory", lFiles[i].getName());
Target lTarget = (Target)project.getTargets().get(_executeTargetName);
project.executeTarget(_executeTargetName); -
Looping through a directory to insert BLOBS
I have about 300GB of jpegs to insert into my database. Does anyone have an example of how to loop through the directories, a directory at a time, to insert all of the images? Thanks.
The best way is to probably use Java it iterate through the directories. You could either store the files in the database (BLOB) or just reference their location (BFILE). Unless you have another 300 or so GB to load the files in the database you will have to reference them. Unless you load a few hundred jpgs, delete them, ... loop. That way you would have the storage requirements. Java handles file access great and because you can wrap the java methods with PL/SQL its a great one two punch. Of course, you will need a java developer (ie. me).
-
Loop through the excel files in folder and sub folder
hi all
I need to loop through all the excel fies in a folder and its sub folder which contain excel files
actually, my excel files contain a column with sdate and it contain different dates in which has to get the max date my query is
"select * from @[User::filename] where sdate=(select max(sdate) asi from @[User::filename] )"
loop all the excel file in folder and its sub folderTake a look at the Foreach Loop.
Here is an article about it.
Andy Tauber
Data Architect
The Vancouver Clinic
Website | LinkedIn
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
"Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
Hi everyone
I am new in crystal reporting and using Crystal Reports XI release 2. Firstly I should explain what I need to have. In my database I have got a parent table called Initiatives and a child table called benefits. One initiative has got many benefits associated with it and benefits are updated regularly by the users. Now my manager wants me to create an Initiative reports in such a way that all the initiatives are displayed and against each initiative there should be a box filled with either of these colour (red, yellow, green).
Let's say if Initiative "X" has got 10 benefits and if one or more benefits are outstanding by more than 2% then the colour of the box should be red. And if no benefit is outstanding by more than 2% and one or more benefits are outstanding more then 1% and less then 2% then colour of box should be yellow. And if no benefit is outstanding more than 1% then colour of box should be green.
Now for this I have created a report displaying all initiatives and a sub report with a SQL command containing the data from the benefits table. I have also included a database field which I would use as a box.
Now I want to loop through each record of the crystal report till the last record and format the field as per condition. I would probably use nested loop to look for the status of the benefits but I don't know how to do this in CR. In short I am looking to do this thing in CR
While Recordset.EOF
Do
But I can't find a key word for EOF or count-1 or some thing like that.
Seeking the help of you guys.
Regards,It would be much easier to simply let Crystal's conditional formatting do this for you.
Almost every formatting aspect of each object in Crystal can be controlled via expressions. Just click on the expression button to the right of the property...
ido -
I got this really great script that loops through some XML files and does stuff based off the content.
What I would like to do now is have it repeat when it gets to a certain field. for example my xml file would look like this.
<xml>
<fileName>nameoffile</fileName>
<userEmail>[email protected]</userEmail>
<commandList>
<item>info here</item>
<item>more info here</item>
<item>yet more info</item>
<item>still more info here</item>
</commandList>
</xml>
then basically i need the applescript to see the <commandList> tag and then repeat for each item.
i can't seem to wrap my head around how to get it to happen.
currently I am using this to extract the normal tags from the xml file
set theXML to choose file
tell application "System Events"
tell XML element 1 of contents of XML file theXML
set the fileName to value of (XML elements whose name is "fileName")
... and so on
end tell
end tell
i believe i have to put an if statment in saying that if the element name == "commandList" then
repeat with item in commandList
my stuff here.
end repeat
but i'm not sure how to build the statement.
thanks for any help.
PSomething like this?
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into the Script Editor">
set theXML to POSIX path of (choose file)
tell application "System Events"
tell XML element 1 of contents of XML file theXML -- root element
set the fileName to value of XML element "fileName"
get value of XML elements of XML element "commandList" -- sub elements
repeat with anItem in the result
log anItem
end repeat
end tell
end tell
</pre> -
How I search only sub directories in my bookmarks?
If I do search Firefox searches through all my bookmarks. I only want it to search in the current directory and/or sub directories.
I do not want to use tags. I just want to search for the name.Is there any add-ons that I can use to make searching my bookmarks useful. It is now getting beyond frustrating. I can not believe this program doesn't have a useful way to search.
-
Looping through an objects children
This post is related to another post I have in the forums:
"Dynamically adding containers".
However, I am using an object (note this object can change -
is dynamic):
[CODE]
[Bindable]
public var dashboardDP:Object =
{item:"dashboard", children: [
{item:"vbox", id:"vbox 1", children: [
{item:"panel", id:"panel 1", children: [
{item:"hbox", id:"hbox 1", children: [
{item:"view" id:"view 1"},
{item:"view" id:"view 2"},
{item:"view" id:"view 3"}
{item:"hbox", id:"hbox 2", children: [
{item:"view" id:"view 4"},
{item:"panel", id:"panel 2", children: [
{item:"vbox", id:"vbox 2", children: [
{item:"view" id:"view 5"},
{item:"view" id:"view 6"},
[/CODE]
And I want to loop through every child in this object but am
struggling to do so :(
e.g. the following loop will ony return the first child of
the object:
[CODE]
for(var i:int=0; i<dashboardDP.children.length; i++)
// some code.....
[/CODE]
I want to advance this loop so that it "drills" into and
retrieves / reads every child and sub child of each parent etc.....
Is this possible???
Any help would be much appreciated on this one.
Thanks in advance,
Jon.Hi "xtempore" thanks for the fast reply!!!
Just off the top of my head... I am using an Object type for
"dashboardDP".
Will this work as in your example to loop through and get all
the children?
I notoce you are using a type UIComponent and referencing
UIComponent.children - will this work?
I have train but am getting errors... with the line:
for each (var c: UIComponent in comp.children) {
when trying to access the ".children"
Could you please expand?
Thanks again,
Kind Regards,
Jon -
When importing from digital camera, I get all my photos arranged into sub-directories (one for each new shooting session), each with its own data and thumbs folder. Fine for iphoto, but when wanting to burn onto CD for storing/playing on TV, using on other computers, etc, it's an absolute pain. Is there any way I can just import all the images on the camera into one straight folder?
I'm not aware that iPhoto 4 (or earlier) does what you describe -- Which version of iPhoto are you using?
Secondly, if you're wanting to burn images to a CD (and not as an iPhoto Library), then it's a simple matter to export the desired images to a folder on the desktop, and all you'll have is the JPG images -- burn that folder to CD.
Another alternative is to download your camera's contents directly to a folder in the Finder using Image Capture, and leave iPhoto out of the loop entirely. -
How to loop through many XML messages and parse them ?
Hi All
I have been trying very hard to loop through many XML messages and process each of them. Let me first explain the problem -
Suppose I have the following String -
<xyz>
<abc>happy</abc>
</xyz>
<xyz>
<abc>new</abc>
<xyz>
<xyz>
<abc>year</abc>
</xyz>
I have to process each message within the <xyz></xyz> tag and find the falue of <abc> element (happy, new and year).
The extraction of <abc> value is very simple, I am using SAX parser's startElement() method to check every element's name and if the element's name is <abc> pick up the value. But I am not able to loop through the different messages within the <xyz></xyz> tag.
I am thinking of using another DOM parser -
DOMParser domParser = new DOMParser();
StringReader rdr = new StringReader(inputXML);
InputSource src = new InputSource(rdr);
domParser.parse(src);
Document doc = domParser.getDocument();
NodeList nodeList = doc.getElementsByTagName("xyz");
Now I can loop through this nodeList, but not able to. Is using the DOM parser and NodeList the preferable way of lopping through the messages, then how I can loop through ? Or is there any other way ?
I have been trying on this for quite a few days, but not able to. Can you please help me out ?
Thanking you in advance ....
Nirmalya SinhaHi,
Try using the SAX reader from the dom4j package. The document object that you receive contains methods for getting the root elements and with that you can traverse down to the sub elements of it.
Hope this was of some help. -
Looping through Collection and getting ConcurrentModificationException
I'm trying to loop through a collection to delete some objects referenced by that collection but keep coming up against a ConcurrentModificationException.
BwView view = svci.getViewsHandler().find("Lists");
Collection<BwSubscription> subarr = new TreeSet<BwSubscription>();
subarr = svci.getSubscriptionsHandler().getAll();
if (subarr == null) {
logger.info("Its not working");
for (BwSubscription sub: subarr) {
logger.info("Removing subs " + sub);
svci.beginTransaction();
svci.getSubscriptionsHandler().delete(sub);
logger.info("Deleting calendars :" + sub);
svci.endTransaction();
The loop is allowing me to delete the first entry but then fails with the exception.
I have tried with a generic loop but this doesn't initialise the sub entity so the loop fails and is ignored leading to problems later in the code.
BwView view = svci.getViewsHandler().find("Lists");
BwSubscription[] subarr = (BwSubscription[])view.getSubscriptions().toArray(new BwSubscription []{});
if (subarr == null) {
logger.info("Its not working");
for (int i=subarr.length - 1; i>=0; i--) {
sub = subarr;
logger.info("Removing subs " + sub);
svci.beginTransaction();
svci.getSubscriptionsHandler().delete(sub);
logger.info("Deleting calendars :" + sub);
svci.endTransaction();
Sub is either not initialised or gets initialised as 0 causing an ArrayIndexOutofBoundsException. I'd be grateful for some advice on getting the code to loop correctly.While iterating over a collection (using its iterator), a ConcurrentModificationException will be thrown if the collection is modified, except if it is modified using the iterator itself.. The enhanched for-loop you're using is iterating over the collection by implicitly using an Iterator. To do what you want, make the Iterator explicit (change the enhanced for-loop to a while loop) and then use iterator.remove().
-
Nested Loops...looping through one month of data at a time year by year
Hi all,
I'm trying to create an insert statement that loops through a table that has 10 years of data (2001 to 2010) month by month to minimize impact on server and commits more frequently to avoid filling up the redo logs and rollback tablespaces. The table is large, has about 40 millions records per year. Lets say the structure of the table is the following:
Customer_ID number(9),
Order_Item_1 number(6),
Order_Item_2 number(6),
Order_Item_3 number(6),
Order_date date
The table is in flat format but I want to normalize it so that it looks like the following:
Customer_ID Order_Seq Order_Item Order_date
999999999 1 555555 01-jan-2001
999999999 2 666666 01-jan-2001
999999999 3 444444 01-jan-2001
888888888 1 555555 03-jan-2001
888888888 2 666666 03-jan-2001
But because I want to loop through month by month....I need to set it up so that it loops through month by month, year by year (Using the Order Date Field) and Order_item by Order_item. Something like:
so my insert statements would be something like if I hardcoded instead of put the insert statement into a loop:
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
insert into orders_normalized
(Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='03';
Hope this makes sense.
ThanksDoes the sequence of items in an order really matter? In other words, do we really need to preserve that an item was in position 2 versus position 1? I bet that the sequence or position of each item in an order is not meaningful. They were probably numbered 1, 2, and 3 just to make them uniquely named columns so there would be three slots to hold up to 3 items in the denormalized table.
You only have about 400 million rows to insert, so it could feasibly be done in a single transaction (depending on your database environment).
You can always do a create table as select (CTAS) to help with undo / redo issues and get better performance. You could run it in parallel, and spit it out to a new table partitioned by month. Single DDL statement running in parallel making your new table--sounds good to me.
How about something like this:
CREATE TABLE ORDERS_NORMALIZED
(CUSTOMER_ID, ORDER_ITEM, ORDER_DATE)
PARTITION BY RANGE(ORDER_DATE)
PARTITION p200901 VALUES LESS THAN (TO_DATE('200902','YYYYMM')),
PARTITION p200902 VALUES LESS THAN (TO_DATE('200903','YYYYMM')),
PARTITION p201012 VALUES LESS THAN (TO_DATE('201101','YYYYMM'))
as SELECT CUSTOMER_ID, ORDER_ITEM_1, ORDER_DATE
FROM OTHER_TABLE
WHERE ORDER_ITEM_1 IS NOT NULL
UNION ALL
SELECT CUSTOMER_ID, ORDER_ITEM_2, ORDER_DATE
FROM OTHER_TABLE
WHERE ORDER_ITEM_2 IS NOT NULL
UNION ALL
SELECT CUSTOMER_ID, ORDER_ITEM_3, ORDER_DATE
FROM OTHER_TABLE
WHERE ORDER_ITEM_3 IS NOT NULL.....................
Out of curiosity, why not normalize it further? You could have used two tables instead of one.
One (ORDER) with:
ORDER_ID
CUSTOMER_ID
DATE
Order_id would be a new surrogate key / primary key.
Another table (ORDER_ITEM) with:
ORDER_ID
ORDER_ITEM
It would be a table that links ORDERS to ITEMS. You get the idea. -
Text is not being displayed in sync on a label when looping through a list -- how to fix?
I have a list of states (50 states). I loop through this list (in a winform app -- VS2012) and want to display the current state ID that is being processed in the loop in the text property of a label. I precede the label.Text = StateID line with
Application.DoEvents() but I am also (in Debug mode) writing the same text to the console. The console displays correctly, but there appears to be a lag in the label.Text property
List<string> StateList = new List<string> { "al", "ak", "az","ar","ca","co","ct","de","fl","ga",...};
foreach (string stateID in StateList)
Application.DoEvents();
lblStateID.Text = "State is " + stateID; //--there is a lag here
I vaguely recollect something about a NotifyPropertyChanged event. I know this is common in WPF, but is there something similar in winform? Or is there a way to make the desired text to be displayed in the label.Text property in synchronization
with the loop?
Rich PThank you. This is way simpler than implementing the INotifyPropertyChanged Interface. Although, here is an article on the INotifyPropertyChanged Interface and event
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx
Rich P -
How to out from infinite while loop in sub VI
Dear Sir,
how to out from infinite while loop in sub VI from main VI
attached photo for solution but I can't understand it and i can't find the function in photo
please help
Attachments:
stop_subVI_frm_main.JPG 36 KBAsking how to get out of an infinite loop is like asking how to find the end of a circle. I'm not trying to be sarcastic but by definition, if there is a way out of the loop, then it is not infinite. I think what you are asking is how to avoid creating an infinite loop. Is there something about the suggestions you have been given that you do not like? My favorite suggestion is the notifier but maybe you just need an example. Turn on context help and read about the notifier functions in the code below.
This is your top level VI
And this is your subVI
If this seems too complex then a global variable will work too. But what seems simpler can cause much more complex bugs. You can code fast and spend lots of time debugging or you can code slow and spend less time debugging. Personally I perfer writing productive code than looking for bugs any time.
=====================
LabVIEW 2012 -
Automator - Loop through a text file and process data through a 3rd party software
Just stumbled on Automator the other day (I am a mac n00b) and would like to automate the processing of a text file, line-by-line, using a third party tool. I would like Automator to loop through the text file one line at a time, copy the string and keep as a variable. Next, place the variable data (copied string) into the text field of the 3rd party software for processing. Once the processing is complete, I would like Automator to fetch the next line/string for processing. I see items like "copy from clipboard" and "variables" within the menu but I am not finding much documentation on how to utilizle this tool. Just hear how potentially powerful it is.
The 3rd party software is not a brand name, just something made for me to process text. I may have to use mouse clicks or tabs + [return] to navigate with Automator. A term I heard on Bn Walldie's itunes video series was "scriptable software" for which I don't think this 3rd party app would be.
Kind regards,
jwGood news and bad news...
The good news is that it should be entirely possible to automate your workflow.
The bad news is that it will be a nightmare to implement via Automator, if it's even possible.
Automator is, essentially a pretty interface on top of AppleScript/Apple Events, and with the pretty interface comes a certain stranglehold on features. Knowing how to boil rice might make you a cook, but understanding flavor profiles and ingredient combinations can make you a chef, and it's the same with AppleScript and Automator. Automator's good at getting you from points A to B but if there are any bumps in the road (e.g. the application you're using isn't scriptable) then it falls apart.
What I'm getting at is that your requirements are pretty simple to implement in AppleScript because you can get 'under the hood' and do exactly what you want, as opposed to Automator's restricted interface.
The tricky part is that if no one else can see this app it's going to be hard to tell you what to do.
I can give you the basics on reading a file and iterating through the lines of text in it, and I can show you how to 'type' text in any given application, but it may be up to you to put the pieces together.
Here's one way of reading a file and working through each line of text:
-- ask the user for a file:
set theFile to (choose file)
-- read the file contents:
set theFileContents to (read file theFile)
-- break out the lines/paragraphs of text:
set theLines to paragraphs of theFileContents
-- now iterate through those lines, one by one:
repeat with eachLine in theLines
-- code to perform for eachLine goes here
end repeat
Once you have a line of text (eachLine in the above example) you can 'type' that into another application via something like:
tell application "AppName" to activate
tell application "System Events"
tell process "AppName"
keystroke eachLine
end tell
end tell
Here the AppleScript is activating the application and using System Events to emulate typing the contents of the eachLine variable into the process. Put this inside your repeat loop and you're almost there.
Maybe you are looking for
-
PS CS6 Smartobject - Changing color space not working
If I initially open a smartobject from ACR into PS CS6 using one color space, eg. sRGB, should it then be possible to click back into ACR and change color space to Adobe RGB ??? This is important to me, since working most of the time in sRGB, batch e
-
I downloaded the latest version of Firefox to install on my Mac (OS 10.5.8). When I tried to install it gave me a message saying I had "insufficient privileges". I am using the Admin account. What should I do?
-
I'm writing a program to reorganize some music. And I have a special case where bands that begin with 'The' need to be organized differently. So I'm writing a method to rename the music directories, but I am having trouble figuring out how to determi
-
Why do I have to keep setting up my iPad almost every time I start my iPad?
Lately-it seems that with greater freaquency my ipad is saying it is not setup, I can't do anything until I reset it all back up. it happens almost everytime i start up now. ARGH! does anyone have answers, it seems to have started after the last upda
-
Sales targets for sales office
hi experts how to set target for sales office wise in sap sd. Thanks