PHP how to list all files in directory in a combobox - only file names and not with full paths |
$files = glob('images/items/Done/*.jpg');
echo "<select>";
foreach ($files as $file) {
echo "<option>".pathinfo($file, PATHINFO_BASENAME)."</option>";
}
echo "</select>";
|
finding most recent file version from list of file path names with jumbled file names |
you can try:
find $WORK.../.history -type f -printf '%T@ %p
' | sort -nr | cut -f2- | xargs grep 'your_pattern'
Decomposed:
the find finds all plain files and prints their modification time and path
the sort sort sort them numerically - and reverse, so highest number comes
first (the latest modified)
the cut removes the time from each line
the xargs run its argument for each file what get to it input,
in this case will run the grep command, so
the 1st file what the grep find - was the lastest modified
The above not works when the filenames containing spaces, but hopefully
this is not your case... The -printf works only with GNU find.
For the repetative work, you can split the command to two parts:
find $WORK.../.history -type f -printf '%T@ %p
' | sort -nr | cut -f2- > /somewhe
|
How to remove specific directory names from path list |
You can do the following (treating the path as a string):
'http://my-cdn-path.com/' + '/'.join(i.split('/')[-4:]))
Or, using os.path:
'http://my-cdn-path.com/' + '/'.join(os.path.abspath(i).split(os.sep)[-4:])
|
How to get full directory path of the file on browse in Firefox and IE using javascript? |
You do not need full file path from the client browser since it will have
nothing to do with the uploaded destination on the server. Many browsers
restrict full local path availability due to security concerns. IE will
show full path if you add site to "Trusted Sites", but again there is no
need for that.
|
Function for getting full directory structure |
You don't have to check. os.walk always returns a tuple in a form:
(current_directory, directory_list, files_list)
So you always know that the second element of the tuple is a list of
directories found in the current_directory, and that the third element is a
list of files found in the current_directory.
You should use os.walk in that manner:
for current, directories, files in os.walk(path):
# do your stuff...
|
get filenames from a directory without full path |
Use Path.GetFileName which returns file name and extension from full path
var files = Directory.GetFiles(directory).Select(f =>
Path.GetFileName(f));
Or even
var files = Directory.GetFiles(directory).Select(Path.GetFileName);
|
Find the root directory without full path in C# |
If the subfolder is under the same root as you application you can use
Directory.GetDirectoryRoot
See:
http://msdn.microsoft.com/en-us/library/system.io.directory.getdirectoryroot.aspx
|
Getting just the current directory without the full path in python |
Like this:
os.path.split(os.getcwd())[1]
Although os.path.split returns a tuple, you don't need to unpack it. You
can simply select the item that you need and ignore the one that you don't
need.
|
Directory.GetFiles() returns full path |
You can use Path.GetFileName:
string[] ImageNames = Directory.GetFiles(path)
.Select(p =>
Path.GetFileName(p)).ToArray();
This will produce a list with only the names of the files.
|
Xtend how to get full path of current working directory |
Yes, Java has a File class. You can create one by calling this constructor
which takes a String. Then you can call getAbsolutePath() on it. You can
call it like this:
package com.sandbox;
import java.io.File;
public class Sandbox {
public static void main(String[] args) {
File file = new File("relative path");
String absolutePathString = file.getAbsolutePath();
}
}
|
How do I update a link with a full directory path with jQuery URI? |
OK, I figured this out with a whole bunch more googling. The function that
works for what I needed is:
var handler = function (data, href, target) {
// Insert data into div
$( '#' + target ).html(data);
console.log("href = ", href);
// Convert relative URLs in #right to include directory
var base_path = URI(href).directory();
//var base_path = uri.directory() + '/';
console.log(base_path);
$('#right a:uri(is: relative)').each(function() {
var cur_href = $(this).attr("href");
$(this).attr("href", base_path+"/"+cur_href);
});
};
The change is to use .each to allow an anonymous function to do the work on
each relative link.
|
how to get the full path of sdcard directory in android phonegap with javascript? |
Please try this code..
There is window.appRootDir.fullPath through you get full path but before
that you must use dirReady();
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>
Insert title here
</title>
<script type="text/javascript"
src="lib/android/cordova-1.7.0.js">
</script>
<script type="text/javascript">
window.appRootDirName = "download_test";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("device is ready");
|
Probing Path - How to Force Calls to Remain Within a Directory Structure |
Further investigation has revealed that this was not a reflection or
assembly loading problem. The problems I was experiencing was due to build
issues inside the assemblies I was reflecting on. The errors were obscure
and it made the problem look like something it wasn't. Thanks to SWeko for
noting to look into the inner exceptions. That comment helped a lot!!
|
List of files from SVN with full path |
Maybe the following command line already helps you. It removes all lines
from the output, that end with the character '/', i.e. it removes
directories.
svn ls -R | grep -v '/$'
If you need more control, I recommend using the option --xml and processing
the output with a script. For example, the following python script prints
the full pathname of all files, when invoked with svn ls -R --xml |
/tmp/filter.pz:
#! /usr/bin/env python3
import sys, lxml.etree
document = lxml.etree.parse(sys.stdin.buffer)
for entry in document.xpath('//entry[@kind="file"]'):
print(entry.xpath('string(name)'))
|
C docs: help Doxygen recognize class structure |
Take a look at the Exclude series of tags in your configuration file.
Since your source is in the ./src/ directory, one option might be to use
one of the following:
Exclude a directory:
EXCLUDE = /src
Exclude a pattern of file names:
EXCLUDE_PATTERNS = *.c
These are off of the top of my head. You might have to add some path
information. I expect that using the first or both will produce output that
does not have any of the comments in your C files.
As a side note, do you think using a structure for the interface for your
'class' would meet your requirements?
|
Nested - display full path of structured list? |
Not quite what your after, but close. Try this:
<style>
ol { list-style-type:upper-latin; }
</style>
That will print your index item labels as letters.
If you wanted something like "1a...2a...2a.a" you'd have to use either
javascript / server side code to build up your list in a loop
programatically.
|
Bash script to grep through one file for a list names, then grep through a second file to match those names to get a lookup value |
awk -v search="$search_string" '$0 ~ search { gsub(/"/, "", $5);
print $1" "$5; }' "$filename"
|
while read line
do
result=$(awk -v search="$line" '$0 ~ search { print $3; } '
"$lookup_file");
# Do "something" with $result
done
|
php file search issue - not returning full path to file |
I was unfamiliar with the RecursiveDirectoryIterator function, so I decided
to check it out. Neat stuff! I wrote the following, it seems to do what you
want:
Method #1 ...
$path = $_SERVER['DOCUMENT_ROOT'];
$search = rawurldecode($_GET['f']);
$it = new RecursiveDirectoryIterator( $path );
foreach (new RecursiveIteratorIterator($it) as $file){
$pathfile = str_replace($path,'',$file);
if (strpos($pathfile, $search) !== false) {
echo 'file = '. basename($file) .'<br>';
echo 'link = http://www.mydomain.com'. $pathfile .'<br>';
echo 'size = '. round(filesize($file)/1024,2) .'
KB<br><br>';
}
}
You run it via http://www.mydomain.com/search.php?f=whatever ... assuming
you name the script search.php, this will find any file containing
|
open file by its full path |
Actually that code works as it is – at least in the current version,
C++11.
Before that, you need to convert the string to a C-style string:
ifstream file(address.c_str());
Although you should beware of spaces in the file’s path as CapelliC
mentioned in his (now-deleted) answer; in order to ensure that the user can
enter paths with spaces (such as “~/some file.txt”), use std::getline
instead of the stream operator:
getline(cin, address);
|
Git whatchanged - how to see full path of a file with changes |
whatchanged can take the same commands as diff-tree and rev-list which it
uses internally. you can try adding --stat=200 --stat-name-width=150 to
your command from diff-tree which will adjust the width of the stats column
to 200, and the file name to 150 which should give you all of it, or you
can use --pretty to adjust the log output to your needs in other ways
|
Get full path from an opened file - C# |
The only way for you to find open file handles is to use the
NtQuerySystemInformation call. Here is a project that has this done as an
explorer context menu. In this guy's case, he looks for files open in a
specific folder.
You would then have to match the file name to the file you have in your
print job.
By the way, this is not C# but you can wrap and call the same calls he is
using. The rest is really up to you to figure out. ;)
|
Get full path and long file name from short file name |
@echo off
setlocal
rem this need to be a short name to avoid collisions with dir command
bellow
cd C:BALBAL~1BLBALB~1
set "curr_dir=%cd%"
set "full_path="
:repeat
for /f "delims=" %%f in ('for %%d in ^(.^) do @dir /a:d /n /b
"..*%%~snd"') do (
set "full_path=%%f\%full_path%"
)
cd ..
if ":" NEQ "%cd:~-2%" (
goto :repeat
) else (
set "full_path=%cd%%full_path%"
)
echo --%full_path%--
cd %curr_dir%
endlocal
The path is hardcoded at the beginning but you can change it or
parameterizied it.As you can easy get the full name of a file here is only
a solution for directories.
EDIT
now works for file and directory and a parameter can be passed:
@echo off
rem ---------------------------------------------
rem ---------------------- TESTS ----------------
rem --------------
|
how to open a file by its full path given by user? |
Your application is failing because you aren't properly handling spaces in
the filename.
Try this instead of cin >> address;:
getline(cin,address);
See this question for the difference between cin and getline.
|
Is there any way to find out full file path from another process? |
If notepad received document's file name from command line, use
GetCommandLine function.
|
Any way to not be required to use full path to file in Xcode? [C/C++] |
The problem isn't that "XCode" doesn't accept a relative path. The problem
is that your code has a different current working directory than you think.
You can, as the comment says, use chdir to get to a place where your file
is, or use a relative path that takes into account the currend working
directory (you can use getcwd() to get the current working directory).
When you are using gcc or g++ on the command line, you are in control over
what directory the final application runs in.
|
Full name of uploaded path with file uploader |
The method System.Drawing.Image.FromFile expect the file to be presented
on the server, but when you use _uploadImageFile.PostedFile.FileName this
is the file which was picked up on the client. So obviously
System.Drawing.Image.FromFile(); will not find it because you pass it a
client path.
I would recomment you to use other methods like Image.FromStream(Stream);,
you can pass input file stream and you can get the image.
|
Get full path image into input file |
MOZILLA DEVELOPER NETWORK show us an example to do that:
<input type="file" id="fileElem" multiple accept="image/*"
style="display:none" onchange="handleFiles(this.files)">
<a href="#" id="fileSelect">Select some files</a>
<div id="fileList">
<p>No files selected!</p>
</div>
<script>
window.URL = window.URL || window.webkitURL;
var fileSelect = document.getElementById("fileSelect"),
fileElem = document.getElementById("fileElem"),
fileList = document.getElementById("fileList");
fileSelect.addEventListener("click", function (e) {
if (fileElem) {
fileElem.click();
}
e.preventDefault(); // prevent navigation to "#"
}, false);
function handleFiles(files) {
if (!files.length) {
fileList.innerHTML = "<p>No files
|
Can't take uploaded image file full path in JSP |
In Internet Expolorer it works more-or-less by accident, because you're
probably running the application on the same machine as your accessing it
from. Internet Explorer sends the real filename along when you upload a
file, for example C:UsersAdministratorDesktopImage.jpg. Your web
application runs on the same machine so it can read that file from disk.
However, Chrome and Firefox don't want to expose the full path names from
your client to the application, and they use the fakepathImage.jpg. There
is no such file on your disk, and that's why the web appliaction can't read
the image.
What you should do is extract the different parts from the request, find
the part that contains the uploaded file, and read the data from the
request (instead of from file). The good news is that you don't h
|
How to parse xml-file with directory structure |
Do you create this file-schema on your own? If you can change it, i would
definitly.
Try to make something like this:
<?xml version="1.0" encoding="UTF-8"?>
<Directory id="regular">
<Directory id="case_10_some_description">
<Directory id="english">
<Directory id="images">
<file id="screenshot_1.png"/>
<file id="screenshot_2.png"/>
<file id="screenshot_3.png"/>
<file id="screenshot_4.png"/>
<file id="screenshot_5.png"/>
<file id="screenshot_6.png"/>
</Directory>
</Directory>
</Directory>
<Directory id="case_12_some_description">
<Directory id="e
|
How to change file and directory names with find? |
First create a shell script like this:
#!/bin/bash
dir=$(dirname "$1")
mv "$1" "$dir/$2"
Then this find should work for you:
find . -name "old_name" -exec ./ren '{}' 'new_name' ;
This will find file with the name old_name from the current dir in all
subdir and rename them to new_name
|
How can I quickly reference a file from git status without the full path |
There isn't a way to do this on the CLI (unless you wrote it yourself).
Those sorts of use cases are what GUIs excel at. Try a bunch until you
find one you like.
|
filesystem directory_iterator not returning full file path |
For full path you need to use start->path().directory_string()
directory_iterator end;
for (directory_iterator start(p);
start != end;
++start)
{
if (is_directory(start->status()))
{
//A directory
}
if (is_regular_file(start->status()))
{
std::cout << start->path().directory_string()<< "
";
}
}
Play around with following based on your need, refer boost docs for more
details, however names their suggest all.
start->path().branch_path();
start->path().directory_string();
start->path().file_string();
start->path().root_path();
start->path().parent_path();
start->path().string();
start->path().basename();
start->path().filename();
start->path().root_name();
start->path().relative_path(
|
maven assembly, avoiding full path in zip file? |
First i would suggest to create dist-packaging module which contains the
resulting package. Furthermore it sounds like your assembly-descriptor for
creating the final archive which contains the zip files of others is wrong.
<id>proj1-assembly</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
But you must be aware that you have to maintain the dependencies in
|
move up and down in directory structure to access file |
Since currentDir is a DirectoryInfo currentDir.Parent gives you the
DirectoryInfo of the parent directory including the full-path and all other
informations of DirectoryInfo.
You have to use it's FullName property:
string fullPath = parent.FullName;
If you want to find the file:
FileInfo[] files = currentDir.Parent.Parent.GetFiles("FileName.txt",
System.IO.SearchOption.TopDirectoryOnly);
|
Editing file names and saving to new directory in python |
If I'am not wrong, you are only opening the file and then you are
immediately closing it again?
With out any writing to the file it is surely empty.
Have a look here:
http://docs.python.org/2/library/shutil.html
shutil.copyfile(src, dst) ;)
|
find and replace a word with another in all file names of a directory |
Use find with the -exec option to call rename on every file and
subdirectory containing "owner" in its name:
find path/to/my/directory/ -depth -name "*owner*" -exec /usr/bin/rename
owner user {} +
If you don't have rename, you can use a mv command with bash parameter
expansion:
find path/to/my/directory/ -depth -name "*owner*" -exec
bash -c 'mv "{}" $(old="{}"; new="${old##*/}"; echo
"${old%/*}/${new/owner/user}")' ;
bash -c '...' invokes the bash shell on the one-liner surrounded by
single-quotes. The one-liner acts as a mv command that renames all
occurrences of "owner" in the basename of the matching
filename/subdirectory to "user".
Specifically, find substitutes every {} after the -exec with the matching
file/subdirectory's pathname. Here mv accepts two arguments; the first i
|
How to get the full Path of the file upload control in a string variable in asp .net? |
It sounds like you're actually asking for the original path to the file on
the client machine.
This is (a) useless (it's on a different computer) and (b) impossible to
get (the browser doesn't tell you it).
What are you trying to do?
|
Extracting zip file on host by PHP destroys directory structure |
PHP does not actually provide a function that extracts a ZIP including its
directory structure. I found the following code in a user comment in the
manual:
function unzip($zipfile)
{
$zip = zip_open($zipfile);
while ($zip_entry = zip_read($zip)) {
zip_entry_open($zip, $zip_entry);
if (substr(zip_entry_name($zip_entry), -1) == '/') {
$zdir = substr(zip_entry_name($zip_entry), 0, -1);
if (file_exists($zdir)) {
trigger_error('Directory "<b>' . $zdir . '</b>"
exists', E_USER_ERROR);
return false;
}
mkdir($zdir);
}
else {
$name = zip_entry_name($zip_entry);
if (file_exists($name)) {
trigger_error('File "<b>' . $name
|
How to set hierarchical structure values through the Web API using friendly names and without exposing the structure itself to the user? |
If you collection elements had aliases then you would be able to use a
natural URI path structure, which is intended to map hierarchies.
<ROOT>
<COLLECTION_ELEMENT> //alias = foo
<SIMPLE_ELEMENT /> // alias = nail
<SIMPLE_ELEMENT /> // alias = hammer
<COLLECTION_ELEMENT> /alias = bar
<SIMPLE_ELEMENT /> // red
<SIMPLE_ELEMENT /> // green
</COLLECTION_ELEMENT>
</COLLECTION_ELEMENT>
....
<COLLECTION_ELEMENT> //baz
<SIMPLE_ELEMENT /> // alias = nail
<SIMPLE_ELEMENT /> // alias = hammer
<COLLECTION_ELEMENT> //blunk
<SIMPLE_ELEMENT /> // red
<SIMPLE_ELEMENT /> // green
|
Allowing punctuation characters in directory and file names in bash |
Always quote your variable substitutions. I.e. not cp $source $target, but
cp "$source" "$target". This way they won't be subject to word splitting
and pathname expansion.
Specify "--" before positional arguments to file operation commands. I.e.
not cp "$source" "$target", but cp -- "$source" "$target". This prevents
interpreting file names starting with dash as options.
And yes, "/" is not a valid character for file/directory names.
|