How to get file name when file change is observed via watch_file - file

I am currently facing an issue which I don't know how to fix. I got the following Julia code:
while true
print(watch_file("test"))
end
So this should get me all the file changes in the directory named "test". At least on windows.
Now thats all well and good, and it kinda works, at least for creating a file or moving a file to that directory. This is an example of what I get:
("New Textfile.txt",Base.FileEvent(true,false,false))
But when I delete or rename that file, I don't get the filename of the file deleted or renamed.
("",Base.FileEvent(true,false,false))
Is there a different method/function I can get the filename with, even when the file is deleted or renamed? Or even better, a way that archives this and is cross-platform-compatible? Any help appreciated.
EDIT: If you could give me an alternative that supports recursive monitoring, that would be even better.

In Linux, Julia 0.4.5 and 0.4.3 watch_file returns file name always. It is a very platform-dependent feature (like in Node.js https://nodejs.org/api/fs.html#fs_caveats) and only manual polling can be truly platform-independent solution.

Related

Update file across multiple folder locations?

I need something that can copy a specified file any and everywhere on my drive (or computer) where that file already exists; i.e. update a file. I tried to search this site, in case I'm not the first, and found this:
CMD command line: copy file to multiple locations at the same time
But not quite the same.
Example:
Say I have a file called CurrentList.txt, and I have copies of it all over my hard drive.  But then I change it and I want all the copies to update.  So I want to copy the newer one over all the others.  It could 'copy if newer', but generally I know it's newer, so it could also just find every instance and copy over it.
I was originally going to use some kind of .bat file that would have to iterate over every folder seeking the file in question, but my batch file programming is limited/rusty.  Then I looked to see if xcopy could do it, but I don't think so...
For how I will use it most, I generally know where those files are going to be, so it actually might be as good or better if I could specify it to (using example), "copy CurrentList.txt, overwriting all other copies wherever found in the C:\Lists folder and all subfolders".
I would really like to be able to have it in a context menu, so I could (from a file explorer) right click on a file or selected files and choose the option to distribute it.
Thanks in advance for any ideas.
Use the "replace" command...
replace CurrentList.txt C:\Lists /s

Rename code in c have a error

i want to move a file from a directory to anther directory with C Coding.
I search and find rename(); function , but when working it doesnt work and have a error:
my code:
#include <stdio.h>
int main() {
if(rename("/root/tmpfile.php", "/home/check-tmp.php"))
perror( NULL );
}
the code well compiled but when running this code showing this error:
Invalid cross-device link
How to move a file from a directory to anther directory without using System for fopen?
Aslo , i finded many codes and ways to do it but doesnt working all codes.
Please say me a way and make sure it will work
Thanks.
Many aspects of the behavior of `rename' are inherently platform-dependent: The rename operation might not be able to move a file from one file system to another , it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists.
In other words, your system does not support rename files cross different partitions (your root partition and your home partition are different.)
So the solution is when it fails, copy the file to the destination and delete the original.
The rename call can only rename and move files within a single disk partition. The error "cross-device link" indicates that you attempted to move a file from one partition to another. (If you were on a Windows system, you can imagine if you tried to rename a file from C: to D:.)
When you use the Unix mv command to move files, it first tries a rename, but if it fails in this way, it falls back and makes a new copy of the file in the new location, then deletes the original. That's what you would have to have your code do in this situation, too.
(Copying a file is easy enough, but there are plenty of library functions out there that will do it for you, and also take care of things like preserving the last-modified time and other file attributes.)

MoveFile and MoveFileEx works weird if filenames are the same in DOS 8.3 style

Ok, I have files named
ANIME~1.MKV~FNH47B97
ANIME~1.MKV
It is FULL filenames. It is named so by user.
And I want to rename the first one to ANIME~1.JPG. From OS point of view they seem to be the same files. And both MoveFile and MoveFileEx do nothing. They return OK and that's all.
Another weird situation is when we have, for example,
ANIME~2.MKV~FNH47B97
ANIME~3.MKV
And I want to rename the first one to ANIME~2.MKV
OS founds that it's the same as ANIME~3.MKV and still does nothing.
It depends on the number of files with "the same dos 8.3 names" in the folder
Any way to workaround it? May be some additional actions/flags needed?
To summarise the discussion in the comments as an approximate answer: MoveFile(Ex) works on the full filenames, though it can find the source file by its short name, the destination file is taken to be the long name.
This means that the destination filename should not clash with any long or short filenames of existing files. This is probably why your second test-case fails.
The first test-case probably fails for a similar reason; I've tried it with just those two files and MoveFile works with it.
It is possible to disable the generation of DOS style 8.3 shortnames, see KB121007, but I really don't recommend it. It can cause lots of issues, see for instance this article. Also, this is a decision that should be left to the system administrator, not any application.

NetBeans - replace in textfiles under a subdirectory

I have troubles with replacing file contents in my current project. I renamed a directory, and a lot of class names has been changed cause of this. A want to rename this classes with netbeans, but I cannot setup the file path pattern well.
The previous directory path was: Test/TestCase under Source Files, and the new path is Test/UnitTest. So I have to rename the TestCase word to UnitTest in my php files.
I tried with *.php, it works (of course it works...), but returns every php file in the project which contains that word, and I don't want to choose from circa half thousand files the right ones. The files of the unit test system could easily contain the TestCase word...
Tried out the following patterns, but they gave empty result:
Test\UnitTest\*.php
*Test\UnitTest\*.php
Test/UnitTest/*.php
*Test/UnitTest/*.php
Test/UnitTest/*
I have not a clue what I do wrong... I tried to search a tutorial for file search patterns but have found only regex patterns and those are definitely not what I was looking for. Can anybody help me?
Lol, I checked it again, and I realized, that I didn't notice the "scope" part last time. In that you can choose the current selection instead of the entire project. So the pattern matches only the file name, not the relative path of the file...
It was so obvious... This is an epic fail, I think I was too tired...

How do I view or rename a file with missing extension?

I have a strange file in my file system without the extension part. The filename is "15.". The weird thing is that it is not one of those without the dot part (like just "15"), but the one with the dot but no extension ("15.") -- it is literally an illegal filename in windows, and not sure how did it get created in the first place.
I know it is a text file and it is about 15KB in size; however, due to the weirdness in name, I can't open it with any application -- I've tried to open in notepad, wordpad, etc., have tried the 'type' command to spit it out on commans shell, tried to shell-open enclosing filename in quotes, and so on -- all methods result in a 'file not found' error except the notepad, which says '15.txt' is not found.
Due to the nature of the issue and the way search engines optimize the search, it is extemely hard to search for an answer in any of the search engines online. So, I just wanted to put this question out there and see if anybody had to deal with a similar issue and have found any way to rename the file or even to change the extension.
Filenames that are valid in NTFS but cannot be used from Windows can be created when accesing disks or shares from other operating systems like Linux.
If you don't have a Linux installation at hand, then get hold of a "live" CD, boot Linux, and change the filename.
That may sound like a hassle, but Windows-only solutions (moving stuff around, deleting the directory) are even worse.
Use REN: http://ss64.com/nt/ren.html
It is a command prompt command (run > cmd > cd wherever > ren 15. 15.txt )

Resources