cmd line rename syntax error - argh

  • Hi there,

    I have a SQL job that produces output.txt then I need to rename it with date suffix.

    I'm producing output.txt but I can't get the rename to work:

    ren w:\dir\output.txt w:\dir\output_%time:~0,2%%time:~3,2%-%DATE:/=%.txt

    It fails just running at cmd line with syntax error.

    It works without the w:\dir\ but for various boring reasons I can't change the access permissions or use psh or any other more useful software to do this so I have to include the path. It's driving me bonkers and I suspect the answer is dead simple but I'm not even sure what to google for!

    Please help!

    Thank you.

    🙂

  • Just remove the second "w:\dir\" from your command.

    A good search term would be "ren command syntax".

    John

  • Thanks John but I can't remove it.

    My agent job outputs to that dir as the first step. It has to output to that dir for various reasons related to my unusual env.

    The second step is the rename & i need to give it the full path for it to find the file.

    This means either running:

    cd w:\dir

    w:

    rename ....

    or

    rename w:\dir\a.txt w:\ ....

    I can't get either to work.

    Nor can I include the commands in a batch that is called from the SQL job (again for stupid env. reasons on my estate).

  • well as John Mitchell pointed out the ren command syntax found here does not allow the path of the filename as part of the second parameter.

    however, the MOVE command syntax found here will do what you want, i think, and it does allow the full path.

    move c:\Data\contents.txt c:\Data\contents44.txt

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Oh my goodness, John, you are a genius! Who knew?! Sorry I didn't properly read / think through your first post. Lowell, you are a very patient person! 🙂

    Thank you both, seriously! You've made my day.

    Have a good one.

    🙂

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

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