Run Command After Sync - Possible to Use Volume Name as Part of the Path?

Get help for specific problems
User avatar
Posts: 143
Joined: 8 Mar 2017

Radish

In the Synchronisation Settings dialogue, at the bottom of the dialogue, there is an option to "Run a command after synchronisation."

I have a program, wxChecksums, that I use to generate an md5 checksums file for all the folders/files on the left-side that will be copied to the right-side of a synchronisation task. The md5 checksums file itself also gets synchronised to the right-side. I want to be able to automatically open that file on the right-side after the sync is done. So I set the "Run a command. . ." option to this:
"G:\DOCUMENTS BACKUP\- Backup.md5"
That command works.

The problem with this is that I'm having to specify an absolute path to the md5 file. What I would really like to do is be able to use the "volume name" for setting that path. The volume name for this particular drive is "USB". So I would like to do something like this:
[USB]"\DOCUMENTS BACKUP\- Backup.md5"
or (should it be):
"[USB]\DOCUMENTS BACKUP\- Backup.md5"
None of these two work. So really can someone say if there is a way of doing this?
User avatar
Posts: 2946
Joined: 22 Aug 2012

Plerry

The [USB] designator is an FFS internal one.
The Run Command After Sync is essentially an FFS external command.

But can't you solve this problem by assigning a persistent drive letter to that specific USB device?
See e.g. https://www.windowscentral.com/how-assign-permanent-drive-letter-windows-10
User avatar
Posts: 143
Joined: 8 Mar 2017

Radish

Hi, Plerry. I thought the situation might be as you describe. And the solution you offer is fine and would to some extent suit my simple needs for doing backups.

However, I can think of scenarios in which it wouldn't be fine for all users of FFS. So I would like to suggest that Zenju make it possible to use the volume name for the commands section of the Synchronisation Settings section of FFS. Basically the user puts in a command using the volume name; before issuing the command to the OS FFS parses the command looking for a volume name as part of a path; if FFS finds such a command, then it parses the path into useable from by the OS then issues the parsed command to the OS. Something like that would be a nice and useful touch to FFS.

Thanks again, though, much appreciated.
Posts: 9
Joined: 16 Aug 2019

tfa

... be able to use the "volume name" for setting that path. The volume name for this particular drive is "USB". Radish, 02 Aug 2018, 20:50
you can check under a Win command prompt the volume ID number of the drive ( as unique identifier) with

mountvol /d and getting in return a string like this:

Volume{f547cb0e-0de5-4f0c-9f7b-53375867938f}

this volume id you can parse into a command box, example below writes a small txt file into a USB drive with date & time of last sync and used instead of hard coded drive letters (that could change based on your Windows environment) this volume id that is more robust, important are the waved brackets {...} that encloses the volume id string

cmd /c echo. > "\\?\Volume{f547cb0e-0de5-4f0c-9f7b-53375867938f}\last filesync "%date%" at "%time%".txt"

I can only say it works under Windows 10/1903, other win version you might want to try

fully agree that the quite neat filesync internal variable [drive/path] would be nice thing to parse to an external command line for such case but probably good reason why they didn't want to implement this like @Plerry said
Posts: 2
Joined: 30 Jul 2025

Color

I have the same issue...

However, I have several external disks (you can never have enough backup copies!), all called "Backups" for backups in round-robin style. Therfore, I want to have a marker when the disk in front of me was used the last time for the backup. I.e. I'd like to run a command like @tfa after completion:
echo. > [Backups]\last filesync "%date%" at "%time%".txt"
Assigning a fixed drive letter or using a unique volume ID doesn't do the trick.
What I would need is a system variable ("Macro") %backupdrv% or so...
echo. > %backupdrv%\last filesync "%date%" at "%time%".txt"
User avatar
Posts: 4866
Joined: 11 Jun 2019

xCSxXenon

Can't say why, but I've written a cmd script that takes a volume name and returns a drive letter. I will attach it. As always, check random scripts/code offered on the internet. I wrote it in Windows notepad, that will suffice to open it for inspection.
It contains usage instructions and limitations, please read them, but should work fine for 99.99% of people. In another reply, I will paste the code if people wish to review it before downloading.

You can call this in your own on-completion script to get the letter and then write the info you desire to that location
Attachments
GetDriveLetterFromVolumeName.bat
(2.31 KiB) Downloaded 28 times
User avatar
Posts: 4866
Joined: 11 Jun 2019

xCSxXenon

@echo off
setlocal enabledelayedexpansion

REM A script that takes an input volume name and returns its drive letter.
REM No warranty expressed or implied, use at your own risk.

REM Usage: Call script with a volume name as a quoted parameter. Ex: GetDriveLetterFromVolumeName.bat "USB drive"
REM Add a second paramter "detailed" if you want more than just a letter returned.

REM LIMITATIONS
REM This only searches using the first 11 characters. If multiple volume names share the first 11 characters, this is unreliable.
REM If the search string contains extra spaces at the end, or vice versa, it still matches. Feature?
REM Only works on local storage.

REM Diskpart only displays the first 11 characters, so pad and truncate for easier comparison later
set volumeName=%~1
set limitedVolumeName=%volumeName%          
set limitedVolumeName=%limitedVolumeName:~0,11%

set detailed=false
IF /I "%~2"=="detailed" set detailed=true

REM Save output of DiskPart 'list vol' in file for parsing.
REM Parse file, looking for volume name. Keep first 30 characters to confirm volume name.
REM This prevents false positives in cases where a volume name is a possible value for another column.
set found=false
echo list vol | diskpart > volumes.txt
for /f "delims=" %%a in ('find /I "   %limitedVolumeName%  " volumes.txt') do (
  set volumeLine=%%a
  set volumeLine=!volumeLine:~0,30!
  IF /I "!volumeLine:~-11!"=="%limitedVolumeName%" (set found=true)
)

IF %found%==false goto volumeNotFound
REM There is an edge case if you search for "volumes.txt" but it isn't an existing volume.
REM %found% will be true, because 'findstr' also returns the file name for some reason.
REM The below conditional checks for this.
IF "%volumeLine:~0,10%"=="----------" goto volumeNotFound

REM Get the volume letter and check if it is empty
set volumeLetter=%volumeLine:~15,1%
IF "%volumeLetter%"==" " goto noLetterAssigned

REM Display result
IF %detailed%==true (
  echo "%volumeName%" has assigned letter: %volumeLetter%
) else (
  echo %volumeLetter%
)
goto end

:noLetterAssigned
echo.
echo Volume name found but it has no assigned letter.
echo It may be mounted using a mountpoint?
goto end

:volumeNotFound
echo.
echo Volume name not found. Search is not case-sensitive, but check for typos
goto end

:end
del volumes.txt
Posts: 2
Joined: 30 Jul 2025

Color

Thanks for the script!

But I think FreeFileSync should export the drive letter in an environment variable in the first place. I mean, FFS has the info, and whatever you want to do with the copied files afterwards you need the destination drive letter. I was surprised how many variables FFS exports – and IMHO is missing the most basic one.