file rename with store procedure

  • Hi all,

    I've files with an unix timestamp as name. For instance filename: 1081277409

    I've written a function that based on the filename returns the readable dateformat: 2004-04-06 16:50:09.000

    I've done this by reading the folder contents (xp_cmdshell) and insert the filenames into a table, wrote a convert function and based on this I get the readable dateformat.

    The last thing I need to do is to rename the file: 1081277409 to 2004-04-06 16:50:09.000 automatically.

    Is this possible with a stored procedure? I've tried SSIS file task but this won't work.

    Any tips would be highly appreciated. Thanks in advance.

  • Trestire (12/3/2013)


    Hi all,

    I've files with an unix timestamp as name. For instance filename: 1081277409

    I've written a function that based on the filename returns the readable dateformat: 2004-04-06 16:50:09.000

    I've done this by reading the folder contents (xp_cmdshell) and insert the filenames into a table, wrote a convert function and based on this I get the readable dateformat.

    The last thing I need to do is to rename the file: 1081277409 to 2004-04-06 16:50:09.000 automatically.

    Is this possible with a stored procedure? I've tried SSIS file task but this won't work.

    Any tips would be highly appreciated. Thanks in advance.

    When you say it didn't work with SSIS did you get an error message? Remember that you can't have colons : in a file name.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (12/3/2013)


    Trestire (12/3/2013)


    Hi all,

    I've files with an unix timestamp as name. For instance filename: 1081277409

    I've written a function that based on the filename returns the readable dateformat: 2004-04-06 16:50:09.000

    I've done this by reading the folder contents (xp_cmdshell) and insert the filenames into a table, wrote a convert function and based on this I get the readable dateformat.

    The last thing I need to do is to rename the file: 1081277409 to 2004-04-06 16:50:09.000 automatically.

    Is this possible with a stored procedure? I've tried SSIS file task but this won't work.

    Any tips would be highly appreciated. Thanks in advance.

    When you say it didn't work with SSIS did you get an error message? Remember that you can't have colons : in a file name.

    If you're already using xp_cmdshell to to get the filenames to convert, why not use another shell where you execute the rename commands in DOS? It's pretty straightforward, but Sean hit the nail on the head - you cannot have a colon in a filename no matter how you approach it.

  • Heh... and stop using spaces in file names. It complicates things further down the line. If you must have separation between "fields" in the file names, use underscores.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

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