Add prefix to existing files using UNC path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rtk513
Posts: 2
Joined: 09 Jun 2017 10:03

Add prefix to existing files using UNC path

#1 Post by rtk513 » 09 Jun 2017 10:05

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.dat

rtk513
Posts: 2
Joined: 09 Jun 2017 10:03

Re: Add prefix to existing files using UNC path

#2 Post by rtk513 » 09 Jun 2017 10:52

Someone suggested I try this code but it failed with 'LFNFOR' is not recognized as an internal or external command, operable program or batch file.

LFNFOR On
FOR %v IN (`\\server.com\hostfiles\Export\Semaphore\assignActivities-*.dat`) DO REN %v prefix%v


I'm running from command line, can't be a batch file.

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: Add prefix to existing files using UNC path

#3 Post by elzooilogico » 10 Jun 2017 03:39

simply

Code: Select all

FOR %v IN ('dir /b /a-d "\\server.com\hostfiles\Export\Semaphore\assignActivities*.‌‌​​dat") DO REN "%v" "S%~nxv"


The ~nx modifier means file name and extension (suppresses drive name and path)

see for /? for more details about variable substitution modifiers.

Post Reply