On Oct 20, 2017, at 1:04 PM, Chip Scheide wrote:
> I want to rename a directory, from say New Folder -> New Folder too
> Move Document complains, as neither the source nor the destination are
> documents.
>
> is there another means to rename a folder other than:
>
> - Create new folder with new/changed name
> - copy all contents from source folder to destination
> - delete original
>
> -repeat for all sub directories of the original source)
>
> seems like an excessive amount of work for a change to a directory
> name.....
It is an excessive amount of work. We need a native RENAME FOLDER command or a
MOVE FOLDER command. I don’t think it makes sense to make the MOVE DOCUMENT
command also work with folders. It needs to be a separate command.
So I had to write my own RenameFolder command. Here it is Chip:
// ===========================================
// PROJECT METHOD: RenameFolder
// PARAMETERS: $0 = error message
// $1 = path to folder
// $2 = new folder name
// DESCRIPTION: Renames a folder by calling the operating system
// to do the work. If rename was successful return blank; otherwise
// return error message text.
// CREATED BY: Tim Nevels, Innovative Solutions ©2017
// DATE: 4/28/17
// LAST MODIFIED:
// ============================================
C_TEXT($0;$errorStream_t)
C_TEXT($1;$folderPath_t)
C_TEXT($2;$newFolderName_t)
$folderPath_t:=$1
$newFolderName_t:=$2
C_TEXT($destinationFolderPath_t;$command_t;$inputStream_t;$outputStream_t)
// setup environment
SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"true")
SET ENVIRONMENT VARIABLE("_4D_OPTION_BLOCKING_EXTERNAL_PROCESS";"true") //
wait for it to finish
$destinationFolderPath_t:=GetParentDirectoryPath
($folderPath_t)+$newFolderName_t
Case of
: (Test path name($folderPath_t)#Is a folder) // check if folder exists
$errorStream_t:="folder does not exist"
: (Test path name($destinationFolderPath_t)=Is a folder) // check if
destination folder name already exists
$errorStream_t:="folder already exists"
: (<>macOS)
$command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" "+GetPOSIXfilePath
($destinationFolderPath_t)
LAUNCH EXTERNAL
PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t)
Else // Windows
$command_t:="cmd.exe /C rename "+Char(Double
quote)+$folderPath_t+Char(Double quote)+" "+Char(Double
quote)+$newFolderName_t+Char(Double quote)
LAUNCH EXTERNAL
PROCESS($command_t;$inputStream_t;$outputStream_t;$errorStream_t)
End case
// return result
$0:=$errorStream_t
Tim
********************************************
Tim Nevels
Innovative Solutions
785-749-3444
[email protected]
********************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************