SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


cmd line rename syntax error - argh


cmd line rename syntax error - argh

Author
Message
snomadj
snomadj
SSC Veteran
SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)

Group: General Forum Members
Points: 294 Visits: 645
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.

Smile
John Mitchell-245523
John Mitchell-245523
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13953 Visits: 15933
Just remove the second "w:\dir\" from your command.

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

John
snomadj
snomadj
SSC Veteran
SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)

Group: General Forum Members
Points: 294 Visits: 645
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).
Lowell
Lowell
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27982 Visits: 39922
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!

snomadj
snomadj
SSC Veteran
SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)

Group: General Forum Members
Points: 294 Visits: 645
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! Smile

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

Have a good one.

Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search