1.

Solve : Add prefix to existing file name using UNC path?

Answer»

I am trying to add a prefix to existing files within a UNC path. For some reason my code is changing the first character of the file name instead of appending it

Existing file names:
assignActivities-20170609100439.dat
assignActivities-20170609094939.dat

Desired file names:
SassignActivities-20170609100439.dat
SassignActivities-20170609094939.dat

Command:
REN \\server.com\hostfiles\Export\Semaphore\assignActivities-*.dat S*.dat

Resulting file names:
SssignActivities-20170609100439.dat
SssignActivities-20170609094939.datAre you sure? What OS are you using?
I don't understand.  Windows 7, command line but this will be running from SQL Server using CmdExec.

I'm told "REN" doesn't have an "insert" mode.

Someone suggested the following but it doesn't work in command line;
Code: [Select]LFNFOR On
FOR %v IN (`\\server.com\hostfiles\Export\Semaphore\assignActivities-*.dat`) DO REN %v prefix%v

'LFNFOR' is not recognized as an internal or EXTERNAL command,
operable program or batch file.OK. Sorry I do not use SQL  hardly ever.
I think this what you are using...
https://docs.microsoft.com/en-us/sql/ssms/agent/create-a-cmdexec-job-step
Quote

This topic describes how to create and define a Microsoft SQL Server Agent job step in SQL Server 2017 that uses an executable program or operating system command by using SQL Server Management STUDIO, Transact-SQL or SQL Server Management OBJECTS.

The rename command in Windows 7 CMD does not have an explicit insert  operator. But I think it allows you to rename a file with a longer name.

(For simplicity, I will not use paths and extensions in the EXAMPLES.)
Say I have wanted five files named:
ass0
ass456
ass4567
ass45678
Plus three  files a little different in the current directory
asw456
aws0
aqs456
I can use this to see of the first three letters identify the files I want
DIR äss* /b   
(Forum rules require me to use äas instead of *censored*.)
Yes, it shows only the five files, not the others.
Now I rename using
Code: [Select]REM äss* Sass*(Change ä to a in above.)
That will insert the letter S  at the start of each name.
Is that what you want?






Discussion

No Comment Found