Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

cmd line rename syntax error - argh Expand / Collapse
Author
Message
Posted Thursday, April 25, 2013 4:27 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 3:31 AM
Points: 79, Visits: 430
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.

:)
Post #1446393
Posted Thursday, April 25, 2013 4:41 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:46 AM
Points: 5,369, Visits: 9,905
Just remove the second "w:\dir\" from your command.

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

John
Post #1446401
Posted Thursday, April 25, 2013 5:17 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 3:31 AM
Points: 79, Visits: 430
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).


Post #1446419
Posted Thursday, April 25, 2013 5:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:57 PM
Points: 12,917, Visits: 32,083
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1446429
Posted Thursday, April 25, 2013 5:47 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 3:31 AM
Points: 79, Visits: 430
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.

:)
Post #1446434
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse