Advanced applescript to rename files

Hi Everybody,
I am trying to do some applescript to rename files.
I know some tips to do that, but I try to write an advanced script with many options
For example : A file to rename :
"project-test.info.jpg"
1st :
I would like the script to find every symbols in the name(without the extension), like here : "-" or "_"
and repace these symbols with another one like "_"
then the new name will be :
"project_test_info.jpg"
2nd :
if the file is named in a "wrong way", like :
test.jpg
or
"test-info.jpg"
or
"project.test.jpg"
etc
then the script will rename in the better way :
"project_test_information.jpg"
(information will be data I will enter by myself)
And many other or examples with all the possibilities to rename...
I succeed to rename some parts of the name, but I don't find the solution to replace symbols, and how to count the number of text parts and replace the good ones...
I dont know even if it's a good way to do like that in fact, an maybe it's possible in another way ?
Thank you very much for your answers !

Hi Everybody,
I am trying to do some applescript to rename files.
I know some tips to do that, but I try to write an advanced script with many options
For example : A file to rename :
"project-test.info.jpg"
1st :
I would like the script to find every symbols in the name(without the extension), like here : "-" or "_"
and repace these symbols with another one like "_"
then the new name will be :
"project_test_info.jpg"
2nd :
if the file is named in a "wrong way", like :
test.jpg
or
"test-info.jpg"
or
"project.test.jpg"
etc
then the script will rename in the better way :
"project_test_information.jpg"
(information will be data I will enter by myself)
And many other or examples with all the possibilities to rename...
I succeed to rename some parts of the name, but I don't find the solution to replace symbols, and how to count the number of text parts and replace the good ones...
I dont know even if it's a good way to do like that in fact, an maybe it's possible in another way ?
Thank you very much for your answers !

Similar Messages

  • Automator/Applescript to Rename files when dropped in folder based on parent folder name

    When a file is dropped in a folder ( ParentFolder/Folder/File.pdf )
    I want to rename the file to ParentFolder_Folder_01.pdf
        --Get folder
        --Get ParentFolder
        --Check for next available number and use it.
        If ParentFolder_Folder_01.pdf exists, try _02
    I automator, I have chosen folder action
    Added 'Get selected finder items'
    I have attempted to modify another sript I found here to no avail.
    on run {input, parameters}
        tell application "Finder"
            set theFolder to input as string
            set theNameOfFolder to name of folder theFolder
            set theFiles to every file in folder theFolder
            set theFolders to every folder in folder theFolder
            my ProcessFiles(theNameOfFolder, theFiles)
            my ProcessFolders(theFolders)
        end tell
    end run
    to ProcessFolders(theFolders)
        tell application "Finder"
            repeat with thisFolder in theFolders
                set theNameOfFolder to name of thisFolder
                set theFiles to every file in thisFolder
                set theFolders to every folder in thisFolder
                my ProcessFiles(theNameOfFolder, theFiles)
                my ProcessFolders(thisFolder)
            end repeat
        end tell
    end ProcessFolders
    to ProcessFiles(NameOfOuterFolder, theFiles)
        tell application "Finder"
            repeat with thisFile in theFiles
                set theSuffix to my grabSuffixOfFile(name of thisFile)
                set name of thisFile to NameOfOuterFolder & "_" & theSuffix
            end repeat
        end tell
    end ProcessFiles
    to grabSuffixOfFile(theFile)
        set text item delimiters to "_"
        return (text item 2 of theFile)
        set text item delimiters to ""
    end grabSuffixOfFile

    Normally it is a bad idea to do things with items that are in the attached folder (earlier OS versions will retrigger folder actions when an item is renamed, for example), and you don't need to use a Get Selected Finder Items action since the dropped items are already passed to your workflow (also note that the input items will be a list).
    It looks like you are trying to use multiple passes to add on the folder names, but you will have less of a headache if you build the base name and just deal with the number suffix.  If I understood your naming scheme correctly, the following script should do the trick - it isn't very fast, but should be OK for a few items at a time.
    on run {input, parameters} -- rename input Finder items (aliases) to name of containing folders
      set divider to "_" -- the divider character between name pieces
      set output to {} -- the result to pass on to the next action
      set counter to "01" -- start suffix at one
      repeat with anItem in the input -- step through each item in the input
      set anItem to contents of anItem -- dereference
      tell application "Finder" to if class of item anItem is document file then -- don't mess with folders or applications
      set {itemParent, itemExtension} to {container, name extension} of anItem
      if itemExtension is not "" then set itemExtension to "." & itemExtension
      set grandParentName to name of container of itemParent
      set parentName to name of itemParent
      set newName to grandParentName & divider & parentName & divider & counter
      set documentNames to my getExistingNames(itemParent)
      repeat while newName is in documentNames -- increment counter suffix as needed
                                            set counter to text -2 thru -1 of ("0" & (counter + 1))
      set newName to grandParentName & divider & parentName & divider & counter
      end repeat
      set name of anItem to (newName & itemExtension)
      set end of output to anItem -- alias still refers to the same file even after renaming
      end if
      end repeat
      return the output
    end run
    to getExistingNames(someFolder) -- get base document names (no extensions) from a folder
      set nameList to {}
      tell application "Finder" to repeat with aFile in (get document files of someFolder)
      set {fileName, fileExtension} to {name, name extension} of aFile
      if fileExtension is not "" then set fileExtension to "." & fileExtension
      set fileName to text 1 thru -((count fileExtension) + 1) of fileName -- just the name part
      set end of nameList to fileName
      end repeat
      return nameList
    end getExistingNames

  • Using AppleScript to rename file as current date

    Hi, I created a script to record a radio show on a daily basis.
    I would like apple script to set the name of the files as the day´s date.
    any help would be appreciated,
    Thank you very much

    Once you've got a file name and path in the Finder, you can use this:
    tell application "Finder"
    set name of file "path:to:file" to (month of (current date)) & " " & day of (current date) & ", " & year of (current date) as string
    end tell
    (14444)

  • 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

  • How to rename files by folder name in applescript

    Hi,
    I need to be able to rename files within a folder to the folder name. I have a work flow and script that allows me to find the files within a folder, enter a new file name and starting sequence number in tow seperate dialogue boxes. What I want to be able to achieve is to rename the files without manually entering the name... I still want to be able to manually enter the number.

    Use code such as:
    tell application "Finder"
    set the_folder to (choose folder)
    repeat with this_file from 1 to (count (get files of the_folder))
    set name of file this_file of the_folder to (name of the_folder) & " " & this_file
    end repeat
    end tell
    replacing the last this_file on the fourth line with the variable which contains the number.
    (104354)

  • Need a script to do the following... rename files based on folder name...

    Hi. Macophile just starting to tread the waters of Applescript, trying to use Automator but don't think it will do what I need.
    I have many images stored with-in folders that I would like to extrapolate a given number of characters from the folder name and Add Text to the files within those given folders.
    Basically...
    Folder name is C00100_Descriptive
    Files within folder are just Descriptive_01, Descriptive_02
    Would like to make all files within a given folder take the first 7 characters from the folder and Add that text to all files and files within subfolders of that folder to make the resulting files shown as...
    C00100Descriptive01
    C00100Descriptive02
    Along with this I would also like to incorporate into the script, an added step to create Thumbnail jpegs of the image files in a Subfolder under C00100_Descriptive folder.
    I can see how to do that in automator but not specifying parameters such as taking a certain number of characters from the folder the file resides in and adding that selected text to the files.
    Ideally I would like a droplet or something that I could take a bunch of folders and drop them on the droplet to perform these actions.
    Any advice, help or guidance would be really helpful! Thanks in advance.

    Awesome, you're quite welcome, glad to hear it worked for ya!! Here's another version of the script that will rename the thumb files as jpg...
    <pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
    title="Copy this code and paste it into your Script Editor application.">on run
    set theItems to choose folder with multiple selections allowed
    open (theItems)
    end run
    on open (itemList)
    repeat with anItem in itemList
    set theInfo to info for anItem
    --VERIFY THAT THE OPENED ITEM IS A FOLDER
    if folder of theInfo and not package folder of theInfo then
    --SET PATH TO THE FOLDER
    set theFolder to POSIX path of anItem
    --GET FIRST PART OF FOLDER NAME
    set folderNameStart to do shell script "echo " & ¬
    quoted form of (name of theInfo) & "|awk -F'_' '{print $1}'"
    --GET ALL FILE NAMES
    set fileList to list folder anItem without invisibles
    --PROCEED IF FOLDER NOT EMPTY
    if fileList is not {} then
    --SET PATH TO THUMBNAIL FOLDER
    set thumbFolder to theFolder & "_thumbs/"
    --CREATE FOLDER IF IT DOESN'T ALREADY EXIST
    try
    do shell script "mkdir " & quoted form of thumbFolder
    end try
    --PROCESS FILES
    repeat with fileName in fileList
    --SET PATH TO CURRENT FILE
    set oldFile to theFolder & fileName
    --PROCEED IF FILE IS NOT A FOLDER
    set oldFileInfo to info for POSIX file oldFile
    if not folder of oldFileInfo then
    --SET NEW FILE AND THUMB FILE PATHS
    set newFileName to folderNameStart & "_" & fileName
    set newFile to theFolder & newFileName
    set theExt to name extension of oldFileInfo
    set thumbName to text 1 through -((length of theExt) + 1) of newFileName & "jpg"
    set thumbFile to thumbFolder & "thumb_" & thumbName
    --RENAME FILE
    do shell script "mv " & quoted form of oldFile & space & ¬
    quoted form of newFile
    --CREATE THUMBNAIL
    --REPLACE '128' WITH MAX HEIGHT OR WIDTH OF THUMB
    try
    do shell script "sips -s format jpeg -s dpiHeight 72 -s dpiWidth 72 -Z 128 " & ¬
    quoted form of newFile & " --out " & quoted form of thumbFile
    end try
    end if
    end repeat
    end if
    end if
    end repeat
    end open</pre>

  • Need to rename files parsing date formats in the filename [SOLVED]

    Godaddy changed the naming scheme of their server logs again.  I need some perl or something magic that will convert format A to format B.  Doing this is bash is going to be painful so I'm hoping some of your perl or python ninjas out there could help me.
    format A:  ex20140425000001.log
    format B: Wed, May 21, 2014.log
    So for the example above, that date needs to be converted to this name: ex20140521000001.log
    Thanks in advance!
    EDIT: nevermind... forgot about date.
    #!/bin/bash
    for i in *.log; do
    fixeddate="$(echo $i | sed -e 's/,//g' -e 's/^....//' -e 's/.log//')"
    useitdate="$(date -d "$fixeddate" +%Y%m%d%H%M%S)"
    newname="ex$useitdate.log"
    mv "$i" "$newname"
    done
    Last edited by graysky (2014-06-07 09:41:59)

    sempervirent,
    You're asking for some pretty advanced file naming. Most people aren't going to need that sort of function, so I doubt there will be a hook into Aperture to do such a thing. I suggest using a shell script or Applescript along with EXIFTool to rename files before you import them into Aperture. http://www.sno.phy.queensu.ca/~phil/exiftool/
    Retain the unique number that the image already has
    If you're not afraid of the command line, it's easy enough to use a tool like awk or maybe perl to parse that sequence number from a well-formatted string like the picture name
    Replace "DSC" with the camera model (D3X)
    You can use EXIFTool to extract the camera model from the EXIF dat ain the photos
    Add a digit prior to the four-digit string to indicate the true numeric sequence of the file.
    Good luck with this one. You'll have to do a filename search through all of your previous files to find out what 10,000 you're on. It's possible, but you'd have to do some specialized coding in AppleScript or shell script.
    nathan

  • Rename files and retain portions of the original filename

    I posted a thread about this a while ago, but no solution was given:
    http://discussions.info.apple.com/thread.jspa?threadID=2564646
    The issue is this: I can't figure out how to rename imported files while also retaining part of the original filename. The images come off of the camera like this:
    DSC_3497.nef
    I need to do the following:
    +- Retain the unique number that the image already has. I don't want to rename the files by date, location, lunar phase, or some other esoteric identifier. I think having a unique ID for each image (one that shows up in standard OS-level searches on both Mac and PC systems) is useful.+
    +- Replace "DSC" with the camera model (D3X), since I use multiple cameras with different resolutions and also need to be able to search for images from a certain camera outside of Aperture (i.e. tags/keywords would not help).+
    +- Add a digit prior to the four-digit string to indicate the true numeric sequence of the file. Since Nikon cameras reset the number sequence every 10,000 files, I want to indicate the true sequence number directly in the filename. This will also avoid filename overlaps. It also lets me know how many images I've shot with each camera.+
    The intended final result would look like this:
    D3X_63497.nef
    Showing the 63,497th image taken with my D3X.
    In Aperture's "File Naming" dialog, I don't see a way to split the existing filename in this way. It looks like I can only append or prepend a Custom Name to the Version/Master name. I don't see a way to split the existing filename at the underscore, for example, so that portions of the original filename can be selectively replaced.
    This is not about finding a workable naming scheme for Aperture and then renaming all existing files. I spend time on the PC side for various things and also work with a number of people who don't use Aperture but need access to my image library. I also have hundreds of references to existing filenames in various print and web design projects, as well as my Flickr account with 3000+ photos.
    Going back and updating all that stuff is not going to happen. But using a System Service to rename files after every import is also pretty tedious.
    Any solutions that meet the three criteria outlined above would be greatly appreciated.

    sempervirent,
    You're asking for some pretty advanced file naming. Most people aren't going to need that sort of function, so I doubt there will be a hook into Aperture to do such a thing. I suggest using a shell script or Applescript along with EXIFTool to rename files before you import them into Aperture. http://www.sno.phy.queensu.ca/~phil/exiftool/
    Retain the unique number that the image already has
    If you're not afraid of the command line, it's easy enough to use a tool like awk or maybe perl to parse that sequence number from a well-formatted string like the picture name
    Replace "DSC" with the camera model (D3X)
    You can use EXIFTool to extract the camera model from the EXIF dat ain the photos
    Add a digit prior to the four-digit string to indicate the true numeric sequence of the file.
    Good luck with this one. You'll have to do a filename search through all of your previous files to find out what 10,000 you're on. It's possible, but you'd have to do some specialized coding in AppleScript or shell script.
    nathan

  • Software to Rename Files is OS 10.5.2

    Does anyone know a program that will rename files: specifically I am looking to remove "_" from a bunch of files; for example "File_Name" > "File Name". Thanks in advance!

    It is very easy to make an Automator workflow to do this.
    There is also an AppleScript in /Applications/AppleScript/Example Scrips/Finder Scripts. If you run AppleScript Utility, you can put a script menu in the menu bar that includes the example scripts.

  • How to open renamed files?

    Hi
    I rename selected files and after that want to open them.
    For my purpose renaming works well like this:
    tell application "Finder"
    set FilesToRENAME to selection
    display dialog "Change what?" default answer ""
    set ChangeFROM to text returned of the result
    display dialog "Change to?" default answer ""
    set ChangeTO to text returned of the result
    set AppleScript's text item delimiters to {ChangeFROM}
    set theCount to count of FilesToRENAME
    repeat with x from 1 to theCount
    try
    set theName to name of item x of FilesToRENAME
    set FirstNamePart to first text item of theName
    set LastNamePart to second text item of theName
    set newName to FirstNamePart & ChangeTO & LastNamePart
    set name of item x of FilesToRENAME to newName
    on error errStr number theNumber
    activate
    display dialog "Error in changing the Name " & theNumber & return & errStr ¬
    & return & "Step " & x
    end try
    end repeat
    set AppleScript's text item delimiters to ""
    end tell
    Now newly renamed files don't belong anymore to FilesToRENAME. So how to point to those files now (how to make a new list from those renamed files)? I was thinking to get a path to each file inside the repeat loop and replace the name, but couldn't do it.
    Thank you for any help.
    Vera

    Pierre's method is pretty clever, but if you don't happen to be using a Finder selection (choose file for example), you can also use the interesting fact that an alias keeps track of an item even if it is moved or renamed.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    -- tell application "Finder" to set filesToRename to selection as alias list
    set filesToRename to (choose file with multiple selections allowed)
    set changeFrom to text returned of (display dialog "Change what?" default answer "")
    set changeTo to text returned of (display dialog "Change to?" default answer "")
    set renamedFiles to {} -- this will be the renamed files
    repeat with aFile in filesToRename
    set aFile to the contents of aFile
    tell application "Finder" to set theName to name of aFile
    try
    set tempTID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {changeFrom}
    set firstNamePart to first text item of theName
    set lastNamePart to second text item of theName
    set AppleScript's text item delimiters to tempTID
    set newName to firstNamePart & changeTo & lastNamePart
    tell application "Finder"
    set name of aFile to newName -- aFile points to the original file
    update aFile -- give Finder a chance to catch up
    set the end of renamedFiles to aFile -- aFile now points to the renamed file
    end tell
    on error errStr number theNumber
    activate me
    display alert "Error " & theNumber & " in changing the Name" message errStr
    end try
    end repeat
    renamedFiles --> aliases to the renamed files
    </pre>

  • Renaming Files In 2-Number-Steps ... how to? (w. or w/o Automator)

    Dear all,
    I have Mac OS X Yosemite 10.10 and a question: I have a 2-pages-per-sheet-PDF-document. I exported the file as single .jpgs in my Adobe Acrobat 11 program. Now I have 10 sheets (20 pages) as jpg. I want to batch crop them with Photo Batch for Mac which is not my problem. I now have 10 left pages (1-3-5-7-9-...) and 10 right pages (2-4-6-8-...).
    I made the left - hand - pages first, they are now 001.jpg, 002.jpg, 003.jpg etc.
    I thence made the right - hand - pages, they are now 011.jpg, 012.jpg, 013.jpg, etc.
    Now I could rearrange everything in one single PDF with 20 pages / 20 sheets, but then I had to manually sort everything in the right way. I need help for the following:
    How can I batch rename a heap of files to odd numbers in ascending order?
    How can I batch rename a heap of files to even numbers in ascending order?
    Then I could just hit the merge button in Acrobat and did not have to sort everything in Adobe :-)
    Thanks for help!
    Yours truly Holger Rogoll

    Hi,
    Use this AppleScript to rename JPEG's files:
    set tFolder to choose folder with prompt "Select the folder which contains JPEG's file"
    tell application "Finder"
        set jpegs to document files of tFolder whose name extension is "jpg"
        set tc to (count jpegs) div 2
        set tmpF to make new folder at tFolder
        set rJpegs to move items (tc + 1) thru -1 of jpegs to tmpF -- move  right - hand - pages to new folder ( to avoid name conflict when renaming)
        set j to (tc * 2) - 1
        repeat with i from tc to 2 by -1 -- rename left, skip the first item because the name of the first JPEG is OK
            set name of item i of jpegs to (text -3 thru -1 of ("00" & j)) & ".jpg"
            set j to j - 2
        end repeat
        set j to 2
        repeat with i from 1 to (tc - 1) -- rename right, skip the last item because the name of the last JPEG is OK
            set name of item i of rJpegs to (text -3 thru -1 of ("00" & j)) & ".jpg"
            set j to j + 2
        end repeat
        move document files of tmpF to tFolder -- move  right - hand - pages to the original folder
        delete tmpF -- delete the created folder
    end tell

  • 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.

  • How can I automatically rename files based on an excel doc?

    I am a scientist and recieve data files from some of my experiments with arbitrary, computer-generated names. For example, if I perform an experiment with four samples, which I name Sample1, Sample2, Sample3, and Sample4, I get back 4 data files named J30935D05.ab1, J30935E05.ab1, J30935F05.ab1 and J30935G05.ab1 along with an Excel doc that lists my names for the samples (sample1, sample 2, etc.) in one column and the computer-generated names for their corresponding files (J30935D05.ab1, J30935E05.ab1, etc.) next to them in another. Therefore, I must open the Excel file and look up which file corresponds to which sample before I can begin processsing my data. Usually these experiments involve a large enough number of samples (70-100 or so) such that looking everything up in the Excel doc gets very tedious and is quite time-consuming. Is there any way to create an automator workflow, applescript, or some other solution to rename these files based on the Excel doc? To clarify, I would like an automator workflow that would take a folder of arbitrarily named files, look up the names I have for the samples in the Excel doc, and rename the files accordingly. In the example, my folder containing files J30935D05.ab1, J30935E05.ab1, J30935F05.ab1 and J30935G05.ab1 would be turned into a folder containing the files renamed as Sample1.ab1, Sample2.ab1, Sample3.ab1, and Sample4.ab1. This example is a bit simplified, however, and trying a simple trick of just systematically renaming files within the folder would not work--both the original and the new file names must be looked up in the Excel doc, as these change dramatically from experiment to experiment. I would also need to maintain the file extension on each file after being renamed. Any help would be greatly appreciated!!

    Try the freeware utility Renamer4Mac (VersionTracker or MacUpdate).
    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.

  • 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

  • Using Automator to Rename Files

    I can't figure out how to rename files so that the number in the name is in parentheses. For example Dog 1.jpg should be changed to Dog (1).jpg. How can I accomplish this in Automator?

    ok. the following should work. paste it into AppleScript Editor. select the files you want to rename in finder and press "run" in script editor. you might want to test it on a small number of files first.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder"
    set selected_items to selection
    repeat with this_item in selected_items
    set current_name to name of this_item as text
    set current_extension to name extension of this_item
    set length_extension to length of current_extension
    set name_no_ext to text 1 thru (-length_extension - 2) of current_name
    set AppleScript's text item delimiters to " "
    if (number of text items of name_no_ext > 1) then
    set z to last text item of name_no_ext --get the number at the end of the name before the extension
    set name of this_item to do shell script "echo " & quoted form of current_name & "|sed 's/" & z & "." & current_extension & "/(" & z & ")." & current_extension & "/'"
    end if
    set AppleScript's text item delimiters to ""
    end repeat
    end tell</pre>

Maybe you are looking for

  • Truncation of Heading characters when an ALV is exported to an excel sheet

    Hi All, I am facing a problem while printing an ALV output on to an excel sheet. In the header the last characters are being truncated in the excel. Now, I have the entire data in tb_output itab. So using REUSE_ALV*, i printed the output. Here comes

  • Returning to a page in JSP

    Hi, Please advise about the following: I have a JSP page (let's call it oldpage.jsp ) with form. After submitting the form I want to switch to another JSP page. How can I do this? Please notice that I can not use: <form name="..." action="newpage.jsp

  • Construing a report writer with a table of client - Table YSCO_BASE_ALOCAC

    I am construing a report writer with a table of client - Table YSCO_BASE_ALOCAC When I definition the library, the message is show... Table YSCO_BASE_ALOCAC is not installed in Report Writer. Message no. GR 493 Diagnosis The Report Writer can only re

  • Bapi fm or idoc strucher for tcode VA41

    Hi, Can any one help me...i want Bapi fm or idoc strucher for tcode VA41. Sales Document Type Sales Organization Distribution Channel Division Sold-to-Party Contract Start Date Contact End Date Material Number Order Quantity Sale Doucment Item Sales

  • Return False?

    Me again.. think my logics wrong here... I have an array, and can be any length, so i cant hard code the loop. I need to check if all the values are 0 and if they are return true, else return false... so i thought of using a count, and if the count w