Get filename and move on

Hi there
I am trying to find a way to through a folder containg a not of files.
What I want is to read the filename of every file in the folder, and based on every filename write a line(the filename) out into a new file.
So I need something that can do like this:
1. read filename for the file
2. write this filename to a new file
3. move on to next file
This should loop until there are no more files.
Can someone help?
Reagards
Tolstrup

It is a lot easier than that.
Make a new File object that points to the directory you want to read from.
File directory = new File("C:\Documents and Settings\All Users\Desktop");Then use listFiles() to get a list of all the files in that directory:
File[] files = directory.listFiles();Then loop and print:
for (int i = 0; i < files.length; i++) System.out.println(files);

Similar Messages

  • Applescript create folder from filename and move file stopped working

    Hi,
    For a while I've used this script but after upgrade and a new machine it stopped working.
    I have  Mac OS 10.8.5.
    This is what I have.
    Images (folder)
    111111_00.jpg
    111111_01.png
    222222_01.jpg
    222222_02.png
    222222_03.gif
    I'd like to be able to create a new folder for each "group of files" (new folder 111111, new folder 222222) and move the appropriate files into each of them.
    The filenames are always built by 6 digits underscore and 2 digits. Can be whatever filetype. (123456_01.jpg)
    I have a script that used to work just fine but now it just creates one folder and then freezes.
    This is the script that doesn't work.
    set chosen_folder to (choose folder)
    tell (a reference to my text item delimiters) to set {old_delim, contents} to {contents, "_"}
    tell application "Finder"
        try
            set file_list to files of chosen_folder
        on error
            set file_list to {}
        end try
        repeat with this_file in file_list
            set folder_name to name of this_file
            if folder_name contains "." then set folder_name to ((text items 1 thru -2 of folder_name) as string)
            set new_folder to ((chosen_folder as string) & folder_name & ":")
            try
                get new_folder as alias
            on error
                make new folder at chosen_folder with properties {name:folder_name}
            end try
            move this_file to folder new_folder without replacing
        end repeat
    end tell
    set my text item delimiters to old_delim
    I know that there are many who can do this easy as pie, but if you can find it in your hearts to help me it would be much appreciated.
    K

    function createFolder(file) {
      var parentFolder = file.parent;
      var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
      if( !saveFolder.exists ) saveFolder.create();
      var saveFile = new File( saveFolder + '/' + file.name);
      if( file.copy( saveFile ) ) file.remove();
    function main() {
       var folder = new Folder("~/Desktop/images");
       var files = folder.getFiles();
       for (var i = 0; i < files.length; i++) {
         var f = files[i];
         if (f instanceof File) {
          createFolder(f);
    main();
    Something like that should work.

  • How do I get music and movies from iPod to my computer?

    Hi How can I put all of my music and movies that are on my iPod onto my computer? They were all on my computer before but became erased. Thanks!

    If you have any iTunes Music Store purchases the transfer of purchased content from the iPod to authorised computers was introduced with iTunes 7. A paragraph on it has been added to this article: Transfer iTunes Store purchases using iPod
    The transfer of content from other sources such as songs imported from CD is designed by default to be one way from iTunes to iPod. However there are a number of third party utilities that you can use to retrieve the music files and playlists from your iPod. You'll find that they have varying degrees of functionality and some will transfer movies, videos, photos, podcasts and games as well. Have a look at the web pages and documentation, this is just a small selection of what's available, they are generally quite straightforward. You can also read reviews of some of them here: Wired News - Rescue Your Stranded Tunes
    TuneJack Windows Only
    iPod2PC Windows Only
    iGadget Windows Only
    iDump Windows Only
    iRepo Windows Only
    iPodRip Mac & Windows
    YamiPod Mac and Windows Versions
    Music Rescue Mac & Windows
    iPodCopy Mac and Windows Versions
    There is also a manual method of accessing the iPod's hard drive and copying songs back to iTunes on Windows or a Mac. The procedure is a bit involved and won't recover playlists but if you're interested it's available at this link: Two-way Street: Moving Music Off the iPod
    If your iPod is set to update automatically you need to take care connecting to an empty iTunes. You can use a keyboard command to prevent your iPod auto-syncing with iTunes. While connecting the iPod to the computer on Windows with iTunes 7 installed hold down the Control and Alt keys (or Shift + Ctrl keys in older versions). This will stop the iPod from auto-syncing with iTunes and the iPod will appear in the source list. Wait until you are sure the iPod has mounted, and that it will not auto sync and then you can let the keys go. This may take between 20 to 30 seconds depending on your computer: iTunes 7 Keyboard Shortcuts for Windows
    Your iPod should appear in the iTunes source list from where you can change the update setting to manual and use your iPod without the risk of accidentally erasing it. Also when using most of the utilities listed below your iPod needs to be enabled for disc use, changing to manual update will do this by default. Check the "manually manage music and videos" box in Summary then press the Apply button: Managing content manually on iPod
    Whichever of these retrieval methods you choose, keep your iPod in manual mode until you have reloaded your iTunes and you are happy with your playlists etc then it will be safe to return it auto-sync. I would also advise that you get yourself an external hard drive and back your stuff up, relying on an iPod as your sole backup is not a good idea and external drives are comparatively inexpensive these days, you can get loads of storage for a reasonable outlay.

  • Get pictures and movies of iphone to PC

    hi
    how do I get the pictures and movies taken with the iphone to mij PC. (also the movies created in imovie on the iphone)
    it seems that it's not possible in itunes...?
    iphone 4, 4.0.2software
    PC with windows XP SP3, with latest itunes software
    thanks in advance
    steven

    Pics and movies take with iphone are NOT part of the sync process. You import them as you would from any digital camera.
    http://support.apple.com/manuals/iphone/

  • IPod touch gets music and movies deleted.

    This is a new issue with iOS6 and/or iTunes 10.7.
    I have a 4th gen iPod touch, and twice in the past week it has had all the music and movies (but not apps or pictures) deleted. The only way to fix this is to go to Settings -> General -> Reset -> Erase all files and settings and restore it like it was out of the box; trying to sync it again or choosing different combinations of songs does not work, it just will not sync the music. Is anybody else encountering this issue?
    Windows 7 Ultimate, 32-bit.

    Technically a double post but . . .
    Ty draining the battery once and than see if you get better battery life.

  • Getting videos and movies to play on iPod

    I have many videos and movies, mostly mpeg.
    I have been waiting 4 hours, since I clicked export save movie for iPod play? This is taking 4ever!
    I upgraded to the QT Pro to accomplish this task, and the progess window now shows 28% At this rate it will take me years to save the videos I have - for iPod play!
    Any way to speed up? I can only imagine how long it will take a full length movie???

    Eddy:
    QT Pro is incredibly, incredibly slow - BUT the results are gorgeous and you don't have to fiddle with settings.
    If you value speed over image quality, then you will need to download Handbreak.
    Before you do, you will need to read the iPod DVD Ripping Guide, which explains the process.
    If you want to rip the DVDs you own to your harddrive, get MacTheRipper. Doing so speeds up the process of converting to an iPod-compatible format.
    Lita

  • Get filename and full path from Forms on local directory in MS Windows

    I am writing a Form, when clicking a Push Button, I can click on sub-directory and select a filename, and the filename and the full path are then passed to a Text Item.
    Does any one know how this could be done?

    which version of forms?
    webforms you can use the webutils bean thing.
    client server forms there is/was the hierarchical tree object

  • Read character 3+4 from filename and move to other position

    Hello,
    I need a javascript to read my filename (I have the one for the full filename) and especially the 3rd and 4th position of the filename.
    The characters on position 3 and 4 must be moved to the position just before the extension.
    Example:
    4PEN12345.pdf (old name) should be 4P12345_EN.pdf
    Now I have the following script to extract all pages in an existing pdf file to separate pages with all the same suffix before the extension
    /* Extract Pages to Folder */
        var re = /.*\/|\.pdf$/ig;
        var filename = this.path.replace(re,"");
            for ( var i = 0;  i < this.numPages; i++ )
            this.extractPages
                nStart: i,
                nEnd: i,
                cPath : filename + "_page_" + (i+1) + "_EN.pdf"
    Can anybody help me to set me on the right direction?

    Now I have the file 4PBG12345-1.pdf (7 pages included in the pdf).
    Your script as I filled in:
    /* Extract Pages to Folder */
        var re = /.*\/|\.pdf$/ig;
        var filePath = this.path.replace(this.documentFileName, "");
        var oldFileName = this.documentFileName;
        var suffix = oldFileName.substring(2,4);
        var newFileName = oldFileName.substring(0,2) + oldFileName.substring(4).replace(".pdf", "_"+suffix+".pdf");
        var newFilePath = filePath + newFileName;
            for ( var i = 0;  i < this.numPages; i++ )
            this.extractPages
                nStart: i,
                nEnd: i,
                cPath : newFilePath
    Result:
    1 file ==> 4P12345-1_BG.pdf (7 pages included in the pdf)
    Of course, because the syntax for extracting and adding automatic pages is not filled in. So, that was my question, how must I nest to add the right:
    Filepath+oldfilenamesubstring(0,2)+oldfilenamesubstring(4)+_page_i++_+suffix+.pdf in the extract section
    So, my example must result in 7 pdf's:
    4P12345-1_page_1_BG.pdf (with content of page 1)
    4P12345-1_page_2_BG.pdf (with content of page 2)
    4P12345-1_page_3_BG.pdf (with content of page 3)
    4P12345-1_page_4_BG.pdf (with content of page 4)
    4P12345-1_page_5_BG.pdf (with content of page 5)
    4P12345-1_page_6_BG.pdf (with content of page 6)
    4P12345-1_page_7_BG.pdf (with content of page 7)

  • Get filename and directory name during runtime

    Hi guys,
    I am developing a file to file interface without content conversion, just a simple file transfer from one ftp server to another. I have to read the same filename (invent.txt) from multiple folders (mstransfer/M01/IN1, mstransfer/M02/IN1, mstransfer/M03/IN1....) that represent different stores and transfer it as it is with the same name to exactly the same directory name in the target ftp location.
    My problem is found inside a dummy mapping that I have created in order to specify the target directory and the name of the file. I am doing the following:
    A) A Java UDF to specify the filename
    trace = container.getTrace();
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    String filename = conf.get(key);
    trace.addWarning("filename = "+filename);
    conf.put(key, filename);
    return "";
    //return filename;
    B) A Java UDF to specify the directory name
       //write your code here
    trace = container.getTrace();
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    String directory  = conf.get(key);
    trace.addWarning("directory before = "+directory);
    directory = "/usr/sap/trans"+directory;
    trace.addWarning("directory after = "+directory);
    conf.put(key, directory);
    return "";
    //return "/usr/sap/trans"+directory;
    In receiver file adapter I do not specify neither a filename nor a target directory.
    When I am testing it, I always get a mapping runtime error.
    Any ideas?
    --Evaggelos

    Guys,
    First of all, I am doing an end to end testing, i.e. I let the FTP adapter pick the file up and another FTP adapter delivers the file to target folder. I am definitely not testing the mapping in mapping editor.
    I get the error in Request message mapping (pipeline step, which I can see in SXMB_MONI transaction) which is a dummy mapping between two message types that I have created and are based on two data types with two fields each.
    The UDF's that I have created go in-between the source and target fileds of the message types/data types.
    The error that I see in the trace section of the XML message in SXMB_MONI is the following:
    "<Trace level="1" type="T">RuntimeException during appliction Java mapping com/sap/xi/tf/_MM_G_SRS_FileTransfer_MNS_</Trace>
      <Trace level="1" type="T">java.lang.NullPointerException at com.sap.aii.mappingtool.tf3.AMappingProgram.exceptionCaught$(AMappingProgram.java:59) at com.sap.aii.mappingtool.tf3.Transformer.checkParserException(Transformer.java:182) at com.sap.aii.mappingtool.tf3.Transformer.start(Transformer.java:149) at com.sap.aii.mappingtool.tf3.AMappingProgram.execute(AMappingProgram.java:102) at com.sap.aii.ibrun.server.mapping.JavaMapping.executeStep(JavaMapping.java:64) at com.sap.aii.ibrun.server.mapping.Mapping.execute(Mapping.java:91) at com.sap.aii.ibrun.server.mapping.MappingHandler.run(MappingHandler.java:90) at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest(MappingRequestHandler.java:95) at"
    I have included some trace.addWarning() lines in Java code to help me debug my code, but I cannot see them anywhere inside the trace to be getting executed.
    I will try Bhavesh's idea and I will write the code in the Java Section of my message mapping ( either Intialization or Destrcution ) section.

  • How do I set up iTunes to get music and movies from 2 different hard drives?

    I have an iMac and a 2 TB Apple Time capsule. I am creating a disk image on the time capsule so I can use 1TB for Time Machine backups and the other 1TB as a wireless external hard drive. The main reason for this is I only have a 500GB hard drive an my iMac and I would like to store all of my movies on the Time Capsule. How do I set up iTunes to pull my music and evrything else like it currently is on my iMac's hard drive, but access my Time Capsule's hard drive for movies?
    Is this even possible?
    Thanks,

    You need to use one iTunes library for music and another alternate library for your movies.  This explains how to open an alternate iTunes Library file or create a new one, http://support.apple.com/kb/HT1589

  • FileUpload get filename and PATH?

    Hi everybody,
    is there a chance to get also the path from where to upload a file using the fileupload-UI?
    Thanks a lot
    Regards Mario

    Mario,
    No, this is not possible due to security restrictions imposed by browsers
    VS

  • I just noticed that some of the movies I had in iTunes did not get transferred to the iPhone. The missing movies are shown as generic movie icons in the iTunes panel. How do I get the original movies to show up again and transfer to the iPhone?

    I just noticed that some of the movies I had in iTunes did not get transferred to the iPhone 5. The missing movies are shown as generic movie icons in the iTunes panel and are checked to select them. But they do not show up in iPhone Videos. How do I get the original movies to show up again and transfer to the iPhone? I recently upgraded Mac OS to 10.6.8

    1. iTunes won't offer cloud downloads for songs that it "thinks" are in your library, even if it "knows" the files are missing. If you've exhaustively searched for the missing files and there is no prospect of repair by restoring to them to their original locations, or connecting to new ones, then delete that tracks that display both the missing exclamation mark and are of media kind Purchased/Protected AAC audio file. Don't hide from iTunes in the cloud when asked, close iTunes, then reopen. You can download from the cloud links or iTunes Store > Quicklinks > Purchased > Music > Not on this computer > All songs > Download all.
    2. Why? Not sure, perhaps 3rd party tools or accidental key presses combined with previously hidden warning messages when trying to organize the library. There is a hint that using the feature to downsample media as it is synced to a device may also be involved, though I've not replicated it. Whatever the reason a backup would protect your media.
    tt2

  • My ipod won't sync and it keeps coming up with an error message saying "internal error" or it tries to get me to restore from a backup. All of my music and movies have been wiped from my ipod and the apps don't work. The backups don't work either. help.

    I plugged my ipod touch into my computer to sync it and it came up with an error message saying that it encoutered an internal error and it refused to sync.
    I then unplugged it and plugged it back in and this time it told me that I needed to restore from a backup or set it up as a new ipod. I tried to restore from a backup but it came up with the error message "Backup session failed" every time. I then looked on my ipod and all of my music and movies are gone though it still says that they are on the ipod in itunes. I decided to use the restore function and let that finish. After restoring it still doesn't allow me to sync or back up and The music and movies can still not be seen. I am currently attempting to copy the music and movies to my ipod though this did not work with my apps as they transfered but when I attempted to open them they just crash... If someone could please help me it would be great. It is driving me crazy.

    If you get an error that says can't backup, try moving the existing backup file to a safe location and thry again. again. You can find the location of the backup file here:
    iPhone and iPod touch: About backups

  • Can not open iCloud on MBP? Want to PhotoShare. Set up in iPhone.   Go to System Preferences, click on iCloud, get the message "move to iCloud", sign in, click on open iCloud", sign in again, and get only FindmyPhone?

    Set up in iPhone.   Go to System Preferences, click on iCloud, get the message "move to iCloud", sign in, click on open iCloud", sign in again, and get only FindmyPhone? Thus, when I go to Iphoto to set up photo sharing, it says I have to have icloud account-go to sys preferences--then i go through the loop again?  Suggestions?

    jgtown wrote:
    Now I have to get my sign-in for mobileme to be the same as my sign-in for Itunes, etc. so I have only one Apple ID!
    You're not going to be able to: you can't merge accounts or transfer iTunes purchases from one Apple ID to another: but there is no problem about using two IDs.
    Use your ex-MobileMe email address (which is also an Apple ID) for iCloud for syncing email, contacts, calendars, bookmarks, and PhotoStream.
    Use your other Apple ID as before for iTunes, iTunes in the Cloud and iTunes Match.
    There's no conflict about doing this, and you won't even notice as Keychain will log you in with the correct ID in each case. It's also better security not to have your iTunes login also your email address, given the number of complaints about hacked iTunes accounts.

  • Can anyone help me write a script that would click "get info" and then "enter" on each movie in my itunes library? I am asking because my itunes 11 repeatedly loses the artwork to my movies in my itunes library.

    Can anyone help me write a script that would click "get info" and then "enter" on each movie in my itunes library? I am asking because my itunes 11 repeatedly loses the artwork to my movies in my itunes library. I can restore the artwork (and make my apple tv see the movie exists as well) by going into the movie library and clicking on each movie by hand, slecting get info, and then selecting enter. Now doing this 10 times in 20 days was fun and all BUT I would really like to automate the process so everytime itunes screws it up I can fix it easier.
    I saw this example of an itunes script that restores artwork for music
    tell application "iTunes" set theSelection to selection repeat with i from 1 to count of theSelection tell (item i of theSelection) set artworkCount to count of artwork repeat artworkCount times set theArtwork to data of artwork 1 delete artwork 1 set data of artwork artworkCount to theArtwork end repeat end tell end repeat end tell
    but I need to tweak this to fit my needs for simply clicking the "get info" button and "enter" in the movie library rather than all the stuff this guy has listed. Any ideas or help on writing this? Thanks.

    Try assigning Queen as the Album Artist on the compilations in iTunes on your computer.

Maybe you are looking for