<|endoftext|>
Q:
How to get a list of all files that contain an extension?
I'm trying to get a list (or array) out with the following code, but I can't seem to get it right...
$file = "C:\Users\user\Desktop\test.txt"; // this is what I want
$list = file_get_contents($file);
foreach ($list as $line){
echo $line; // prints out the line that contains an extension, but not a file name...
}
I'm using PHP 5 and Apache 2.2 on Ubuntu 12.04 LTS
Thanks in advance!
EDIT: I've tried the following code to get all files with an extension of .txt (which is what I want), however it doesn't work, any ideas?
$file = "C:\Users\user\Desktop\\test.txt"; // this works but not a file name...
// $list = array();
$file = "C:/Users/user/Desktop/test.txt";
$file_name=$_GET['file'];
$line = explode(",",$file);
foreach ($line as $_) { // this is what I want...
echo $line; // prints out the line that contains an extension, but not a file name.
}
}
I've tried the following code:
$file = "C:/Users/user\Desktop\\test1.txt"; // this works...
echo $line; // prints out all files with extensions that contain an extension, but not a file name..
// I'm trying to get it right now and I can't figure how!
A:
$file = "C:/Users/user\Desktop\\test1.txt"; // this works...
echo $line;
?>
$file_name=$_GET['file'];
// This is what you want to get with the extension
if(strpos($file, '.') !== false){
foreach ($file as $_):
echo " ". strtr($_,"\t"); // this works...
// I'm guessing this isn't what your looking for.
// If you want to get all files with an extension that contains a .txt, use the following code:
if(strpos($file,'.') !== false){
echo " ". strtr($_,"\t"); // This works...
}
?>
EDIT 2: I think you're looking for something like this. I'm not sure what you want to do with the extension, but it should work if your file is .txt and you want all files that contain an extension of .txt (or any other extension). If so then you can use the following code in PHP:
$file = "C:/Users/user/.htaccess"; // this works...
if(strpos($file, '.') !== false){
echo $line;// prints out all files that contain an .txt extension.
}
?>
EDIT 3: I think you want to use the following code if your file is a directory and not just one of those extensions (like my example above):
if(strpos($file, '.') !== false){
echo $line;// prints out all files that contain an extension.
<?php }
<|endoftext|>
Q:
How to get the value from a textbox in asp.net?
I have this code which is working fine but I want it so when user clicks on "Add" button, it should add the value of the textbox and then it should show the value as well..
<asp:TextBox ID="txt_Name" runat = Server1
Text='<%# Bind("name") %>' />
</asp:DropDownList>
<asp:Button ID="btnAdd" Text="add" OnClick= "return Add()" />
<asp:Label ID="lblNew" runat = Server1
Text='<%# Eval("name").ToString()%>'></asp:Label><br />
</asp:DropDownList>
<asp:Button ID="btnAdd" Text="add" OnClick= "return Add()" />
<asp:TextBox ID="" runat = Server1
Text='<%# Bind("name") %>'></asp:TextBox>
<asp:Label ID="lblNew" Runat = Server2
Text='<%# Eval("name").ToString()%>'></asp:Label><br />
</asp:DropDownList >
<asp:Button ID="" runat=Server1
Text="Add" OnClick= "return Add()" />
<asp:TextBox ID="_txt_Name" runat = Server2
Text='<%# Eval("name") %>'></asp:TextBox> </asp:DropDownList>
<asp:Button ID="" Runat = Server3
Text="Add" OnClick= "return Add()" />
<asp:Label ID="_txt_Name" runat = Server4
Text='<%# Eval("name") %>'></asp:Label><br /><br />
</asp:DropDownList> <br/>
A:
You can use the following code to get value from textbox and add it in asp.net control
string txt_Name = "test"; //your text box name here
string[] values = { "name", "value" };
TextBox txt_Name1; // your textBox Name here
string[] values1= { "name", "value1"}; <-- you can use this to get value from textbox and add it in asp.net control
txt_Name = txt_Name1 + values1[0]; //your value is added into the textbox
<|endoftext|>
Q:
How to make a button click event on an element in javascript?
I have created a simple form with a submit button, and I want it so that when you click this button (which is inside of a div), then if there are any other elements within your form which contain the same text as my form's input field ("myForm"), they will be clicked.
Here what i've tried:
<form id="submit" action="/index.php?action=Submit&id=1">
<input type='text' name='myForm' value='test'>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11-jstools2+3/js/jquery_ujs.js"></script><script>
$(document).ready(function(){
$('#submit').click(); //this is the code I'm trying to use in my script, but it doesn't work!
});
</script>`
<div id="myForm">
<input type='text' name='myForm'>
</form>
<script>
$(document).ready(function(){
$('#submit').click(); //this is the code I'm trying to use in my script, but it doesn't work!
});
</script>` //This is where i want this button click event fired.
A:
You can use jQuery's .on() method for that purpose and then you just need a function like so :
$('#submit').click(function(){
var myForm = $('#submit'); //this is the code I'm trying to use in your script, but it doesn't work!
//This is where we want this button click event fired.
}); <---here you can use the .on() method for that
A:
$('#submit').click(function(){
var myForm = $('#submit'); //this works fine, but it doesn't work with .on().
//This is where we want this button click event fired.
}); <---here you can use the function to call your function and then do whatever else that's needed in order for a button on an element (like a text input)
<|endoftext|>
Q:
How to get the value of a variable from another class?
I have two classes, one is called "A" which has a method named GetValue() ,and I want it so when user clicks on the button, that value should be displayed in the second A.
class A{
public string Value;
public int Id;
public void SetValue(string id) {
Id = (int)(id); //this is the variable to store this ID into
}
} //A class
I want it so that when user clicks on "GetValue" button, value should be displayed in A.
How can I do?
Thanks in advance!
EDIT:
Here's my code for getting the value from A :
public string GetValue() {
A a = new A(); //this is the class that gets called when user clicks on "GetValue" button
return (a.Value); //returns this variable in B class
}
A:
You can use the following code to get value from A and store it into another class, then you could call it like this :
A a = new A(); //this is your class that gets called when user clicks on "GetValue" button
<|endoftext|>
Q:
How to make an array of objects in javascript?
I have the following code. I want my object to be an array, but not sure how do i do this with javascript or jquery... ive tried using a for loop and it doesnt seem like its working..
var obj = {
name: 'John',
};
for (var i=0;i<obj[0].length ;++j){
console.log(obj); //this is not working, how do I make this work?
}
//This is the code that isnt working...
A:
You can use a for loop to iterate over each object in your array and then assign it as an argument of .push() method on obj.
var obj = {
name : 'John',
};
for (var i=0;i<obj[0].length ;++j){
console.log(obj); //this is not working, how do I make it work?
//This works!
}
// This will be the code that'snt working...
<|endoftext|>
Q:
How to get a list of all files in a directory?
I have an application which has many folders. Each folder is named with a different name, for example "C:\Users\user1\AppData\Local\Temp". I want each file from the C:\Users\user1\AppData\Local\Temp to be listed as a folder in my directory tree (I have no idea how to do this).
How can i get all files that are found within "C:\\Users\\user1\\AppData\\Local\\Temp" and then list them?
Thanks!
A:
string[] fileNames = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.txt"); //get the current directory of the application folder (in this case C:\Users\user1)
foreach ((string fileName) in fileNames){
string filePath = Path.Combine(fileName, fileName);
<|endoftext|>