Renaming file problem

hi
i'm having a problem renaming a file in java.
i'm trying to delete a string from a file and the only thing that seems rationaly to me is to search the string out take the strings before and after and concatinate them into a new file. i'm not sure if this is the best way or the easiest but it seems the most logical to me right now.
the problem now is renaming the temp file into the original file name. how do i do that properly? i've tried renameTo(); but i'm having problems with that i'm getting an invalid IO error.
Please help
Thanks a lot

Hi
I normally use a replace function that I found on this forum earlier this year. If you want to use it on a file you can do it as follows and then there is no need to work with 2 files. (You see that the string that I use for replacement is empty, so in effect it deletes the strings that you don't want.).
import java.io.*;
public class FindReplace {
public static void main (String args[]) {
try {
RandomAccessFile file = new RandomAccessFile("testfile", "rw");
String oString;
String nString;
long len = file.length();
byte[] b = new byte[(int)len];
file.readFully(b);
oString = new String(b);
nString = replace(oString, "old", "", true);
file.seek(0);
file.writeBytes(nString);
// in case the "new file" is shorter than the old one
// truncate the rest of the file, this ensures we don't
// have duplicate content at the end of the file
long nlen = file.getFilePointer();
if (nlen < len) {
file.setLength(nlen);
file.close();
} catch (IOException ioe) {
System.out.println("Error during processing: " + ioe);
public static String replace(String str, String o, String n, boolean all) {
if (str == null || o == null || o.length() == 0 || n == null)
throw new IllegalArgumentException("null or empty String");
StringBuffer result = null;
int oldpos = 0;
do {
int pos = str.indexOf(o, oldpos);
if (pos < 0)
break;
if (result == null)
result = new StringBuffer();
result.append(str.substring(oldpos, pos));
result.append(n);
pos += o.length();
oldpos = pos;
} while (all);
if (oldpos == 0) {
return str;
} else {
result.append(str.substring(oldpos));
return new String(result);
}

Similar Messages

  • Problem renaming File

    Hello,
    I have a problem about renaming file. This is the file.
    "C:\Documents and Settings\Rose 2\Desktop\download directory\5406-5473\a " . It has no extension so I need to add extension(.mp3). here's my code:
                File mFile = new File(soundFile.getParent(),"a.mp3");
                soundFile.renameTo(mFile);
                System.out.println(mFile.toString());
                if (mFile.exists()) {
                    setAudiofile(mFile);
                } else {
                    System.out.println("mFile does not exist");
                }the soundFile variable is the original file. The output of my code is nothing and I don't see a.mp3.
    Result of System.out.println(mFile .toString()) :
    C:\Documents and Settings\Rose 2\Desktop\download directory\5406-5473\a.mp3
    Thanks in advance and Happy New year!!!

    The output of my code is nothing and I don't see a.mp3.But you posted some output...
    Anyway try if (mFile.exists()) {
        System.out.println("mFile *does* exist");
        setAudiofile(mFile);
    } else {
        System.out.println("mFile does not exist");
    }What is the output?
    By the way, your code gives no hint as to what setAudiofile() does - including the possibility, albeit unlikely, that it deletes a.mp3. Rather than post a snippet excised from a longer piece of code, construct a SSCCE that illustrates renameTo() not working.
    http://homepage1.nifty.com/algafield/sscce.html

  • What is the name of the process that renames File & Folders? To fix name entry problem?

    What mac linux process found in the Activity Monitor renames files and folders? My mac is slow under mac osx 10.7.5 and nearly unusable to name files and folders since as you name them it will jump the cursor and highlight causing the name I put in to disappear. I hate this so much I'm looking at a windows box! So what process can I raise priority of to help with this severe problem?

    aaron-
    Premiere Elements 12 on Windows 7 (assumed 64 bit)
    Have you updated 12 to the 12.1 Update using an opened project's Help Menu/Update? If not, please do so.
    If you are referring to that red stem with the blue head at the Timeline level in the Expert workspace, that is indeed the Timeline Indicator (also referred to as CTI).
    To be ruled in or out at the onset...whether or not you see an orange line over the Timeline content that you are attempting to preview?
    If you (manually) or the project (automatically) have set the correct project preset, there should be no colored line
    of the source video when it is first dragged to the Timeline. That is the program telling you that you are getting
    the best possible preview. If orange, you are not and need to "Render" the Timeline content to get the best possible preview.
    Does this "Timeline Rendering" factor apply to your situation?
    If you are getting the best possible preview, we still need to know the properties of your source media ---
    video compression
    audio compression
    frame size
    frame rate
    interlaced or progressive
    pixel aspect ratio
    Often the above can be gathered from knowing brand/model/settings for the camera that recorded the video.
    Also are you observing this behavior if you start a new project or use different source media, such as, stills or videos
    recorded with a different format?
    Let us start here and then decide what next.
    Thank you.
    ATR

  • Problem in renaming file

    hi
    There are 2 files in a directory called
    js1.html
    js2.html
    i am reading from js1.html and making some modification to
    the data as i read and storing in js2.html
    finally i have to rename js2.html to js1.html
    i am using fileinputstream and fileoutputstream amd i am
    closing both before ranaming.
    I also am trying to delete js1.html before renaming
    as both are in the same dir
    The code i am using for renaming
    File old=new File("js2.html");
    old.renameTo(new File("js1.html");
    But this always returns false
    i am using win2k
    could anyone pls help me out with this
    thanks

    Just a guess but maybe it is returning false because you already havea file named js1.html. Trying doing this through Windows Explorer and it will spit out an error.
    What you should try is deleting js1.html first and then renaming. Presumably you don't need js1.html anymore once you make the changes so go ahead and delete it.

  • Rename files or folders in Windows 8 not working

    Rename a file or folder on a Windows CE device is not working from Windows 8 when connected through Windows Mobile Device Center.
    From Windows 7 it worked just fine!
    This has been a problem for a very long time now, and im not alone according to all forums.
    But no fix as far as i can find!
    Is there anyone that have found a fix on this?

    http://answers.microsoft.com/en-us/windows/forum/windows8_1-files/windows-8-unable-to-rename-files-on-pocket-pc/abae21b7-7ee1-41c7-853e-1ac7ea5b0413
    It seems a issue in window 8.x system. Maybe you can ask for a MS support ticket. 

  • Sharepoint 2013 ItemAdded event receiver for renaming files is not working

    In SP 2013 I coded an event receiver that intercepts the ItemAdded event and it just renames the file.
    It is a synchronous event (I added <Synchronization>Synchronous</Synchronization> in the Elements.xml).
    This is the code:
            public override void ItemAdded(SPItemEventProperties properties)
                SPSecurity.RunWithElevatedPrivileges(delegate()
                    try
                        OutputDebugStringA("Inside ItemAdded");
                        string szHttpUrl = properties.WebUrl + "/" + properties.AfterUrl;
                        SPWeb openedWeb = properties.Web.Site.OpenWeb(properties.Web.ID);
                        SPFile spf = openedWeb.GetFile(szHttpUrl);
                        EventFiringEnabled = false;
                        string szUrl = properties.AfterUrl;
                        szUrl = szUrl + ".renamed";
                        string szNewFileName;
                        if (szUrl.LastIndexOf('\\') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('\\') + 1);
                        else if (szUrl.LastIndexOf('/') != -1) szNewFileName = szUrl.Substring(szUrl.LastIndexOf('/') + 1);
                        else szNewFileName = szUrl;
                        if (properties.ListItem != null)
                            properties.ListItem["Title"] = szNewFileName;
                            properties.ListItem.Update();
                        spf.MoveTo(szUrl);
                        EventFiringEnabled = true;
                        base.ItemAdded(properties);
                        OutputDebugStringA("Renaming to " + szUrl);
                    catch (System.Exception exception)
                        OutputDebugStringA("ItemAdded ERROR: " + exception.ToString());
    The problem is that when I upload a .txt file using Internet Explorer, just after the renaming is done, IE says that something went wrong and when I inspect the log files I see:
    SPRequest.GetFileAndFolderProperties: UserPrincipalName=i:0).w|s-1-5-21-4050800873-4278272723-3073177257-500, AppPrincipalName= ,bstrUrl=http://sp2013/sites/demo/subsite1 ,bstrStartUrl=Shared Documents/test2.txt ,ListDocsFlags=16400 ,bThrowException=True 0fa7689c-674b-5045-c3a2-b214a5d4cbed
    01/09/2014 15:29:26.75  w3wp.exe (0x1544)                        0x16F4 SharePoint Foundation        
     General                        ai1wu Medium   System.IO.FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>,
    StackTrace:    at Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask)     at Microsoft.SharePoint.SPFile.PropertiesCore(Boolean
    throwException)     at Microsoft.SharePoint.SPFile.get_Length()     at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e)     at Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadExPage.OnSubmit(Object
    o, EventArgs e)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest(Boolean includeSta... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
    ...gesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest()     at System.Web.UI.Page.ProcessRequest(HttpContext context)     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()    
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)     at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)     at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext
    context, AsyncCallback cb)     at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
    rootedObjectsPointer, IntPtr nativeRequestContex... 0fa7689c-674b-5045-c3a2-b214a5d4cbed
    ...t, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr
    pHandler, RequestNotificationStatus& notificationStatus)     at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr
    rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)     at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) 
     0fa7689c-674b-5045-c3a2-b214a5d4cbed
    So it is clear that the fact that I renamed the file is causing an issue in the SharePoint upload logic.
    As a solution what I did was to not declare it as Synchronous, but if I do it then there is another error when Sharepoint shows the Edit Properties dialog... in this case the upload is OK but when it is time to show that Edit Property dialog IE fails and
    says that the file has been already modified, or that "something went wrong".
    If I use a synchronous event I get one problem. If I use the asynchronous event I get another problem... It's very frustating and I am pretty sure that a so important API like Event Receivers should have support renaming files so I hope someone can tell
    me what I am doing wrong.
    Thanks in advance

    May be you want to consider using the following code and see if it works for you.
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/40c78e03-2dca-4083-89d2-a7430099da68/how-do-i-change-the-name-property-of-a-file-in-a-document-library?forum=sharepointdevelopment
    Amit

  • Deleting & renaming files - is there a shortcut to finder?

    I am a recent convert from PC to Mac. So far so good. However, one thing starts to drive me up the wall which is deleting/renaming files in programs such as photoshop, word, excel etc.etc.
    As far as I can tell, this is only possible in the finder menu. Is this Correct? I am using a lot of folders and subfolders - sometimes 3-4 levels deep. Every time I need to change/delete a file or filename - lets say while in photoshop, I have to go to finder and click my way through several levels of folders to the actual file I need to change. This is somewhat annoying and timeconsuming.
    Question 1: is there a way to do these operations in - lets say photoshop directly?
    Question 2: If not, is there a shortcut key that would point me automatically to the file in finder where I can make the changes?
    Your input would be very helpful and save me some aggravation.
    fupe

    Hi Greg,
    Thanks for your input. You are correct as far as "save" and "save as" is concerned. Windows and Mac work the same way.
    However, as far as I can tell, in Mac you can only "delete" or "rename" a file in "finder" which forces you to open up finder and locate the file in order to delete or change it.
    In windows you can do these 2 functions directly in the program (such as photoshop, excel or words). You do not have to go to "explorer or root directory" to make these changes which I believe would be the equivalent of "finder".
    In any case, Terence solved the problem. By command clicking the name (title) of the file in any program, it opens up the directory in "finder". This way makes it easy to select the file and do the changes.
    fupe

  • Can't delete, rename files, or move to another folder

    I had posted earlier about not being able to delete, rename files, or move to another folder. It never was resolved here, and I guess Apple still hasn't done anything about it. Here's a great workaround I found though in case others need something. Download the program called "Unlocker", it's free and you can get it at http://ccollomb.free.fr/unlocker/ When you get the message about the file being in use, even though QuickTime isn't even open, you can unlock the f'ing file and do whatever you want to then, move, uh DELETE, or rename, or whatever. Try it, it's the best thing going so far seeing Apple isn't doing anything about this problem.

    Hi there,
    I am still struggling with this problem. Actually my coworker has the same machine, Apple pro with windows xp installed, but he does not have this problem with his quicktime 7.5. I uninstalled 7.5 and installed 7.2, but it did not solve the problem. The fact is that I don't have the problem in my laptop which I am using it in the office. I am still trouble shooting. Hopefully I can find an answer.
    Peace

  • Automator: Impossible to rename file using automator under Mac OS X Lion

    Hi,
    Before upgrade my iMac to MAC OS X Lion 10.7.2, I had service created with automator under snow leopard in order to rename my pictures file names by blocks instead of one by one. Since I'm using Lion, this one doesn't work anymore. I have completely recreate the service under Lion and the results is the same.
    You can find below my workflow that is easy. The problem is the message error in the history of automator application. The message is "impossible to rename file "file name" because this one should create conflict with existing file". I already test a lot of times with different name where I'm sure that this one doesn't exist on my Mac but all the time without success (verify also with search function under mac)
    If somebody can help me, it would be very interesting because I already tried to find answer on internet without success too.
    Thanks in advance for your help.

    the whole automator and in particular the record action was substantially rewritten in snow leopard. and the record action is slow, unreliable and you can't trouble-shoot it. it's a wonder it works at all. the only advice i can give is to use it as little as possible. if at all possible avoid it altogether. if you do need to use it try using keyboard strokes instead of the mouse movement. for example. use command+c and command+v for copying and pasting and use tabbing to choose the correct box on the page.

  • Renaming files with invalid characters in their names on NTFS partitions, introduced by operating systems other than 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.

    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.

  • Rename file name

    Hello to everyone,
    I need to change the old file name  for that I used this code ......but the problem here is..............
    normally I will get the file name is
    /interfaces/in/1601/payroll03052007
    directory
    /interfaces/in/1601                                                                 
    file name  is payroll03052007
    so the new file name starts with z ...like zpayroll03052007.....here the problem is...'z' should come before the file name.......for that how can I write the code.......
    form renamefile.                                                
       file-name-old(50) = jefile(50).                               
       v_date = sy-datum.                                            
       v_time = sy-uzeit.                                            
    concatenate: file-name-old '-' hrec-hpostdate(2) hrec-hpostdat
                                                    into file-name-
        concatenate: file-name-old  v_date v_time into file-name-new.
    Rename Input file to prevent second interface of data         
       refresh rctable.                                              
       call function 'Z_RENAME_FILE'                                 
            exporting                                                
                 source_file_name = file-name-old                    
                 target_file_name = file-name-new                    
            tables                                                   
                 rc_table         = rctable.                                                                               
    if sy-subrc = 0.                                              
         write:/  'Rename function sucessfully executed'.            
         write:/  'Renamed file from: ', file-name-old.              
         write:/  '               to: ', file-name-new.              
       else.                                                         
         write:/  'Z_Rename function could not be executed'.         
       endif.                                                        
    Thanks in advance....
    Madhu.

    You can use SXPG_COMMAND_EXECUTE. This function is used to execute operating system command and can be used to rename a operating system file. For example you can use "mv" on UNIX or "REN" on Windows systems.
    CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
      EXPORTING
        COMMANDNAME                         =
    *   ADDITIONAL_PARAMETERS               =
    *   OPERATINGSYSTEM                     = SY-OPSYS
    *   TARGETSYSTEM                        = SY-HOST
    *   DESTINATION                         =
    *   STDOUT                              = 'X'
    *   STDERR                              = 'X'
    *   TERMINATIONWAIT                     = 'X'
    *   TRACE                               =
    * IMPORTING
    *   STATUS                              =
    *   EXITCODE                            =
      TABLES
        EXEC_PROTOCOL                       =
    * EXCEPTIONS
    *   NO_PERMISSION                       = 1
    *   COMMAND_NOT_FOUND                   = 2
    *   PARAMETERS_TOO_LONG                 = 3
    *   SECURITY_RISK                       = 4
    *   WRONG_CHECK_CALL_INTERFACE          = 5
    *   PROGRAM_START_ERROR                 = 6
    *   PROGRAM_TERMINATION_ERROR           = 7
    *   X_ERROR                             = 8
    *   PARAMETER_EXPECTED                  = 9
    *   TOO_MANY_PARAMETERS                 = 10
    *   ILLEGAL_COMMAND                     = 11
    *   WRONG_ASYNCHRONOUS_PARAMETERS       = 12
    *   CANT_ENQ_TBTCO_ENTRY                = 13
    *   JOBCOUNT_GENERATION_ERROR           = 14
    *   OTHERS                              = 15
    COMMANDNAME is the logical name as defined in SXPGCOSTAB, maintained via SXPG_COMMAND_MAINTAIN function. For example you would assign ZMV for "mv" command for renaming file. In the ADDITIONAL_PARAMETERS you can given old file name and new file names

  • Open File dialog user can delete and rename files.

    Does any one know if there is a way to prevent a user from deleting and renaming files by right clicking on them in an Open File dialog box?

    Well, the problem is that this isn't a LV dialog box. It's the standard Windows file dialog box and this is the way they work in Windows.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to edit move rename files in iTunes

    how to edit move rename files in itunes

    I don't like iTunes.
    I don't want iTunes to keep the physical location of my files because they can be on a SD card, or an USB drive and i don't want iTunes to stop me from playing a song because it cannot find it anymore.
    So i would like to use physical files just to upload to iTunes Match and then delete the link to the physical file.
    If needed, iTunes Match will download the file.
    The problem is just that i would like to delete all references to physical files to make iTunes Match download the file only when needed and stop using the first version i had given to it
    maybe i could have a Apple Script to check if there is a physical file referenced and if so delete it to have only the Cloud version     

  • 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

  • Renaming files in iBooks

    I hope Apple will read this and add a feature to allow users the ability to rename files in iBooks!

    I have been renaming some picture files in Finder,
    and lately when I have been renaming them it will do
    a few fine, but then when I go to rename the next
    file I suddenly am not able enter any text in Finder
    and can rename no more files.
    I cannot offer a solution to this problem, although I can add the details of a similar situation that seems to happen to me: when I am creating new folders in Finder, after I create and name the first one, Finder no longer responds to keystrokes. Restarting Finder seems to help, but is an ugly solution to the symptom. What is the cause of this unresponsiveness?
    15" Aluminum PB 1.5ghz   Mac OS X (10.4.7)  

Maybe you are looking for

  • Old itunes songs only playing halfway on new computer

    I used to own a 2006 macbook and now have a new windows HP laptop. When I tried to transer my itunes library to the new windows computer, all of the songs DID transfer over to the new computer from the mac, however, the songs that were purchased in 2

  • Is firefox 3.6 or 4 beta compatible with windows98se?

    that is all i want to know my operating system is windows 98se i just would like to know if mozilla/firefox 3.6 or 4 beta is compatible????/

  • Open PFD from R/3 with WebDynpro for Java

    Hi All, Could any one of you please suggest on how to open a pdf from R/3 with a WebDynpro (JAVA) application. For example I was trying to display one PDF-Document from Records Management in my Web Dynpro. Does anyone have a good idea how to solve th

  • Why am I getting these lines?

    Hello everyone. I have asked this before here and was helped out very well. I have followed the same steps I was told before which worked before but for some reason is not working now. Here is a clip of a Demo I made for a client but I keep getting t

  • 20"/24" iMac hang at desktop?

    We have three 24" iMacs here at work, and one 20". The 20" and two of the 24" iMac's have hung at boot up, all at the same place. As soon as the desktop starts to load, the Spotlight magnifying glass comes up then the machine sits there and stops boo