GetFileAttributes in NTFS - ntfs

i want to use a windows API to check a file/directory is hidden or not .
GetFileAttributes may the best choice. but when i check the FAT "C:\", it's return 0x10.it's looks work well. but in NTFS "C:\" it's return 0x16, maybe it's show that "C:\"'S Attribute is "system", "directory",and "hidden". so the problem is here, why it's return hidden? in fact it's not hidden.
would you please give me another API to check the windows file system's file/directory is hidden or not?
thanks a lot.

GetFileAttributes has a BIG BUG, to see it try this simple code:
ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.MyNonExistantFile'))));
It shows that GetFileAttributes has return 32 in decimal (since file does not exists it is a BUG, correct return value must be -1).
Also you can try it with this:
CreateDir('C:\.Anything');
ShowMessage(IntToStr(GetFileAttributes(PChar('C:\.Anything\MyNonExistantFile.TXT'))));
It is related with files and directories starting by a period (.) symbol.
Note: FileExists also returns true in that situations (and file does not exists).

Related

How to overcome the 126 character restriction for filepaths on 'LoadPicure' that exists since Windows update 1903

Existing VBA add-ins have started to fall over on this line if the filepath is longer than 126 characters. Shorter file paths are not an option, unfortunately.
Set ImageControl.Picture = LoadPicture (FilepathLongerThan126CharsErrors)
Runtime Error '75' (File/Path access error)
The error does not occur if the file path is shortened to 125 characters.
We tried to set the RegKey HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled to (1) but to no avail.
Machines that have not yet had the Windows 10 1903 update don't seem to be affected. The problem occurs mainly on Surface Laptops so far but also a few other PCs.
Possible workarounds are listed below:
You may copy existing images into the AppData subfolder to make a path shortened.
Use the ShortPath property which returns the short path used by programs that require the earlier 8.3 file naming convention.
Yes, thank you Tim and Eugene. I am now working with the 'ShortPath'.
However, the problem is still that the behaviour of this method has changed with the Windows 1903 update (from allowing 260 characters to now 126). There must be quite a few people out there scratching their heads why their codes are failing seemingly at random.
Thanks anyway. I'll put an error trap to feed the ShortPath through when needed.

How do I set a variable value in emacs org mode?

The org-mode tutorial often talks about setting the value of a variable to change the behavior of the mode. For example, in this org-mode tutorial:
This warning is deactivated if the task gets scheduled and you set org-agenda-skip-deadline-prewarning-if-scheduled to t.
I have been searching for a while but it looks like knowing how to set an emacs variable value is an assumed knowledge in many tutorials.
Could someone please educate me how and where to set variables in the org-mode? Is it set in the .emacs file or in each org file? Do these questions even make sense or am I missing some important concepts?
Thank you very much!
With Customize
If you want some help about a variable, you can use C-h v then Emacs will ask you the variable name.
There if you enter org-agenda-skip-deadline-prewarning-if-scheduled you will see a buffer with the variable
description. At the end you will see a clickable customize. Click it and you will see an interactive buffer from which you can change variable value (saved in your .emacs file).
Note: you can directly use M-x customize-option + variable name
With setq lisp function:
Another way is to directly use this:
(setq org-agenda-skip-deadline-prewarning-if-scheduled t)
in your .emacs file or
in the *scratch* buffer, then M-x eval-buffer
(Your modification is immediate but not saved.)

nio2: detect '..' and suchlike elements

I wish to use a string handed to me as a parameter as an element of a pathname. I do not wish to be troubled with 'Little Bobby Tables'. That is, I don't want '..' to be acceptable. I want this to work with an arbitrary NIO2 FileSystem, so just looking for the string .. isn't good enough. I can make some checks, such as !path.isAbsolute(), and path.getNameCount() == 1 to filter out other problem cases, but can I do anything other than pass it to resolve and look for the wrong name count to tell if it has the semantics of ..?
toRealPath()
Is mostly the answer. The method on a path after resolved gives you
the real path after resolving parent (e.g. "..") and links.
You can then use root.startsWith( path ) to quickly check that it is in your subtree.
But: Works only for existing files.

gulp-newer vs gulp-changed

What're the differences between them?
gulp-newer:
gulp.src(imgSrc)
.pipe(newer(imgDest))
.pipe(imagemin())
.pipe(gulp.dest(imgDest));
gulp-changed:
gulp.src(SRC)
.pipe(changed(DEST))
// ngmin will only get the files that
// changed since the last time it was run
.pipe(ngmin())
.pipe(gulp.dest(DEST));
It seems gulp-changed is more powerful, because it provides an option
hasChanged: changed.compareLastModifiedTime
I hope it's not too late to answer this question. I have had to evaluated both of them at a source-code level for a recent project, and here is my take.
gulp-newer
At the core, this plugin compares the source and dest file's modified time (see node API) to decide whether the source file is newer than the dest file or if there is no dest file at all. Here is the related code in the plugin:
var newer = !destFileStats || srcFile.stat.mtime > destFileStats.mtime;
gulp-changed
This plugin by default also uses a file's modified time to decide which to pass through the stream
function compareLastModifiedTime(stream, cb, sourceFile, targetPath) {}
but it goes one step further by offering an option to compare the file's content SHA1 hash:
function compareSha1Digest(stream, cb, sourceFile, targetPath) {}
This information is nicely documented.
Conclusion
So theoretically speaking, if you use gulp-changed's default hasChanged: changed.compareLastModifiedTime, each plugin is relatively as fast as the other. If you use gulp-changed's hasChanged: changed.compareSha1Digest, it's reasonable to expect gulp-changed to be a bit slower because it does create a SHA1 hash of the file content. I didn't benchmark but I'm also interested in seeing some number.
Which to choose
gulp-changed, purely because of the developer behind it (sindresorhus). If one day this awesome man decides that he will stop supporting his gulp plugins, I think I will stop using gulp altogether.
Joking aside, though, gulp-changed's source code is gulp-y, while gulp-newer's source reads pretty much like just another node module's source with lots of promises. So another +1 for gulp-changed :)
HUGE EDIT
Gulp-changed only works with 1:1 source:dest mapping. If you need many:1, e.g. when using with gulp concat, choose gulp-newer instead.
May I suggest gulp-newy in which you can manipulate the path and filename in your own function. Then, just use the function as the callback to the newy(). This gives you complete control of the files you would like to compare.
This will allow 1:1 or many to 1 compares.
newy(function(projectDir, srcFile, absSrcFile) {
// do whatever you want to here.
// construct your absolute path, change filename suffix, etc.
// then return /foo/bar/filename.suffix as the file to compare against
}
In order to answer this question you will have to compare both plugins source code.
Seems that gulp-changed has more options as you have said, more used (it was downloading more time) and more contributors, thus, it could be more updated and refactored, as it was being used more.
Something that can make a difference, due to them documentation.
On the example, for gulp-newer, its used like this:
gulp.task('default', function() {
gulp.watch(imgSrc, ['images']);
});
Thus, seems that once this task is running, it will only notice files that are changing while you are using this plugin.
On gulp-changed, they say: "will only get the files that changed since the last time it was run". So, and I didnt try this on a working example, that gulp-changed proccess all files and then only the ones that have been changed since last execution, so seems it will always "look" at all files and internally (md5 hash? no clue, didnt check the source) decide whereas a file has changed since last execution. Do not need a watcher for that.
All this, was only reading their official documentation.
A "on the wild test" would be very welcomed !

Twisted.web File directory listing issues

I'm trying to use Twisted in a web-app, and I'm coming across an interesting issue. I'm very new to Twisted, so I'm not sure if I'm seeing a bug in Twisted, or if I just am not using it correctly.
Theoretically from the example, a File resource object can be use to both serve files from a directory, as well as provide the directory listing. So assuming I have the variables (port, reportsDir) defined elsewhere before the code snippet, I do the following:
rootResource = Resource()
rootResource.putChild("reports", File(reportsDir))
reactor.listenTCP(port, Site(rootResource))
reactor.run(installSignalHandlers=False)
Now, when I access '/reports' on my host I get a message "Request did not return bytes" in my browser with a bunch of stuff that was obviously produced by twisted, but also contains a print of a u'.....' string literal, which in fact has the directory listing in it. So the DirectoryLister is obviously creating the listing HTML, but it isn't seeing as valid by something in Twisted. It doesn't seem to like the unicode string; which was in fact produced by Twisted itself.
Do I need to set some other configuration item to get it to convert the unicode string to the necessary bytes object (or whatever), or some other approach?
Many thanks,
-D
Well, it seems like the issue is that Python will promote any string to unicode if any source string on a format was unicode. In my case, "reportsDir" was unicode because it came from a XML file, and that set it down the error path.
Changing the above line:
rootResource.putChild("reports", File(reportsDir))
to:
rootResource.putChild("reports", File(reportsDir.encode('ascii', 'ignore')))
fixed the issue. I would however suggest that the Twisted developers do a check for unicode in the constructor for File, or in the DirectoryLister simply check for unicode, and if it is then return the ascii-encoded version.