Renaming files

  • Not sure whether the solution will be in  DOS or in query analyzer but for sure  help will be appreciated in renaming files as shown below Example

    renaming

    logname_2004-01-12. 300.trn should be logname3

    logname_2004-01-12. 630.trn should be logname6

    logname_2004-01-12. 1630.trn should be logname16

     

    (ie appending just the hour behind the logname )

     

    Thanks in advance

    Michael

  • Hi,

    i think the way must go over VBS Scripting, I dont know about any funktion in dos or TSQL to work so on with filenames.

     

    Kind Regards

    Michael

  •  

    First you need to determine the length of the file (DOS???  If not use Perl, VBS? JS), then you do something like the following.  I dont know how to drop the first "." but this should get you started. 

    RENAME logname*.?*.* logname.?*.*

    Then run a second command

    RENAME logname.?*.* logname.?.*

     

  • I would say use a Vbs to read the names of all the files in the directory, then just use fso object for renaming the files.

    Naveen

  • Thanks for the responses people .OnceI hit post it dawned on me that perl could be useful

     

    Michael

  • Try something like:

     

    Declare @FileFrom varchar(255),

      @FileTo varchar(255),

      @path varchar(255),

      @OutputString varchar(500)

    SELECT @path='C:\Program Files\Microsoft SQL Server\Backups\' --Or whatever your path is

    SELECT @FileFrom =@path +'logname_2004-01-12. 300.trn'

    SELECT @FileTo =@path +'logname3.trn'

    select @OutputString= 'REN ' + '"'+ @FileFrom + '"' + ' ' +'"' +@FileTo +'"'

    exec xp_cmdshell @OutputString

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply