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
Add prefix to existing files using UNC path
Moderator: DosItHelp
Re: Add prefix to existing files using UNC path
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.
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.
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: Add prefix to existing files using UNC path
simply
The ~nx modifier means file name and extension (suppresses drive name and path)
see for /? for more details about variable substitution modifiers.
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.