Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Add prefix to existing file name using UNC path  (Read 3598 times)

0 Members and 1 Guest are viewing this topic.

rtk513

    Topic Starter


    Newbie

    • Experience: Guru
    • OS: Unknown
    Add prefix to existing file name using UNC path
    « on: June 09, 2017, 10:08:21 AM »
    I am trying to add a prefix to existing files within a UNC path. For some reason my code is changing the first character of the file name instead of appending it

    Existing file names:
    assignActivities-20170609100439.dat
    assignActivities-20170609094939.dat

    Desired file names:
    SassignActivities-20170609100439.dat
    SassignActivities-20170609094939.dat

    Command:
    REN \\server.com\hostfiles\Export\Semaphore\assignActivities-*.dat S*.dat

    Resulting file names:
    SssignActivities-20170609100439.dat
    SssignActivities-20170609094939.dat

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Add prefix to existing file name using UNC path
    « Reply #1 on: June 09, 2017, 11:09:40 AM »
    Are you sure? What OS are you using?
    I don't understand.  :(
    « Last Edit: June 09, 2017, 11:22:54 AM by Geek-9pm »

    rtk513

      Topic Starter


      Newbie

      • Experience: Guru
      • OS: Unknown
      Re: Add prefix to existing file name using UNC path
      « Reply #2 on: June 09, 2017, 11:44:59 AM »
      Windows 7, command line but this will be running from SQL Server using CmdExec.

      I'm told "REN" doesn't have an "insert" mode.

      Someone suggested the following but it doesn't work in command line;
      Code: [Select]
      LFNFOR On
      FOR %v IN (`\\server.com\hostfiles\Export\Semaphore\assignActivities-*.dat`) DO REN %v prefix%v


      'LFNFOR' is not recognized as an internal or external command,
      operable program or batch file.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Add prefix to existing file name using UNC path
      « Reply #3 on: June 09, 2017, 12:47:55 PM »
      OK. Sorry I do not use SQL  hardly ever.
      I think this what you are using...
      https://docs.microsoft.com/en-us/sql/ssms/agent/create-a-cmdexec-job-step
      Quote
      This topic describes how to create and define a Microsoft SQL Server Agent job step in SQL Server 2017 that uses an executable program or operating system command by using SQL Server Management Studio, Transact-SQL or SQL Server Management Objects.

      The rename command in Windows 7 CMD does not have an explicit insert  operator. But I think it allows you to rename a file with a longer name.

      (For simplicity, I will not use paths and extensions in the examples.)
      Say I have wanted five files named:
      ass0
      ass456
      ass4567
      ass45678

      Plus three  files a little different in the current directory
      asw456
      aws0
      aqs456

      I can use this to see of the first three letters identify the files I want
      DIR äss* /b   
      (Forum rules require me to use äas instead of *censored*.)
      Yes, it shows only the five files, not the others.
      Now I rename using
      Code: [Select]
      rem äss* Sass*(Change ä to a in above.)
      That will insert the letter S  at the start of each name.
      Is that what you want?