Please syntax for me :) Re: Rename files with a given string
From the post http://forum.java.sun.com/thread.jspa?forumID=54&threadID=5118509
Was wondering if someone could explain how the red characters work and what it does. Thanks!
String newFileName = destFiles.getName().replaceFirst("[^.]*", rename);
File newFile = new File(destFiles, newFileName);
destFiles.renameTo(newFile);
It would serve you better to look at the API documentation.
getName() returns a String, right? So it is invoking String.replaceFirst with those arguments. Do you know where the API documentation is?
http://java.sun.com/j2se/1.5.0/docs/api/index.html
(That's for version 1.5 - you can find other docs for other versions).
Similar Messages
-
Rename files with a given string
Can anyone please help with the following code. I need to rename files with a given string. My code is:
import java.io.File;
public class RenameFile
public RenameFile()
void naming(File destFiles, String rename)
System.out.println("destFiles:"+destFiles.getName());
//output: destFiles:C:\temp\store\test.abc
//output: destFiles:C:\temp\store\test.def
//output: destFiles:C:\temp\store\test.ghi
System.out.println("rename:"+rename);
//output: rename:pmnr
String name=destFiles.getName().toString();
System.out.println("name:"+name);
//output: name:test.abc
//output: name:test.def
//output: name:test.ghi
String ren="";
ren=name.replaceAll(name,rename);
System.out.println("ren:"+ren);
//output: ren:pmnr
My files I am getting from "destFiles" are:
C:\temp\store\test.abc
C:\temp\store\test.def
C:\temp\store\test.ghi
which I need to rename as:
C:\temp\store\pmnr.abc
C:\temp\store\pmnr.def
C:\temp\store\pmnr.ghi"I seem to remember telling him this recently...
Probably but unless the OP takes an interest in the replies we are just wasting our time. "
Sorry, there has been a misunderstanding. I take full interest in all the replies.
About renaming, I had got the solution from sun.com, it works fine when I am passing all the files in the source directory to the destination directory. But since I am passing only a selected few files from source to destination, I have changed my code and the previous solution is not working now.
Anyway, below code is working and thanks a lot
String newFileName = destFiles.getName().replaceFirst("[^.]*", rename);
File newFile = new File(destFiles, newFileName);
destFiles.renameTo(newFile); -
Please advise how to custom batch rename files with Aperture 3 in the following format: IMG_0023.cr2 to Smith_120816_0023.cr2? I cannot find a way to structure the date in Aperture as such (YYMMDD), as well as extract only the camera file (0023, for example). Adobe Bridge CS5 can do this, but NONE of the Adobe software is retina optimized, and is terrible to look at.
In Aperture you are limited to renaming files by the entries in the File Naming preset window.
At what point are you looking to rename, import or export? It might be possible to do what you are looking to do external to Aperture either via a script or other software.
regards -
Essentially, Linux created some files with colons (:) in the name on a NTFS partition where I have Windows installed. I have since uninstalled Linux, but now I can only view these files in Windows Explorer. I can't open them, I can't even rename them to
correct the problem. It's as if they don't exist, because of the invalid search paths.
If I try to rename them in Windows Explorer I get following message.
The file name you specified is no valid or too long.
Specify a different file name.
Well isnt' that something?... isn't that nice? Windows is able to display these files, but it doesn't allow me to open them and it certainly doesn't like me to rename them. So why is it whining about it then, when I'm trying to help? It says "try a different
file name". Yeah, right! Like I haven't tried that one already! It doesn't matter what file name I input it will never accept it.
So what am I supposed to do now? Ditch Windows and go back to Linux? Surely, Microsoft doesn't like the sound of that. Sure, I could reinstall Linux or run a Linux live system to correct the problem. But what good is Windows then? I might as well switch to
Linux altogether.
After doing some research I now know by fact that it's (kind of) possible to rename files from UNIX and UNIX-like operating systems to those compliant with Windows by using something called file name character translation. To some level this is essential and
necessary for Windows interoperability with other operating systems (Windows is not the only operating system in the world). But this seems to be very complicated and I can't get my head around it. My brain is in overload. I don't know where to start.
Once there was a...
There's the Windows Services for UNIX (SFU) 1.0, 2.0, 3.0, 3.5. The first two versions were based on MKS Toolkit, a package licensed by Microsoft from MKS Inc. The later versions were based on the similar Interix product, after Microsoft purchased the company
that made it.
Then there's the new Subsystem for UNIX-based Applications (SUA). These are services for UNIX components. They are supposed to have Client for NFS v3 included as well. But the server components from the SFU line is missing (e.g. Server for NFS). These are included
in Server editions of Windows.
Then there's the Microsoft Knowledge Base article
289627: "How to Enable File Name Character Translation". This article seems to describe exactly my situation.
Windows and UNIX operating systems have restrictions on valid characters that can be used in a file name. The list of illegal characters for each operating system, however, is different. For example, a UNIX file name can use a colon (:), but a Windows
file name cannot use a colon (:). If a UNIX user attempts to create a file with a Windows illegal character on a Windows Services for UNIX network file system (NFS) share, the attempt is unsuccessful and the UNIX client computer receives an input or output
error.
It goes further than that. At first glance, this KB article also seems to offer a solution to this exact problem, with examples as shown below.
For example, the following maps the UNIX colon (:) to a Windows dash (-):
0x3a : 0x2d ; replace client : with - on server
I checked these values in charmap.exe and they are correct. Except for 2D not being a "dash", it's rather a hyphen ("hyphen minus" to be exact), but these two have pretty much the same appearance and they get interchanged a lot, I'm sure
they are used to it by now. (Yes, the characters! They don't mind.)
Then there's this registry key.
HKEY_LOCAL_MACHINE\Software\Microsoft\Server For NFS\CurrentVersion\Mapping
Well, of course, I don't have Server for NFS. So this is a dead end. Well, actually, it was a dead end from the beginning...
1. First of all, I'm not working with a network share on a NAS or SAN storage. The files are on the local disk drive where Windows is installed, so that's a DAS for you.
2. I don't have SFU! Well obviously, I'm on Windows Vista! So that means SUA!
3. SUA are service components only. No server components. Can you guess what that means? Yeah... no "Server for NFS" since it's a server component.
4. Windows Vista is a client side operating system! Server for NFS is only offered for use with Windows Server systems.
5. Back to square one!
So there you have it. They all lived happy for the rest of their lives...
I'm stuck here. Can someone tell me what to do? I mean beyond the obvious option to use Linux to fixa a Windows problem? The NTFS file system itself supports colons in file names. It's Windows that doesn't, and so by default it proclaims it invalid character.
Surely, even a Windows client operating system like Windows Vista should be able to allow the user to at least rename files with invalid characters to something more sensible (from the system point of view) and valid, if not being able to open them as they
are. Just add some crazy voodoo code to it and it will work. If you can make it possible on Windows Server with UNIX user-mode subsystem on NT kernel, then what's stopping you from giving the Windows client system the same benefit?
So what now? Purchase a Windows Server 2012 R2 license, copy my invalid files to a NAS share with NFS on a UNIX or Linux system, and have a go at the Windows registry and Server for NFS? Yeah... you're right, it's probably a bit over the top...
On a second thought... I might as well install Linux again. There are countless situations where Linux has helped me solve problems related to, and more often than not caused by Windows.Essentially, Linux created some files with colons (:) in the name on a NTFS partition where I have Windows installed. I have since uninstalled Linux, but now I can only view these files in Windows Explorer. I can't open them, I can't even rename them to
correct the problem. It's as if they don't exist, because of the invalid search paths.
If I try to rename them in Windows Explorer I get following message.
The file name you specified is no valid or too long.
Specify a different file name.
Well isnt' that something?... isn't that nice? Windows is able to display these files, but it doesn't allow me to open them and it certainly doesn't like me to rename them. So why is it whining about it then, when I'm trying to help? It says "try a different
file name". Yeah, right! Like I haven't tried that one already! It doesn't matter what file name I input it will never accept it.
So what am I supposed to do now? Ditch Windows and go back to Linux? Surely, Microsoft doesn't like the sound of that. Sure, I could reinstall Linux or run a Linux live system to correct the problem. But what good is Windows then? I might as well switch to
Linux altogether.
After doing some research I now know by fact that it's (kind of) possible to rename files from UNIX and UNIX-like operating systems to those compliant with Windows by using something called file name character translation. To some level this is essential and
necessary for Windows interoperability with other operating systems (Windows is not the only operating system in the world). But this seems to be very complicated and I can't get my head around it. My brain is in overload. I don't know where to start.
Once there was a...
There's the Windows Services for UNIX (SFU) 1.0, 2.0, 3.0, 3.5. The first two versions were based on MKS Toolkit, a package licensed by Microsoft from MKS Inc. The later versions were based on the similar Interix product, after Microsoft purchased the company
that made it.
Then there's the new Subsystem for UNIX-based Applications (SUA). These are services for UNIX components. They are supposed to have Client for NFS v3 included as well. But the server components from the SFU line is missing (e.g. Server for NFS). These are included
in Server editions of Windows.
Then there's the Microsoft Knowledge Base article
289627: "How to Enable File Name Character Translation". This article seems to describe exactly my situation.
Windows and UNIX operating systems have restrictions on valid characters that can be used in a file name. The list of illegal characters for each operating system, however, is different. For example, a UNIX file name can use a colon (:), but a Windows
file name cannot use a colon (:). If a UNIX user attempts to create a file with a Windows illegal character on a Windows Services for UNIX network file system (NFS) share, the attempt is unsuccessful and the UNIX client computer receives an input or output
error.
It goes further than that. At first glance, this KB article also seems to offer a solution to this exact problem, with examples as shown below.
For example, the following maps the UNIX colon (:) to a Windows dash (-):
0x3a : 0x2d ; replace client : with - on server
I checked these values in charmap.exe and they are correct. Except for 2D not being a "dash", it's rather a hyphen ("hyphen minus" to be exact), but these two have pretty much the same appearance and they get interchanged a lot, I'm sure
they are used to it by now. (Yes, the characters! They don't mind.)
Then there's this registry key.
HKEY_LOCAL_MACHINE\Software\Microsoft\Server For NFS\CurrentVersion\Mapping
Well, of course, I don't have Server for NFS. So this is a dead end. Well, actually, it was a dead end from the beginning...
1. First of all, I'm not working with a network share on a NAS or SAN storage. The files are on the local disk drive where Windows is installed, so that's a DAS for you.
2. I don't have SFU! Well obviously, I'm on Windows Vista! So that means SUA!
3. SUA are service components only. No server components. Can you guess what that means? Yeah... no "Server for NFS" since it's a server component.
4. Windows Vista is a client side operating system! Server for NFS is only offered for use with Windows Server systems.
5. Back to square one!
So there you have it. They all lived happy for the rest of their lives...
I'm stuck here. Can someone tell me what to do? I mean beyond the obvious option to use Linux to fixa a Windows problem? The NTFS file system itself supports colons in file names. It's Windows that doesn't, and so by default it proclaims it invalid character.
Surely, even a Windows client operating system like Windows Vista should be able to allow the user to at least rename files with invalid characters to something more sensible (from the system point of view) and valid, if not being able to open them as they
are. Just add some crazy voodoo code to it and it will work. If you can make it possible on Windows Server with UNIX user-mode subsystem on NT kernel, then what's stopping you from giving the Windows client system the same benefit?
So what now? Purchase a Windows Server 2012 R2 license, copy my invalid files to a NAS share with NFS on a UNIX or Linux system, and have a go at the Windows registry and Server for NFS? Yeah... you're right, it's probably a bit over the top...
On a second thought... I might as well install Linux again. There are countless situations where Linux has helped me solve problems related to, and more often than not caused by Windows. -
Urgent.
I have been not approved of this error
been back and forth with Apple
The title of the Table of Contents in portrait view is placeholder text : Book Title. Please redeliver your corrected full book file with a custom preview file. The book will not go live in the store without a matching custom preview file."
1st, how do you clarify the Table of Contents issue. No idea what I am doing wrong
2nd what is a customr preview file? I uploaded a sample book already.
Please advise ASAP
my email: [email protected]
thanksI double check my table of content and I do not have a place holder... so I don't understand the error.
-
I have Adobe Design and Web Premium CS6. If I buy adobe CC, can I easily open my for example indesign CS6 files with no complications?
I cannot imagine any problems in doing so, but you can keep your cs6 installation anyway.
-
SPD 2010 - How to know if a file with a given name already exists in a document library
Hi,
I've created a workflow using SPD. One of the steps in there is changing the name of the document to a clean name. This workflow fails if a document with this same name already exists in my document library. Is there a way to check in a SPD workflow if
a document with a given name already exists in my document library ?
Marc NemegeerHi,
According to your post, my understanding is that you wanted to know if a file with a given name already exists in a document library.
You can use a SharePoint Designer workflow to achive it.
To test to see if a document exists, you need to use condition:
If Current List:Name equals [%Current Item:Title%].docx
Here is a similar thread for you to take a look at:
http://social.technet.microsoft.com/Forums/en-US/cc227020-ce81-4c08-aee0-a66789d8ad05/test-to-see-if-document-exists?forum=sharepointcustomizationprev
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
How can I search the tree with a given string?
How can I search the tree with a given string?
I don't find any function like "search(...)".
I want to find the tree nodes which include the given string.
Thanks.Try it with .com instead of .ca - fixes it for me (corporate firewall blocks .ca here)
http://spendolini.blogspot.com/2013/09/working-with-apex-tree.html
Anyway - it links to an article of mine which describes interacting with the tree: Tom's Blog: Working with the tree in Apex. There is also a demo application on apex.oracle.com: http://apex.oracle.com/pls/apex/f?p=54687:38 -
Work flow for syncing separate Audio files with Video files in FCP
It may be too late for me to use this workflow that I want with my current project, but I need to figure out what it is anyway for future reference.
Right now I'm editing a movie which is near completion. When we recorded the movie, the camera's deck recorded reference audio from the sound guy at 48k @ 16bit. This audio also went through an additional set of preamps which added a small amount of noise. So we don't want to use the reference audio because of it's low resolution and less clean audio. The sound guy recorded straight to his deck at 48k @ 24bit, besides the better resolution, his audio is noticeably better.
The camera deck and 'clapper' (I think that's what you call it) were not connected or synced. So the video files and the soundsguy's audio files are slightly different lengths, but at least have a 'clap sound' to manually sync to. And I don't mean that the audio and video files won't play in sync with each other, I mean that the soundguy always started recording before the camera, so his audio files have slightly different start and stop times.
Could I have synced the audio files with the video files before I started editing this project? If so, could it have been in the way that the soundguy's audio would be connected to my video files while editing? What would that procedure have been?
My current workflow right now is I have my finished sequence, I change the bit rate to 24 in Sequence Settings, and start manually dragging the soundguy's files to the sequence for every little edited clip. This is going to take forever, there are 99 scenes in this movie. Anyway, at the end of the day these sequences are exported as .omf files and imported into Pro Tools for audio post production.
I was not thinking to figure this out before I started editing the movie, this is unfortunate, a newb move in a decent production.
Anyway, I don't know if there is a standard for this situation or if I just opened up a can of worms for many possible workflows. Please comment if you have experience in this area or please refer me to any reading material.
Thanks for your time!
-MontyThe normal workflow (besides manually syncing up before editing!)
is to have ' some ' way of auto syncing the clips.
So you must have common timecode.
With external audio, you can slave the cam's TC to the TC output of the BWF recorder.
Then you can use BWF / QT merge (one of my apps) to sync them, or use Sync 'n Link.
(another third party application)
If it is not possible cause you're shooting with a cam without a TC input, you can record the TC output on one of the audio tracks of your cam, and use FCPauxTC reader to decode the beeps and translate that to QT TC, and again use the former tricks to sync them.
It is difficult when you have never done it, but very easy once you get the hang of it, and it saves a huge amount of time to do it right from the start.
Have a look at the FCP aux TC reader here:
http://www.videotoolshed.com/?page=products&pID=26
Sync 'n Link can be found here:
http://www.assistedediting.com/Sync-N-Link/
/// disclaimer, i AM the owner of Videotoolshed, and i WILL (at least try) to make money on it. ///
/// i do NOT have any relation with AssistedEditing.com, besides friendship with the owner. /// -
It is my understanding that Adobe's migration tool will NOT support transferal of custom metadata from Aperture to Lightroom.
I have recently enhanced my Custom Metadata plugin to read custom metadata from Expression Media xmp, and it seems like a no-brainer to have a "preset" which can read/import/transfer custom metadata from Aperture xmp too - I just need a sample to work with - thanks.
If you don't want to post here, please send directly to me.
robcole.com - Contact Me
RobTo attempt a wrap-up for this thread:
Aperture does NOT provide a means to save custom metadata in XMP - the initial premise of this thread was incorrect: a thank you to John Beardsworth for setting me straight. Specific question asked has been answered.
The purpose for the thread however was to learn how to get information out of Aperture so it can be gotten into Lightroom (final destination: custom metadata fields).
Here is one way to get custom metadata in Aperture to custom metadata in Lightroom, recommended if you have enough free IPTC fields to house the custom data temporarily:
* Create an applescript file with the following contents, modified to support your custom metadata fields; note: it must also be modified to specify the IPTC fields to be used:
tell application “Aperture”
set imageSel to the selection
repeat with i from 1 to count of imageSel
tell library 1
tell item i of imageSel
set customFieldValue to value of custom tag "myCustomFieldName"
set value of IPTC tag "myFreeIptcFieldName" to customFieldValue
end tell
end tell
end repeat
end tell
Note: you must adapt script depending on your custom fields, and which IPTC fields you have free.
* Select photos in Aperture.
* Execute the script.
* Once photos are in Lightroom, with IPTC fields populated.., then in Lr's plugin manager, with 'Custom Metadata' plugin selected, click 'Transfer Metadata' button, then "follow the yellow-brick road" (you will be prompted with instructions..). Metadata will be transferred from IPTC fields to custom metadata in Lightroom.
If you do NOT have sufficient IPTC fields to use, or would rather not use IPTC fields for this, then you'd have to modify the script to populate a row in a CSV file for each photo, then use the 'Import from CSV' function in Custom Metadata plugin. I can help if it comes to this..
PS - There may be other ways as well, but maybe this is enough..
Rob -
Renaming files with alternate numbers
I'd like to rename a large number of files with alternate numbers. For example, files 1-10 would be renamed 1,3,5,7,9,11 etc, and 2-10 would be renamed 2,4,6,8,10,12 etc.
I'm not familiar with AppleScript but use Automator and cannot find a way to do it with actions - a script that I could run from within Automator would be wonderful. Any help would be greatly appreciated.There's certainly no Automator action that's going to do this directly - it's a pretty specific requirement.
Additionally, there are some specific caveats to consider. For example, you can't rename file '2' to '3' because there's already a file '3' in the directory.
There are two classic solutions to this: one is to work in reverse - rename file 10 -> 19, 9 -> 17, 8 -> 15, etc. so that file '3' is moved before you try to rename file 2
The other solution is to move the files to a new directory as you rename them which ensures that no naming conflicts exist.
Also, before anyone can show you an example, you need to be clearer on your file names. Are they really '1', '2', '3', etc., or are they "1.jpg", '2.txt', '3.png', etc. File name extensions are going to be a critical element in renaming these files correctly (e.g. you can't just rename file '2.jpg' to '3' and hope it'll work. -
Steps for the IDOC TO FILE with ACKNOWLEDGMENT
Hello experts,
Kindly give me the step by step procedure for the following scenario.
My scenario is an IDOC( any idoc) for R/3 is coming to XI and send to FTP as XML file with out any modifications, and ftp have to send an response (acknowledgment) to XI and that to R/3 as an IDOC.
I have seen snd but i not able to find the exact steps for the above requirement. Probably i may failed to find it.
So kindly give me the steps or any blogs links explaining the above scenario.
Thanks inadvance.
Kiran.Hi
Pls check the following docs.
ALEAUD not coming to SAP from XI & u0093Acknowledgment not possible" in idx5
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/903a0abc-e56e-2910-51a8-9dc616df56eb
if you are looking to receive the File Acknowledgements..pls check the below link
/people/michal.krawczyk2/blog/2006/06/22/xi-playing-with-the-file-adapters-acknowledgments
Regards
Abhijit -
Syntax for update descriptor description file?
I'm looking to update my AIR app and I have that working. But what is the syntax for the description in the update descriptor file? How can I add a description that has multiple lines??
KyleHi Kyle,
Are you referring to the updater framework? You should be able to do this using simple line breaks.
http://www.adobe.com/devnet/air/articles/air_update_framework.html
Chris -
Renaming files with Automator & Apple Spript
Hi there!
I need the help of an expert in Automator & Apple Spript....
I've got to rename 500 files with the following names:
001-001 firstfilename.jpg
104-095a otherfilename.jpg
Any idea on how to get rid of the second number (that is 3 or 4 characters long, but always followed by a space) so to have something like:
001 firstfilename.jpg
104 otherfilename.jpg
Thanks in advance & Ciao!
Sergio
Black MacBook Mac OS X (10.4.7)The following script should work.
IMPORTANT:
1) The files whose names you want to change must all be in the same folder. That folder must be open, and it must be the front finder window.
(Also, no other files should be in that folder)
2) Make a back-up of the files before you do this (just in case there is a problem. I hope the files are not too large)
3) This should work if the file names are consistent. I have presumed that there is always a hyphen and a space ( ) and that you wish to keep the characters before the hyphen and after the space.
4) Copy the script below into the script editor. When you have prepared 1 & 2 above then run the script. Good luck
--Start of Script
tell application "Finder"
set myFiles to every file of the front window
repeat with Cfile in myFiles
set WholeName to the name of Cfile
set AppleScript's text item delimiters to "-"
set WNlist to every text item of WholeName
set WNpart1 to first item of WNlist
set AppleScript's text item delimiters to " "
set WNlist2 to every text item of WholeName
set WNpart2 to last item of WNlist2
set NewName to WNpart1 & " " & WNpart2
set name of Cfile to NewName
end repeat
end tell
set AppleScript's text item delimiters to ""
--End of Script
MacBook Mac OS X (10.4.7) iMac G4 (10.3.9) -
Can't rename file with Applescript
Hi,
I'm a programmer but I'm new to Automator and Applescript. I am trying to rename pdf files based on a specific line of its content but I don't succeed. I created a service that exports the text from the pdf to a file. Then I use applescript to read that specific line from the file, then another applescript to rename the pdf to that string. Every step works except the rename part. When I tell Finder to rename the file it stops with the error: "The operation can't be completed because there is already an item with that name." This is not true, but I keep getting this error message no matter which file I try it with.
The odd thing is that if I set varName to some constant like
set varName to "METEOR CEE Kft..pdf"
it works like a charm. So I figured maybe
item 1 of input & ".pdf" = "METEOR CEE Kft..pdf"
is false. But that is not the case, I tested it in the script and they are equal.
What am I missing?I think that the problem is that there is a lot of invisible characters in the text file when Automator extracts a PDF to plain text (open the file in a text editor and turn on "view invisible characters", or use cat -e in Terminal)
I've gotten around this is the past by extracting to a RTF and then using textutil to convert to txt
Try this Automator Workflow:
The bash script is:
textutil -convert txt "$1" # Convert from RTF to TXT
n=$( sed -n '9 p' "${1%.*}.txt" ) # extract line 9 fron text file
mv "${1%.*}.pdf" "${1%/*}/$n.pdf" # Rename file
rm "$1" "${1%.*}.txt" # Clean-up RTF and TXT files
Maybe you are looking for
-
The Built in SharePoint 2013 Help Menu (?) on our Enterprise Farm for both the sites and Central Admin does not work. On Central Admin help the error comes back as: "Sorry, the page you're looking for can't be found". The site collections Help menu g
-
hi floks, We have created one new DSO and moved to Production system. When we did data load and try activating the request we are getting a short dump. The screen shots are attached here with. We did not face any problems in D and Q systems. Please l
-
Hi, This is a simple requirement but not sure why its getting so complicated, i have done lot of search on SDN and got the solution, but unable to execute it. Basis has created a swc in Dev SLD and i imported it into my ESR, created my objects and ex
-
Bridge loses connection after a few minutes
Hi at all, my name is Daniel and i have a problem with two AIR-SAP1532E-E-K9 with the software version 15.2(4)JB3b. The situation: Our customer want to connect two buildings with a wireless bridge, so he bought two 1532 with two AIR-ANT5114P2M-N= ant
-
In my home net with EA450 doesn't work Remote Desktop Access
Hello. Today I've bought new LinkSys EA4500. And now it is a promlem with RDP into my home network (not from outside). My iMac can't to connect to PC by RDP and so also iPad can't. The PC is working properly and at this moment I can see it by web a