Watch Dir For New File

I'm trying to monitor a directory on my linux server to watch for new files being created. So far I have this.
watched = new File(inputDirectory);
          long lastModified = watched.lastModified();
          while( true ) {
              if (watched.lastModified() > lastModified) {
              Thread.sleep(2000);
          }If a directory has been created within inputDirectory, I want to move into that file and read some of it's contents. How would I get the name of the directory that was created?

In my project I need to know when only file is created other events are not important for me.Here a code that only trace if file is created on given directory and say what file is created. However I could not totally control every situation but it seems to work .
public class Main {
public static File CurrentFile=new File("");
public static File bestLast=new File("");
public static int currentNumber=0;
public static void main(String[] args) throws InterruptedException {  
File watched = new File("C:\\deneme");
File[] mycurrentFiless= watched.listFiles();
currentNumber=mycurrentFiless.length;
     long lastModified = watched.lastModified();
while(true){
while( true ) {
          if (watched.lastModified() > lastModified)
File[] mycurrentFiles= watched.listFiles();
if(mycurrentFiles.length > currentNumber)
currentNumber=mycurrentFiles.length;
for(int i=0;i<mycurrentFiles.length;i++)
if(mycurrentFiles.lastModified()>bestLast.lastModified())
bestLast=mycurrentFiles[i];
if(CurrentFile!=bestLast)
CurrentFile=bestLast;
System.out.println("hey, New file is created...: FileName is ..:"+bestLast.getName());
break;
}else if(mycurrentFiles.length != currentNumber)
currentNumber=mycurrentFiles.length;
          Thread.sleep(1000);

Similar Messages

  • How do i set a default group (not staff) for new files?

    by default, new files created from within applications appear to be assigned group "staff", regardless of the folder in which they are being created.
    i want new files to inherit the group of the folder in which they are being created. if i create a new file from the terminal command-line, this works. note that it also works when creating new folders from the finder and "save as" dialogue boxes.
    how do i get this to work for new files saved from all applications?
    thanks.

    I usually use the .NET method myself, but if I were forced to poll I would do something like this.  I use a variant to hold the list of filenames.  I would only poll the folder info, when it has been modified then do the Folder List.  Any new files are spotted when the variant attribute does not exist (Replace = FALSE), and this is added to the array.

  • Default optimization for new files in Acrobat 9 Pro

    When I create a new file in Acrobat Pro 9, it automatically saves as version 1.6 (Acrobat 7.x). Much as I would love the whole world to have the latest reader version on their computer, the reality is that many of my website's users have older versions installed. As a consequence, I need to optimize all files as version 1.4, otherwise they won't be able to open the documents in their browsers.
    Why isn't there a preference setting to optimize all new files as 1.4 by default? This would save having to run the optimizer every time. Also, if I start from a file that is already optimized as 1.4, I extract a page and save it, this saves as 1.6. Why? If I am starting from a 1.4 PDF, surely that's the version I want?
    So every time I extract a page, tese are the steps I have to take:
    1) Extract and save the page
    2) Optimize it for 1.4
    3) Save it again (after confirming that yes, I do indeed want to overwrite it).
    I do this several times a day and it's an absolute pain in the neck, which could be avoided by implemeting any of these features:
    1) A setting under Preferences> Default PDF Version for new files;
    2) A PDF version selection box within the "Save As" dialog (I believe this feature has been requested by others);
    3) Acrobat Pro realizing that you have extracted the page from a 1.4 file and therefore saving the new file with the same format;
    4) Some sort of batch optimization option, so I only have to run the conversion once.
    Frankly I'm surprised none of these features already exist.
    Come on Adobe, is this really so hard to do?
    Thank you.

    Acrobat : Advanced menu : Preflight…
    Then:

  • MacOS how to use standard UNIX behavior for new files

    Hi,
    I have one problem. then i create new files and folders on my Mac, they get group owner from parant. How can i say to OS that it should get group owner for new files from user GID? same as it works on UNIX/Linux?
    How it works on Mac:
    MacOS:/ napetrov$ mkdir -p /tmp/new_dir
    MacOS:/ napetrov$ id
    uid=34148(napetrov) gid=45956(users)
    MacOS:/ napetrov$ ls -al /tmp/new_dir
    total 0
    drwxr-xr-x 2 napetrov wheel 68 Aug 13 19:06 .
    drwxrwxrwt 14 root wheel 476 Aug 13 19:06 ..
    How it works on linux:
    -bash-3.2$ mkdir -p /tmp/new_dir
    -bash-3.2$ id
    uid=34148(napetrov) gid=45956(users)
    -bash-3.2$ ls -al /tmp/new_dir
    total 20
    drwxr-xr-x 2 napetrov users 4096 Aug 13 19:01 .
    drwxrwxrwt 22 root root 12288 Aug 13 19:01 ..
    Message was edited by: napetrov

    napetrov, there are two varieties of UNIX behavior regarding the group of a newly created file. The first variety, which Linux uses, comes from System V UNIX — where the file is created with the group ID of the creating user. The second variety, which Mac OS X uses, comes from BSD UNIX — where the file is created with the group ID of the directory in which it is located.
    In some UNIXes that come with the System V behavior by default, the BSD behavior can be applied to a particular directory by setting the directory‘s “setgid” bit. However, it is rare for a UNIX that comes with the BSD behavior by default to provide a way to allow the System V behavior for a particular user. To my knowledge, Mac OS X does not provide a way to allow the System V behavior for a particular user; thus, I’d recommend the explicit use of chgrp to set the group ID of a newly created file to that of the creating user, if that behavior is what your application needs.

  • PSE 12 Has stopped showing thumbnails for new files

    PSE 12 has stopped showing thumbnails for new file imports. Have  Windows 8.1 update

    In the PSE12 Organizer, the last files imported show an hourglass thumbnail. I am importing from the camera card. Other images have the correct thumbnail. I see the spinning icon on the lower bar showing it updating the catalog. Thank you for your assistance

  • Scan a folder on a different computer for new files

    Hi all,
    I need to scan a folder for new files. I already have a deamon that can do this without a problem. What i need to do, is to scan files on a different computer. The program is going to run on a windows PC and needs to get data from a machine using Unix. I was able to get this done between two windows PC by mapping the drive of the other computer, put i cant do this with Unix.
    I found on the net a class used to make an FTP client(edtftpj-1.5.4). This works fine to get the folder contents once, but it dosen't scan it to see if there are new files. I could of course just loop this FTP client, but this could get very slow if there are to many files in the folder.
    So do you guys know of a way that i could scan this Unix machine for new files?? anything to give me a hint on where to look would be apreciated.
    Thanks in advance
    Alex

    why should we help you make a program that can be used to spy on people, because that's what you're trying to make (even if it's not your current purpose for it, but then it wasn't the purpose of the person who wrote the Michaelangelo virus to write a virus...)?
    It doesn't work on Windows either. As you noted you need to create a drive mapping, which effectively makes the mapped drive available to the other machine as if it were a local drive (applications, including Java applications, don't notice the difference).
    You can install a daemon on Unix machines that allows you to expose drives on them for access over networks as well, similar to what you can do with Windows machines.
    That's your best bet.
    Alternatively you will need to create some sort of server running on the Unix machine which does the work for you and reports the results to your main application on demand through a network connection.

  • How to add support for new file type.

    Using the ESDK, I would like to add support for new file type ( a new extension). this new extension will function like any other non visual code editor but will have specific syntax highlighting, code folding and explorer.
    I am trying ot figure out if I need to create a new editor or use existing JDeveloper code editor and add support for new file type. Does anyone have a high level outline on how to do this using the ESDK that is specifically targeted at adding new file type support for a text based code editor?
    I have looked at the Samples and keep going in multipe directions. It would be cool if there was an example that was how add syntax higlighting for new file type.
    Thank you

    Brian, thank you. I looked at this extension and it answered a lot of questions for me. I was going in the right direction but needed a little help and bost of confidence, this is just what I needed. I created the LanguageSupport, LanguageModel, Addin, Node and TextDocument that are specific to the new file type. I was getting hung up on how to hook this into the JDevelpoer editor. I keep thinking I have to create a custom editor but it looks like I don't have to and it looks like I can associate this file support with the editor framwork, for version 10.1.3.2, with the following in the Addin Initilize() method.
    Recognizer.mapExtensionToClass(MY_EXTENSION, MyNode.class);
    CodeEditor.registerNodeType(MyNode.class, MY_EXTENSION);
    LanguageModule.registerModuleForFileType(new MyLanguageModule(), MY_EXTENSION);
    I have done this but still not able to recognize the new file type.
    At this point, I just want to be able to recognize the new file and display it's associated icon or display a messare to the message log. I put a System.out.println("test") in the Initilize() method of my addin. then I registered MyAddin in the extension.xml. JDeveloper sees this new extension and it is loaded but I have not been able to show the test message or display the new icon when I open the new file type.
    extension.xml
    <?xml version="1.0" encoding="windows-1252" ?>
    <extension xmlns="http://jcp.org/jsr/198/extension-manifest"
               id="teisaacs.jdev.myext.MyAddin" version="1.0.0" esdk-version="1.0"
               rsbundle-class="teisaacs.jdev.myext.resources.MyResBundle">
        <name rskey="EXTENSION_NAME">My Code Editor</name>
        <owner rskey="EXTENSION_OWNER">Me</owner>
        <dependencies>
            <import version="10.1.3">oracle.jdeveloper</import>
        </dependencies>
        <hooks>
            <jdeveloper-hook>
                <addins>
                    <addin>teisaacs.jdev.myext.MyEditorAddin</addin>
                </addins>
            </jdeveloper-hook>
            <feature-hook>
                <description>My Code Editor</description>
                <optional>true</optional>
            </feature-hook>
            <document-hook>
                <documents>
                    <by-suffix document-class="teisaacs.jdev.myext.model.MySourceDocument">
                        <suffix>my</suffix>
                        <suffix>MY</suffix>
                    </by-suffix>
                </documents>
            </document-hook>
            <editor-hook>
                <editors>
                    <editor editor-class="teisaacs.jdev.myext.editor.MyEditor">
                        <name rskey="EXTENSION_NAME">My Editor</name>
                    </editor>
                    <mappings>
                        <mapping document-class='teisaacs.jdev.myext.model.MySourceDocument">         
                            <open-with editor-class="teisaacs.jdev.myrext.editor.MyEditor"
                                       preferred="true"/>
                            <open-with editor-class="javax.ide.editor.CodeEditor"/>
                        </mapping>
                    </mappings>
                </editors>
            </editor-hook>
        </hooks>
    </extension>
    public class MyAddin implements Addin {
        public static final String MY_EXTENSION = "my";
        public void initialize() {
            System.out.println("MyEditor Constructor");
            new MyLanguageModule();
            Recognizer.mapExtensionToClass(MY_EXTENSION, MyNode.class);
            CodeEditor.registerNodeType(MyNode.class, MY_EXTENSION);
            LanguageModule.registerModuleForFileType(new MyLanguageModule(), MY_EXTENSION);
    }I have added and removed the editor hook along with many other modificaitons to the extension.xml but still not recognizing the new file extension.
    Todd

  • How do I change the default save location for new files in Pages back from iCloud to my Documents folder?

    I just upgraded OSX to Mountain Lion and Pages to 4.2, and because OSX is syncing with my iCloud account, when I go to save a new file in Pages it defaults to try to save to my iCloud account rather than giving me the folder structure on my hard-drive that I prefer. It requires two extra steps to save to the proper place in my Documents folder on my hard drive.
    Is there a way to reset the default so that when I go to save a new file, the folder structure opens to the last saved folder (like it does in other non-iCloud applications) rather than defaulting to my iCloud, and to do it without just removing documents from my iCloud account entirely?
    I checked the Preferences for both Pages and iCloud and found nothing about this.

    What I meant is turn off Documents and Data in iCloud in OS X. Keep it on on your iOS devices. iCloud will sync documents between the iOS devices and make them available on the iCloud web site, but it won't mess up iWorks' open and save dialog boxes. It also won't assume that you want all your documents in iCloud, which I think is undesirable anyway.
    Keep iOS and OS X separate, and use the web site to move files between the two as necessary.
    iOS iWork is different from OS X iWork. There are fewer fonts on an iOS device. iOS iWork programs have slightly different feature sets than OS X iWork programs, and the file formats are different. iCloud automatically converts the file format when necessary, but if you make a habit of saving things directly to iCloud, you are limited to the lowest common denominator between the two versions of iWorks. So why would anyone want iWork on the Mac to open and save documents on iCloud by default?
    If you want to store files in the cloud and sync them on your Macs, SugarSync is a much better solution. It lets you choose your sync folders, it doesn't make you reorganize your files, it lets you sync all file types, it doesn't convert files to a different format and back, and it stores everything in the cloud, too. Just the simle act of saving a file backs it up and syncs it. I wouldn't live without it. iCloud is best with iTunes purchases and synchronizing Mac settings and iOS files; I woudln't live without it. The two make an unbeatable combination.

  • Read-only access permissions for new files/folders?

    System:
    Clean Install on new intel Xserve
    10.4.8 Server w/ Open Directory
    Windows clients can read/write completely fine...
    Clients connecting using AFP (whether Standard or Kerberos authentication) can access files, but when new files/folders are created on the server, they register as full permissions for the user who created them, but not for the rest of the group.
    The share(s) in question are set using POSIX from WGM: Full access for owner/group/everyone (changed it to this thinking it would help, but it does not). Of course, no one can make changes to a newly-created/deposited files/folders, which is just plain silly.
    I can chmod the permissions recursively from a script (which fixes the problem, of course) on a regular basis so that its not (as much of) an issue, but there is still a 5-minute lag for the script to kick in, since we don't want to bombard the server with chmod requests every minute....which is unnecessary in the first place!
    I have plenty of other setups which are identical but have no such issue...
    Any reason why POSIX permissions on the share are being ignored from every user account?
    Thanks,
    k

    "That's default posix behaviour no matter what access permissions you set on the sharepoint."
    I'm afraid this is dead wrong. What matters most is how you set permissions on the share, not if you've chosen to inherit vs. using POSIX. POSIX is still used in inherit functions, though you can use ACL's to override them. In this case, ACL's are not being used on those shares (though we tried it).
    After all, why would Apple (let alone anyone else) even offer the ability to change POSIX permissions on a share if it didn't have any effect? That would be somewhat contradictory in nature.
    Like I said before, I have several other installations which are identically setup that have no such issues.
    As for Windows, it is also not set to inherit permissions; we're setting those explicitly. And they work fine.
    Any other ideas?
    Thanks,
    k

  • How to set default sharing permission for new files???

    Hello. I have an imac 24" and a macbook pro 15". they are connected over an airport network. i have file sharing set up, which is working great. i am having one problem though.
    whenever a file is created on either computer, it defaults to only allow the other computer to access it read only. is there a way to set a preference that will make all new files that are created to have read & write permission by the other computer????

    the easiest way to do that is to connect from one computer to the other not as a guest but as a registered user. then any files you create will be owned by that user. so if you have user1 on imac and user2 on mbp connect from the imac to the mbp as user2.

  • Set default permissions for new files?

    We have a small LAN where different users often need to open and resave each others' files. No server, just a bunch of client computers on ethernet sharing an internet router.
    Each time a user creates a file, that file's permissions default to read only for anyone but that user. How can I set up the default permissions so that any newly-created files default to Read & Write for "groups" and "others".
    I anticipate I will have to make this change for each user on each workstation.
    Any help would be greatly appreciated.
    Thanks

    If you want users to share files then have them place the file in the /Users/Shared/ folder. Files placed in that folder can be accessed by any user.
    Why reward points?(Quoted from Discussions Terms of Use.)
    The reward system helps to increase community participation. When a community member gives you (or another member) a reward for providing helpful advice or a solution to their question, your accumulated points will increase your status level within the community.
    Members may reward you with 5 points if they deem that your reply is helpful and 10 points if you post a solution to their issue. Likewise, when you mark a reply as Helpful or Solved in your own created topic, you will be awarding the respondent with the same point values.

  • Can iTunes monitor folders for new files and add to library?

    Hi,
    Is there a way to have iTunes monitor my media folders so that if I add any media files in those folders, iTunes will catch the added media files and add them into the library automatically? I have been using something similar in WMP10; moving to iTunes since iPods are not supported in WMP Sorry if this has already been asked (couldnt find anything similar through search)
    Kapil

    No it cant you have to add manually

  • Message "New files found in your watched folder".

    I keep getting a message "New files found in your watched folder".  But it shows me old files. If I say I want to download them, it tells me it cannot.
    PE 11   Windows 7

    Watch folders is a function of the Elements Organizer, it has nothing to do with the Editor half of the program.
    Do you want to use Watched Folders? If not, disable them by going to File > Watch Folders, then uncheck the "Watch Folders and their Sub-Folders for New Files" option. If you want to use the option, try creating a new folder and set that up as the watched folder and place your images there. The Watch Folders option can get messed up if the folder has images already in it when it is set up.

  • Trigger automator script when new file created

    I want to create an automator script that will recognise when a new file is created (with a name that matches a particular pattern and in a certain directory) and mail that file to a predefined address. Is that possible?

    yes, this is possible with a folder action. you can attach a folder action to the folder in question. it will watch this folder for new files and trigger when a new file is added. you can create an automator workflow and save it as a folder action plugin.

  • How do you get a new file in a shared folder to inherit permissions

    I have a shared folder that I share with a co-worker and having trouble with the permissions for new files/folders.
    When he creates a new file or new folder, the permissions for that file/folder are set as read only for myself. The parent shared folder is set at "Read/Write" for both of us.
    Is it possible to control the permissions for new files/folders?

    Actually, that property used to go in the entry for that sharepoint in the "NetInfo" database, and really only worked properly when 'afpuse_parentowner' was also set. The .plist file controls the behaviour of the afp server as a whole, not that of individual share points.
    I'm not sure what the "DirectoryService" equivalent is - a lot of the things have similar names but differ in "case", but some things are completely different or absent.
    Unfortunately, I'm not equipped to test these things myself but changes can be made using 'dscl', or possibly by editing the flat files directly in a manner similar to what is described here:
    http://www.macgeekery.com/hacks/software/netinfo_dead

Maybe you are looking for

  • Multiple emails on one account.

    How can my daughter get into her FB and other accounts that uses her email address when I used my info to set up an account.  It tells us the email entered does not belong to any account.

  • How to open a .doc file in MS word?

    Hello Can any body direct me to any api or library or sample, where by if you have word document in your local machine, you can run a java program to open that file in MS word. Basically Microsoft word is opened with the local file in your machine an

  • How do I update to latest version of Premiere Pro and After Affects from current version 6?

    Cyrrently running version 6 of Premiere Pro and After Affects. How do I go about upgrading?

  • Twitter for blackberry issue

    i'm having a problem with twitter for blackberry application like when i'm using it and tried to load some of my followers tweets page it doesn't load at all and sometimes it loads then I wouldn't be able to view the remaining tweets at some point pl

  • QoS PM http error when logging in

    Hi All, I've recently installed QoS PM 4.1 on our CiscoWorks server and ran the install to upgrade CS from 3.1 to 3.2 and then the QoS install. I am now unable to logon to Ciscoworks - get an http 400 error. Tried stopping and starting the web server