This question already has an answer here:
How to set the current working directory in Dart?
(1 answer)
Closed 5 years ago.
I want to know what the current directory is. I don't want to shell out to run pwd. Is there an easy way to do this in Dart?
and also,
Is there a way, put name of directory into a string?
Re the current directory, from the documentation from the Directory class in dart:io (emphasis added).
In addition to being used as an instance to access the file system,
Directory has a number of static properties, such as systemTemp, which
gets the system's temporary directory, and the getter and setter
current, which you can use to access or change the current directory.
To get the name of a Directory as a string just use toString(), or perhaps the path property.
Related
This question already has answers here:
How to read file from an imported library
(2 answers)
Closed 6 years ago.
Suppose the following files:
lib/src/program.dart
lib/src/file.txt
I want to read file.txt contents from program.dart using a library that contains readingFunction(path):
//program.dart
String fileContents = library.readingFunction("./file.txt");
This throws an error, because the current path is the one in which execution was launched (or the package path if executing with pub run).
How could I achieve the reading with relative path instead of being forced to use "./lib/src/file.txt" path?
Use the Resource package.
It allows you to read files that are embedded in packages. Files are specified with a special URL that looks like package:package_name/path/to/file.txt (same as used in import statements).
I'm planning to do a program with Lua that will first of all read specific files
and get information from those files. So my first question is whats the "my documents" path name? I have searched a lot of places, but I'm unable to find anything. My second question is how can I use the first four letters of a file name to see which one is the newest made?
Finding the files in "my documents" then find the newest created file and read it.
The reading part shouldn't be a problem, but navigating to "my documents" and finding the newest created file in a folder.
For your first question, depends how robust you want your script to be. You could use Lua's builtin os.getenv() to get a variety of environment vars related to user, such as USERNAME, USERPROFILE, HOMEDRIVE, HOMEPATH. Example:
username = os.getenv('USERNAME')
dir = 'C:\\users\\' .. username .. '\\Documents'
For the second question, there is no builtin mechanism in Windows to have the file creation or modification timestamp as part of the filename. You could read the creation or modification timestamp, via a C extension you create or using an existing Lua library like lfs. Or you could read the contents of a folder and parse the filenames if they were named according to the pattern you mention. Again there is nothing built into Lua to do this, you would either use os.execute() or lfs or, again, your own C extension module, or combinations of these.
This question already has answers here:
How to create directories recursively in ruby?
(6 answers)
Closed 8 years ago.
i have built this little app that generates a excel document. i am trying to make a directory to stick it in. these documents are built differently depending on the #agency that people select. so i made this method to return the path since the path is used in a few places.
def reportsheet_dir
file_path = "#{Rails.root}/public/reportsheets/#{#agency.downcase.gsub("_","")}"
end
At the beginning of the method that creates the document i have this method that supposedly builds directories but it doest seem to be working
Dir.mkdir(reportsheet_dir) unless File.exists?(reportsheet_dir)
I keep getting. this
and i get
Errno::ENOENT at /addons/agency_report_builders
No such file or directory -/Users/fortknokx/Work/toolkit/public/reportsheets/empowerlogicbuilder
I think its because its multiple levels deep?? since public/reportsheets/agency_name/file_name has to be made. i could just go and make the folders but i would like to just make the dir each time because new agencies could be made at any time. is this possible?
Have a look at FileUtils.mkdir_p()
http://ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-mkdir_p
It will recursively create non-existent directories. Dir.mkdir will not.
I'd like to get a file last modified time in Delphi.
Normally something like FileAge() would do the trick, only the problem is: if I overwrite *File A* with File B using CopyFile, File A's modified date is not updated with current overwrite time as it should(?)
I get that: CopyFile also copy file attributes, but I really need to get the modified date that also works when a file is overwritten.
Is there such function? My whole application relies on modification time to decide whether or not I should proceed with files!
EDIT Just to clarify: I'm only monitoring the files. It's not my application who's modifying them.
The documentation for CopyFile says:
File attributes for the existing file are copied to the new file.
Which means that you cannot use base your program on the last modified attribute of the file, or indeed any attribute of the file. Indeed there are all sorts of ways for the last modified attribute of the file to change. It can in fact go backwards in time.
Instead I suggest that you use ReadDirectoryChangesW to keep track of modifications. That will allow you to receive notifications whenever a file is modified. You can write your program in an event based manner based on the ReadDirectoryChangesW API.
If you can't use ReadDirectoryChangesW and the file attributes, then you'll have to base your decisions on the contents of the file.
What is the difference between:
include("./somepath/class.php");
and
include("somepath/class.php");
There shouldn't be any difference, directory wise, since the former assumes relative directory structure. The only potential pitfall could be if "somepath" were actually a command to be run - some users expect to type a command for a local script file and assume it should run, when you actually have to run "./somepath" to invoke it. This, of course, only pertains to commands not on your $PATH.
I don't see any difference. "." means current directory.
. refers to the current working directory.
Sometimes you want to specify explicitly that what you want is in the current working directory, and that it is not from something in your path variable for example.
For example in PHP "somepath/somefile" is appended after paths specified in include_dir (for example: /home/var/; /home/bin/ ....) directive.
The second variant is more specific it says: search in current directory!