How can I get the file names and directory names in a directory using Dart? This question shows how to get the absolute paths but I only want the actual file/directory names. This code gives absolute paths:
Directory('/').list().map((entry) => entry.path).toList();
Is there a way other than parsing entry.path to just get the last component of the path? I would have thought the FileSystemEntity had a name field but it doesn't. Am I missing something?
You can map the entry.uri and then get the last segment of it:
final files = Directory('/')
.listSync()
.map((e) => e.uri.pathSegments.last)
.toList();
print(files);
Related
For clarification, I'm just talking about relative file paths that also include a directory or filename in them, for example ../../some_directory/my_file.ext. I understand that ./ is current directory and ../ is parent directory and that on their own they are in fact relative paths.
But, I am wondering in the context of a relative path that includes directory/directories and possibly the filename and extension after the dots and slashes, what are the dots and slashes known as? The "directory referrer", "path adjuster", etc.?
I'd like to know, because I have a function that creates this portion of the relative path based on target folder's depth (which I am calling frequently throughout my app) and I'd like to give it a name that will help make my code more legible to others. Right now I'm calling them dotSlashes and the function is called prependDotSlashes.
I've googled and stackoverflowed around, but didn't find a definitive name.
If anybody knows the industry-standard name for this portion of relative file paths, I would be curious to know it.
Man, I know the dot as "current directory", and the slashes as directory separator.
The double dots (..) is know as parent directory.
Relative path is a path relative to where you are. Eg: If you are in the /etc path, then, the ./apache path is a relative to that /etc. A full string path (from the root) is named absolute path. So, for example:
../../../../ => Relative path
/home/user/Documents/doc1 => absolute path
./Document/doc1 => relative path from home
I am passing in an wilcard match string as gs://dev-test/dev_decisions-2018-11-13*/. And i am passing to TextIO as below.
p.apply(TextIO.read().from(options.getLocalDate()))
Now i want to read all folders from the bucket named dev-test and filter and only read files from the latest folder. Each folder has a name with timestamp appended to it.
I am new to dataflow and not sure how would I go about doing this.
Looking at the JavaDoc here it seems as though we can code:
String folder = // The GS path to the latest/desired folder.
PCollection<String> myPcollection = p.apply(TextIO.Read.from(folder+"/*")
The resulting PCollection will thus contain all the text lines from all the files in the specified folder.
Assuming you can have multiple folders in the same bucket with the same date prefix/suffix as for example "data-2018-12-18_part1", "data-2018-12-18_part2" etc, the following will work. Its a python example but it works for Java as well. You will just need to get the date formatted as per your folder name and construct the path accordingly.
# defining the input path pattern
input = 'gs://MYBUCKET/data-' + datetime.datetime.today().strftime('%Y-%m-%d') + '*\*'
(p
| 'ReadFile' >> beam.io.ReadFromText(input)
...
...
it will read all the files from all the folders matching the pattern
If you know that the most recent folder will always be today's date, you could use a literal string as in Tanveer's answer. If you don't know that and need to filter the actual folder names for the most recent date, I think you'll need to use FileIO.match to read file and directory names, and then collect them all to one node in order to do figure out which is the most recent folder, then pass that folder name into TextIO.read().from().
The filtering might look something like:
ReduceByKey.of(FileIO.match("mypath"))
.keyBy(e -> 1) // constant key to get everything to one node
.valueBy(e -> e)
.reduceBy(s -> ???) // your code for finding the newest folder goes here
.windowBy(new GlobalWindows())
.triggeredBy(AfterWatermark.pastEndOfWindow())
.discardingFiredPanes()
.output()
i'm trying to get full path of the selected Folder. Only thing i was able to find is this
cxShellTreeView2.Folders[Index].PathName, but i don't know how to get this Index.
Is it the path of the map?
self.cxShellTreeView2.Path;
or
self.cxShellTreeView2.AbsolutePath;
Description TcxCustomShellTreeView.AbsolutePath
Use the AbsolutePath property to specify the path to the required shell node. Folder path can be specified in two ways:
as a full path, including all sequence of folders, required for accessing the required shell node from the shell root.
Description TcxCustomShellTreeView.Path
Use the Path property to specify the path to the current shell item. Folder path can be specified in two ways:
as a full path, including all sequence of folders, required for accessing the required shell item from the shell root.
The full path of a selected folder is returned by cxShellTreeView1.AbsolutePath.
I have a .csv file with the following format:
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
I want to copy what's on column #1 in my CSV from Location A to Location B, then rename the file on Location B with the content of the column #2 in my CSV.
This is what I have done so far, the copying works but the renaming seems doesn't really happen:
For /F "tokens=1* delims=," %%i in (myCSV.csv) do (copy "%%i" "C:/myFolder" && rename "C:/myFolder/%%~nxi" "%%j")
Thanks in advance.
This answer used to contain my wrong suggestion from comments:
When the second column isn't a full pathname, but just a file name, rename "C:/myFolder/%%~nxi" "%%j" takes its destination argument as a path relative to current directory, not to the source directory.
I thought the problem should be solved by providing a full path name in the second argument of rename as well:
rename "C:/myFolder/%%~nxi" "C:/myFolder/%%j"
But no: the full path name is actually invalid in the destination argument for rename. The solution of cding to the target directory first and renaming without folder names in either argument turned out to work. I think that replacing forward slashes with backslashes in the first argument (leaving the second without the folder name) would help too: in my tests on Windows XP, rename failed with "file not found" when a source folder path contained forward slashes, and worked for backslashes.
For me, a path was always something that "walks the way to something", but without the "something".
Like a chicken following bread crumbs until it hits the target. But the target is not part of the path. That's what I believe.
So, example: C:/foo/bar = the path. C:/foo/bar/something.html = Path and the "Target".
Can someone tell me what are the correct terms here? How do I call such a path with file?
"Full path"?
"Full qualified path"?
"Path with File Name"? (not precise! "Path with File Name and Extension" ... way too long)
Sure there's a special name for this. Want to know! :)
Nice chicken example... I think you mean absolute path
but, It doesn't matter what the path points to, be it a directory, file, device or otherwise
Wikipedia says:
A path, the general form of a filename or of a directory name, specifies a unique location in a file system.
It doesn't even require an extension, as other mechanisms work out the filetype.
/foo/bar/file.txt = Absolute path
/foo/bar = An absolute path to a directory
../foo = A relative path to a directory, from current directory
./file.txt = A relative path to a file, from current directory (Unix)
file.txt = A relative path too
Also
Systems can use either absolute or relative paths. A full path or absolute path is a path that points to the same location on one file system regardless of the working directory or combined paths. It is usually written in reference to a root directory.
The distinction between files and directories isn't catered for with a path. A path is always a path to something, be it a file or a directory:
/a/b/c is the path to c regardless of what type (file, directory, device) the end point is.
Also checkout basenames
basename is a standard UNIX computer program, when basename is given a pathname, it will delete any prefix up to the last slash ('/') character and return the result. basename is described in the Single UNIX Specification and is primarily used in shell scripts.
From LINFO
A path is the address of an object
(i.e., file, directory or link) on a
filesystem.
So, unfortunately, you are looking for a specificity of terms that isn't part of the accepted usage. You'll have to define your own terms.
I beleive it is called "full name" regardless of the "target" type, just because everything in UNIX is a file, including a directory. So if a foo is the target (as you called it), then foo is the name, while C:\Direcotry\foo or /usr/bin/foo is the foo's full name.
i have been thinking about it too lately, because in Everything, the path do not include the "target" itself. but when i search in Wikipedia, it say that the target is included.
in your example, you have implicitly assume that there is "only one" target at the end of the bread crumbs. and someone tell the chicken to follow the bread crumbs and then it can get to the target.
what if there are 2 objects in the end? if someone did not tell which one is the target, e.g. include the target itself in the path, the chicken will never know its target.
you can also think like this: for a path which include the file, the target is not the file, but its content or some other imformation of the file.
back to the file system, assume there is several file in a folder. if file name is not included in its path, then they all have same path and you can not find a specific file through its path alone.