Re: v13 - Renaming a Directory via code.

2017-10-24 Thread James Crate via 4D_Tech
On Oct 20, 2017, at 5:40 PM, Tim Nevels via 4D_Tech <4d_tech@lists.4d.com> 
wrote:
> 
> On Oct 20, 2017, at 4:30 PM, Chip Scheide <4d_o...@pghrepository.org> wrote:
> 
>>> $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
>> had trouble here -
>> apparently 4D's (v13) Convert path system to POSIX command - fails to 
>> do what it is advertised to do.
>> Fortunately I had a routine already written to do this.
> 
> That’s exactly why I wrote my own. I use the 4D Convert path system to POSIX 
> command but then Replace String for all spaces to “\ “. That seems to make it 
> work. 

Rather than escaping spaces (and all other characters that may cause problems 
when used in a command), you could just escape double-quotes, and enclose the 
path name in double-quotes when building the command for LEP. 

I haven’t tested the 4D Convert path system to POSIX command to see if it 
escapes double-quotes, I would just tell the users not to use quotes in their 
file/folder names.

Jim Crate

**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-23 Thread Chip Scheide via 4D_Tech
follow up on this:
Code :

  //utl_file_Convert_to_Posix
  // $1 - text - Path to convert

  //original :  
  //JorgeChB 2012-05-30   pathToUnix
  //JorgeChB 2015-02-05

  //Converts a Mac file path to a Posix form

  //RETURNS - text - converted path
  // • Created 3/24/15 by Chip - 
C_TEXT($Path;$Path)

$Path:=$1

$Path:=Replace string($Path;"/";"__-sLaSh-__")  //'a/b' -> 
'a__-sLaSh-__b'
$Path:=Replace string($Path;":";"/")  //'a:b' -> 'a/b'
$Path:=Replace string($Path;"__-sLaSh-__";":")  //'a__-sLaSh-__b' -> 
'a:b'
$Path:=Replace string($Path;"\\";"")  //'a\\b' -> 'a\\b'"
$Path:=Replace string($Path;" ";"\\ ")  //'a b' -> 'a\ b'
$Path:=Replace string($Path;"*";"\\*")  //'a*b' -> 'a\*b'
$Path:=Replace string($Path;"'";"\\'")  //'a'b' -> 'a\'b'
$Path:=Replace string($Path;"&";"\\&")  //'a' -> 'a\'
$Path:=Replace string($Path;"\"";"\\\"")  //'a"b' -> 'a\"b'
$Path:=Replace string($Path;"(";"\\(")  //'a(b' -> 'a\(b'
$Path:=Replace string($Path;")";"\\)")  //'a)b' -> 'a\)b'

$0:="/Volumes/"+$Path

On Fri, 20 Oct 2017 19:02:53 -0400, Chip Scheide via 4D_Tech wrote:
> Ill post mine on Monday. I got it from Jorge I think
> 
>> On Oct 20, 2017, at 4:30 PM, Chip Scheide 
>> <4d_o...@pghrepository.org> wrote:
>> 
  $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
>>> had trouble here -
>>> apparently 4D's (v13) Convert path system to POSIX command - fails to 
>>> do what it is advertised to do.
>>> Fortunately I had a routine already written to do this.
>> 
>> That’s exactly why I wrote my own. I use the 4D Convert path system 
>> to POSIX command but then Replace String for all spaces to “\ “. 
>> That seems to make it work. 
>> 
>> Tim
>> 
>> 
>> Tim Nevels
>> Innovative Solutions
>> 785-749-3444
>> timnev...@mac.com
>> 
>> 
>> 
> 
> Hell is other people 
>  Jean-Paul Sartre
> **
> 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:4d_tech-unsubscr...@lists.4d.com
> **
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Keisuke Miyako via 4D_Tech
if you don't mind using a plugin, perhaps as a stop gap measure:

https://github.com/miyako/4d-plugin-rename



**
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:4d_tech-unsubscr...@lists.4d.com
**

RE: v13 - Renaming a Directory via code.

2017-10-20 Thread Stephen J. Orth via 4D_Tech
Obviously I misspoke about the BAT file, you can directly call the cmd.exe 
command using the syntax outline...

My apologies.


Steve


-Original Message-
From: 4D_Tech [mailto:4d_tech-boun...@lists.4d.com] On Behalf Of Stephen J. 
Orth via 4D_Tech
Sent: Friday, October 20, 2017 6:27 PM
To: '4D iNug Technical' <4d_tech@lists.4d.com>; timnev...@mac.com
Cc: Stephen J. Orth <s.o...@the-aquila-group.com>
Subject: RE: v13 - Renaming a Directory via code.

If you only work on Windows (like me) you can take advantage of a Windows DOS 
command by creating a batch file with the following:

 SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"TRUE")
 LAUNCH EXTERNAL PROCESS("cmd.exe /C rename "+$dir_current+" "+$dir_rename)

You just need to account for any spaces in the path names, since they will need 
to be placed inside double quotes.

Very simply, very fast...


Steve


**
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:4d_tech-unsubscr...@lists.4d.com
**

RE: v13 - Renaming a Directory via code.

2017-10-20 Thread Stephen J. Orth via 4D_Tech
If you only work on Windows (like me) you can take advantage of a Windows DOS 
command by creating a batch file with the following:

 SET ENVIRONMENT VARIABLE("_4D_OPTION_HIDE_CONSOLE";"TRUE")
 LAUNCH EXTERNAL PROCESS("cmd.exe /C rename "+$dir_current+" "+$dir_rename)

You just need to account for any spaces in the path names, since they will need 
to be placed inside double quotes.

Very simply, very fast...


Steve


-Original Message-
From: 4D_Tech [mailto:4d_tech-boun...@lists.4d.com] On Behalf Of Chip Scheide 
via 4D_Tech
Sent: Friday, October 20, 2017 6:03 PM
To: timnev...@mac.com
Cc: Chip Scheide <4d_o...@pghrepository.org>; 4d_tech@lists.4d.com
Subject: Re: v13 - Renaming a Directory via code.

Ill post mine on Monday. I got it from Jorge I think

> On Oct 20, 2017, at 4:30 PM, Chip Scheide <4d_o...@pghrepository.org> wrote:
> 
>>>  $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
>> had trouble here -
>> apparently 4D's (v13) Convert path system to POSIX command - fails to 
>> do what it is advertised to do.
>> Fortunately I had a routine already written to do this.
> 
> That’s exactly why I wrote my own. I use the 4D Convert path system 
> to POSIX command but then Replace String for all spaces to “\ “. 
> That seems to make it work. 
> 
> Tim
> 
> 
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> timnev...@mac.com
> 
> 
> 

Hell is other people 
 Jean-Paul Sartre
**
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:4d_tech-unsubscr...@lists.4d.com
**

**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Chip Scheide via 4D_Tech
Ill post mine on Monday. I got it from Jorge I think

> On Oct 20, 2017, at 4:30 PM, Chip Scheide <4d_o...@pghrepository.org> wrote:
> 
>>>  $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
>> had trouble here -
>> apparently 4D's (v13) Convert path system to POSIX command - fails to 
>> do what it is advertised to do.
>> Fortunately I had a routine already written to do this.
> 
> That’s exactly why I wrote my own. I use the 4D Convert path system 
> to POSIX command but then Replace String for all spaces to “\ “. 
> That seems to make it work. 
> 
> Tim
> 
> 
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> timnev...@mac.com
> 
> 
> 

Hell is other people 
 Jean-Paul Sartre
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Tim Nevels via 4D_Tech
On Oct 20, 2017, at 4:30 PM, Chip Scheide <4d_o...@pghrepository.org> wrote:

>>  $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
> had trouble here -
> apparently 4D's (v13) Convert path system to POSIX command - fails to 
> do what it is advertised to do.
> Fortunately I had a routine already written to do this.

That’s exactly why I wrote my own. I use the 4D Convert path system to POSIX 
command but then Replace String for all spaces to “\ “. That seems to make it 
work. 

Tim


Tim Nevels
Innovative Solutions
785-749-3444
timnev...@mac.com


**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Chip Scheide via 4D_Tech
Tim, 
first - it works (OSX) even renaming a folder to the same name but case 
changed.
i.e. My_Folder -> MY_FOLDER
THANKS!


the below line of code -

On Fri, 20 Oct 2017 16:21:24 -0400, Chip Scheide via 4D_Tech wrote:
>>   $command_t:="mv "+GetPOSIXfilePath ($folderPath_t)+" 
had trouble here -
apparently 4D's (v13) Convert path system to POSIX command - fails to 
do what it is advertised to do.
Fortunately I had a routine already written to do this.

Thanks again

---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Chip Scheide via 4D_Tech
Thanks Tim,


I wrote code to use MOVE DOCUMENT and CREATE FOLDER to do this.
It works, it is (on my tests, NOT very deep folder structures) quick.

So - Folder_Rename(Old_Folder_Path;New_Folder_Name)
works, no problem.

Then I tried to change the case, rather then rename on a folder and hit 
a wall...
Folder_Rename(Old_Folder_Path;OLD_FOLDER_NAME)

FAIL!
folder already exists of course it does!!! as the OS is case blind, 
unless you are one of the few masochists out there running OSX with 
case sensitivity turned on.

this is where I stopped today...

I will try your code, I suspect that it will work even with a case 
change, as this is occurring at the OS level, rather then 4D.

Thanks again


On Fri, 20 Oct 2017 15:07:23 -0500, Tim Nevels via 4D_Tech wrote:
> 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
> timnev...@mac.com
> 
> 
> **
> 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:4d_tech-unsubscr...@lists.4d.com
> **
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
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:4d_tech-unsubscr...@lists.4d.com
**

Re: v13 - Renaming a Directory via code.

2017-10-20 Thread Tim Nevels via 4D_Tech
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
timnev...@mac.com


**
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:4d_tech-unsubscr...@lists.4d.com
**