Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #9215 > unrolled thread

Copy and Rename issue

Started by"Philippe Bayard (Belgium)" <philbayard@gmail.com>
First post2016-03-31 08:37 -0700
Last post2016-04-01 12:41 +0200
Articles 8 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Copy and Rename issue "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2016-03-31 08:37 -0700
    Re: Copy and Rename issue "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2016-04-01 00:18 -0700
    Re: Copy and Rename issue Sjonnie D <Sjonnied@gmail.com> - 2016-04-01 00:34 -0700
      Re: Copy and Rename issue "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2016-04-01 00:43 -0700
        Re: Copy and Rename issue D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2016-04-01 12:29 +0200
          Re: Copy and Rename issue "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2016-04-01 05:20 -0700
            Re: Copy and Rename issue "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2016-04-01 06:34 -0700
        Re: Copy and Rename issue "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2016-04-01 12:41 +0200

#9215 — Copy and Rename issue

From"Philippe Bayard (Belgium)" <philbayard@gmail.com>
Date2016-03-31 08:37 -0700
SubjectCopy and Rename issue
Message-ID<4e7739c9-396c-4a91-8767-7763e8a8e4a4@googlegroups.com>
Hi Everyone,

i have a very strange case there.

In one of our app, people can drop Outlook .msg file to add it to a document tab. Everything works like a charm until one of our user tried to drop a file with a specific name.

The file has the subject of the mail as name.

"1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016.msg"

The problem is that VO is unable to FCOPY this file. With a SHCOPY, i can somehow move it, but i'm unable to rename it...

And in our process, i must give this file to another exe which cannot handle file with a space in it.

I've tried everything i have in mind to rename it.

1) FCopy 

Failed, my app start freezing and i can only stop is via the task manager.
Same for FRename.

2) SHCOPY + SHRENAME ( ~ SHFileOperation with FO_COPY and FO_RENAME )

SHCOPY works, SHRENAME not so i'm still not able to proceed it.
Everything works fine with another file.

SHRename ( ShFileOperation ) return 114 ( 0x72 ) which means 

DE_MANYSRC1DEST	0x72	Multiple file paths were specified in the source buffer, but only one destination file path.

Here, i'm lost.

 SHRename( WorkDir()+"TMP\"+ofs:FileName+ofs:Extension , WorkDir()+"TMP\"+ SysObject():cUsername +"_email.msg")

There is only one file here !

My SHRename function :

FUNCTION SHRename( cFROM as STRING, cTO as STRING ) as LOGIC PASCAL
 //http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795%28v=vs.85%29.aspx

 LOCAL struSHFileOpStruct is _WINSHFILEOPSTRUCT
 LOCAL lSuccess as LOGIC  
 LOCAL lRet as int

 struSHFileOpStruct.pFrom  := StringAlloc( cFROM+_chr(0) )
 struSHFileOpStruct.pTo    := StringAlloc( cTO+_chr(0) )
 struSHFileOpStruct.wFunc  := FO_RENAME   
 struSHFileOpStruct.fFlags := FOF_NOCONFIRMATION | FOF_SILENT             

 lRet := SHFileOperation( @struSHFileOpStruct ) 
 lSuccess := (  lRet = 0 )

 CloseHandle(struSHFileOpStruct.hwnd)
 MemFree(struSHFileOpStruct.pFrom)
 MemFree(struSHFileOpStruct.pTo)
 
 RETURN lSuccess  


CFrom = c:\pgmvo28\exe\carpack\TMP\1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?.msg

CTo = c:\pgmvo28\exe\carpack\TMP\DEBUG_email.msg


3) COPYFILE 

Fails ( return false... )

4) FileSpec + Filespec:Rename()ofs:
FileSpec Works ( FileSpec:filename gives "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?"  with a "?" coming from no where...)

then FileSpec rename fails, no error in the Filespec:oErrorInfo.

Does someone has an idea about how i can manage this?
Does this mean that any Fcopy with a long name (or is it the # the problem? ) will freeze the soft?

Any advice is welcome :)

Best regards,
Jean-Philippe


[toc] | [next] | [standalone]


#9217

From"Philippe Bayard (Belgium)" <philbayard@gmail.com>
Date2016-04-01 00:18 -0700
Message-ID<8a94de3b-e504-44b2-aaae-47e947c3888a@googlegroups.com>
In reply to#9215
Dear Johan,

Thank for the idea, but unfortunately, it doesn't work.
Still the return code 114 for SHFileOperation




Le jeudi 31 mars 2016 18:02:00 UTC+2, Johan Nel a écrit :
> Jean-Philippe
> 
>     
> 
>     Have you tried creating the string with single quote ' and then use
>     the double quote " to contain the whole file name?
> 
>     
> 
>      SHRename('"' + WorkDir()+'TMP\'+ofs:FileName+ofs:Extension + '"' , '"' + WorkDir()+'TMP\'+ SysObject():cUsername +'_email.msg' + '"')
> 
>     
> 
>     HTH,
> 
>     
> 
>     
> On 2016/03/31 17:37, Philippe Bayard
>       (Belgium) wrote:
> 
>     
>     
>       Hi Everyone,
> 
> i have a very strange case there.
> 
> In one of our app, people can drop Outlook .msg file to add it to a document tab. Everything works like a charm until one of our user tried to drop a file with a specific name.
> 
> The file has the subject of the mail as name.
> 
> "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016.msg"
> 
> The problem is that VO is unable to FCOPY this file. With a SHCOPY, i can somehow move it, but i'm unable to rename it...
> 
> And in our process, i must give this file to another exe which cannot handle file with a space in it.
> 
> I've tried everything i have in mind to rename it.
> 
> 1) FCopy 
> 
> Failed, my app start freezing and i can only stop is via the task manager.
> Same for FRename.
> 
> 2) SHCOPY + SHRENAME ( ~ SHFileOperation with FO_COPY and FO_RENAME )
> 
> SHCOPY works, SHRENAME not so i'm still not able to proceed it.
> Everything works fine with another file.
> 
> SHRename ( ShFileOperation ) return 114 ( 0x72 ) which means 
> 
> DE_MANYSRC1DEST	0x72	Multiple file paths were specified in the source buffer, but only one destination file path.
> 
> Here, i'm lost.
> 
>  SHRename( WorkDir()+"TMP\"+ofs:FileName+ofs:Extension , WorkDir()+"TMP\"+ SysObject():cUsername +"_email.msg")
> 
> There is only one file here !
> 
> My SHRename function :
> 
> FUNCTION SHRename( cFROM as STRING, cTO as STRING ) as LOGIC PASCAL
>  //http://msdn.microsoft.com/en-us/library/windows/desktop/bb759795%28v=vs.85%29.aspx
> 
>  LOCAL struSHFileOpStruct is _WINSHFILEOPSTRUCT
>  LOCAL lSuccess as LOGIC  
>  LOCAL lRet as int
> 
>  struSHFileOpStruct.pFrom  := StringAlloc( cFROM+_chr(0) )
>  struSHFileOpStruct.pTo    := StringAlloc( cTO+_chr(0) )
>  struSHFileOpStruct.wFunc  := FO_RENAME   
>  struSHFileOpStruct.fFlags := FOF_NOCONFIRMATION | FOF_SILENT             
> 
>  lRet := SHFileOperation( @struSHFileOpStruct ) 
>  lSuccess := (  lRet = 0 )
> 
>  CloseHandle(struSHFileOpStruct.hwnd)
>  MemFree(struSHFileOpStruct.pFrom)
>  MemFree(struSHFileOpStruct.pTo)
>  
>  RETURN lSuccess  
> 
> 
> CFrom = c:\pgmvo28\exe\carpack\TMP\1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?.msg
> 
> CTo = c:\pgmvo28\exe\carpack\TMP\DEBUG_email.msg
> 
> 
> 3) COPYFILE 
> 
> Fails ( return false... )
> 
> 4) FileSpec + Filespec:Rename()ofs:
> FileSpec Works ( FileSpec:filename gives "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?"  with a "?" coming from no where...)
> 
> then FileSpec rename fails, no error in the Filespec:oErrorInfo.
> 
> Does someone has an idea about how i can manage this?
> Does this mean that any Fcopy with a long name (or is it the # the problem? ) will freeze the soft?
> 
> Any advice is welcome :)
> 
> Best regards,
> Jean-Philippe
> 
> 
> 
> 
>     
>     
> 
>     
> -- 
> 
>       Johan Nel
> 
>       Grafx Support Team (Vulcan.NET)
> 
>       George, South Africa
> 
>       
> 
>     
>   
>  
> 
>  
> 			
> 		This email has been sent from a virus-free computer protected by Avast. 
> www.avast.com

[toc] | [prev] | [next] | [standalone]


#9218

FromSjonnie D <Sjonnied@gmail.com>
Date2016-04-01 00:34 -0700
Message-ID<7801c885-e68e-46a2-8b0f-eb9a22564ace@googlegroups.com>
In reply to#9215
> 4) FileSpec + Filespec:Rename()ofs:
> FileSpec Works ( FileSpec:filename gives "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?"  with a "?" coming from no where...)

Jean-Philippe,
When an email is dropped from a mailclient, the file name is created from the email subject. A subject can contain characters that are not allowed in filenames. The "?" is probably a hidden unicode character.

Before renaming the file to its destination, we always make a copy to a file with a valid filename. This means we replace all unwanted characters with a "_" and limit the length to 64:

cNewName := ""
For i := 1 to Min(Slen(cFileName),64)  // cFileName without path or extention, max 64 characters.
   cChar := substr(cFileName,i,1)
   if IsAlpha(String2Psz(cChar)) .or. IsDigit(String2Psz(cChar)) .or cChar=="."
      cNewName += cChar
   else
      cNewName += "c"
   endif
next i

After the fcopy to cNewName, we can rename it anyway you want.

Best Regards,
John

[toc] | [prev] | [next] | [standalone]


#9219

From"Philippe Bayard (Belgium)" <philbayard@gmail.com>
Date2016-04-01 00:43 -0700
Message-ID<76417a95-77a6-4c97-aff5-6b50a8e8f277@googlegroups.com>
In reply to#9218
Well, it's exactly the point of my problem. I cannot rename it. I'm trying to. But none of the VO function allow me to rename it properly.

The system works like this
Outlook => Drop to desktop (.msg file) => From desktop drop to the app.
With this way, i'm unable to rename it in any way because i don't have any control of the name of the file created by Outlook.


We have another way of working with outlook (via an add-in) and with this way, i can rename the msg file but for people who doesn't work with the add-in, i'm done. ;)





Le vendredi 1 avril 2016 09:34:30 UTC+2, Sjonnie D a écrit :
> > 4) FileSpec + Filespec:Rename()ofs:
> > FileSpec Works ( FileSpec:filename gives "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?"  with a "?" coming from no where...)
> 
> Jean-Philippe,
> When an email is dropped from a mailclient, the file name is created from the email subject. A subject can contain characters that are not allowed in filenames. The "?" is probably a hidden unicode character.
> 
> Before renaming the file to its destination, we always make a copy to a file with a valid filename. This means we replace all unwanted characters with a "_" and limit the length to 64:
> 
> cNewName := ""
> For i := 1 to Min(Slen(cFileName),64)  // cFileName without path or extention, max 64 characters.
>    cChar := substr(cFileName,i,1)
>    if IsAlpha(String2Psz(cChar)) .or. IsDigit(String2Psz(cChar)) .or cChar=="."
>       cNewName += cChar
>    else
>       cNewName += "c"
>    endif
> next i
> 
> After the fcopy to cNewName, we can rename it anyway you want.
> 
> Best Regards,
> John

[toc] | [prev] | [next] | [standalone]


#9221

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2016-04-01 12:29 +0200
Message-ID<0tisfblg13jetu34s0t3i59hq2r5h11s1t@4ax.com>
In reply to#9219
Replying on message of Fri, 1 Apr 2016 00:43:43 -0700 (PDT) from
Philippe Bayard (Belgium):


 Hello Philippe,

>Well, it's exactly the point of my problem. I cannot rename it. I'm trying to. But none of the VO function allow me to rename it properly.


I think John is right in assuming that the filename Outlook generates
an illegal filename. I wonder if you can rename the file in e.g. a
command prompt?

I'v had such an issue years ago and I couldn't rename in Explorer nor
in DOS. I managed to solve it with renaming with a  wildcard,
something like ren 1DXT684 *.* Newname.msg.

Not sure if this is something FRENAME could handle, if it would solve
the problem outside VO.

Dick

[toc] | [prev] | [next] | [standalone]


#9223

From"Philippe Bayard (Belgium)" <philbayard@gmail.com>
Date2016-04-01 05:20 -0700
Message-ID<9817cb63-f8bb-4f49-9a39-1943073f980a@googlegroups.com>
In reply to#9221
I think it's like John & Dick said, some illegal filename.

I can rename it on the command line :

C:\Users\Jpb\Desktop>rename "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 20150
20361 021 - Autopia #14016? - Copie.msg" test1234.msg 

=> Succeed.

One solution in my case is than to write a small function which call a command line to rename the illegal filename ! Let's try this ;)

Le vendredi 1 avril 2016 12:29:16 UTC+2, D.J.W. van Kooten a écrit :
> Replying on message of Fri, 1 Apr 2016 00:43:43 -0700 (PDT) from
> Philippe Bayard (Belgium):
> 
> 
>  Hello Philippe,
> 
> >Well, it's exactly the point of my problem. I cannot rename it. I'm trying to. But none of the VO function allow me to rename it properly.
> 
> 
> I think John is right in assuming that the filename Outlook generates
> an illegal filename. I wonder if you can rename the file in e.g. a
> command prompt?
> 
> I'v had such an issue years ago and I couldn't rename in Explorer nor
> in DOS. I managed to solve it with renaming with a  wildcard,
> something like ren 1DXT684 *.* Newname.msg.
> 
> Not sure if this is something FRENAME could handle, if it would solve
> the problem outside VO.
> 
> Dick

[toc] | [prev] | [next] | [standalone]


#9224

From"Philippe Bayard (Belgium)" <philbayard@gmail.com>
Date2016-04-01 06:34 -0700
Message-ID<0f4c5699-6adb-403c-adfc-b3e072139ae7@googlegroups.com>
In reply to#9223
Solved with the function bellow...  So i think i will test the encoding and length of the filename in the future and switch from frename to dosrename... 

Function DOSRename( cFROM as STRING, cTO as STRING ) as LOGIC PASCAL         
   
   LOCAL startup is STARTUPINFO
	LOCAL pro_inf is PROCESS_INFORMATION
	LOCAL lresult as USUAL          
	LOCAL var as DWORD          
	LOCAL lrunning as LOGIC   
	  
   FErase('"'+SysObject():cPathUser+'rename.bat"')
   FErase('"'+SysObject():cPathUser+'error.log"')       
   
   If Left(cFROM, 1) <> '"' 
   	cFROM := '"' + cFROM 
   ENDIF                 
   
   If Right(cFROM, 1) <> '"' 
   	cFROM := cFROM+'"' 
   ENDIF
  
	MemoWrit(SysObject():cPathUser+'rename.bat', 'rename '+cFROM+' '+ cTO +' 2>"'+SysObject():cPathUser+'error.log"' )
	
	
	startup.cb := _sizeof(_WINSTARTUPINFO)    
	startup.wShowWindow := SW_HIDE
	startup.dwFlags := STARTF_USESHOWWINDOW      
	lresult:=CreateProcess(null_ptr,;
		String2Psz(SysObject():cPathUser+"rename.bat"),;
		null_ptr,;
		null_ptr,;
		FALSE,;
		0,;
		null_ptr,;
		null_ptr,;
		@startup,;
		@pro_inf)   
	
	GetExitCodeProcess(pro_inf.hProcess,@var)
	IF  var == STILL_ACTIVE
		lrunning := true 
	ELSE
		lrunning := FALSE
	ENDIF   
  
	WHILE lrunning
	   GetExitCodeProcess( pro_inf.hProcess, @var )
	   IF  var == STILL_ACTIVE
		lrunning := true
	   ELSE
		lrunning := FALSE
	   ENDIF    
	   Sleep(10)
	END 
	
	IF !VOFile( SysObject():cPathUser+"errorlog") .or. Empty(MemoRead(SysObject():cPathUser+"error.log"))                               
		return true
	ELSE          
		return false
	ENDIF  


Le vendredi 1 avril 2016 14:20:10 UTC+2, Philippe Bayard (Belgium) a écrit :
> I think it's like John & Dick said, some illegal filename.
> 
> I can rename it on the command line :
> 
> C:\Users\Jpb\Desktop>rename "1DXT684 - MAZDA MX-5 - LA ROCCA Marc - Ethias 20150
> 20361 021 - Autopia #14016? - Copie.msg" test1234.msg 
> 
> => Succeed.
> 
> One solution in my case is than to write a small function which call a command line to rename the illegal filename ! Let's try this ;)
> 
> Le vendredi 1 avril 2016 12:29:16 UTC+2, D.J.W. van Kooten a écrit :
> > Replying on message of Fri, 1 Apr 2016 00:43:43 -0700 (PDT) from
> > Philippe Bayard (Belgium):
> > 
> > 
> >  Hello Philippe,
> > 
> > >Well, it's exactly the point of my problem. I cannot rename it. I'm trying to. But none of the VO function allow me to rename it properly.
> > 
> > 
> > I think John is right in assuming that the filename Outlook generates
> > an illegal filename. I wonder if you can rename the file in e.g. a
> > command prompt?
> > 
> > I'v had such an issue years ago and I couldn't rename in Explorer nor
> > in DOS. I managed to solve it with renaming with a  wildcard,
> > something like ren 1DXT684 *.* Newname.msg.
> > 
> > Not sure if this is something FRENAME could handle, if it would solve
> > the problem outside VO.
> > 
> > Dick

[toc] | [prev] | [next] | [standalone]


#9222

From"Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it>
Date2016-04-01 12:41 +0200
Message-ID<ndlj2a$uck$1@dont-email.me>
In reply to#9219
Hello Philippe,

there is the possibility that the Mailclient program together with Windows 
or Antivirus programs block the file exclusively for antivirus protection 
reasons.
In this case your own program is blocked until the file is released but you 
block finishing the operation exactly by this waiting operation.

Probably you have to delay the processing of the file until the Drag/Drop 
operation has been finished completey.

Arne Ortlinghaus
ACS Data Systems

"Philippe Bayard (Belgium)" <philbayard@gmail.com> schrieb im Newsbeitrag 
news:76417a95-77a6-4c97-aff5-6b50a8e8f277@googlegroups.com...
Well, it's exactly the point of my problem. I cannot rename it. I'm trying 
to. But none of the VO function allow me to rename it properly.

The system works like this
Outlook => Drop to desktop (.msg file) => From desktop drop to the app.
With this way, i'm unable to rename it in any way because i don't have any 
control of the name of the file created by Outlook.


We have another way of working with outlook (via an add-in) and with this 
way, i can rename the msg file but for people who doesn't work with the 
add-in, i'm done. ;)





Le vendredi 1 avril 2016 09:34:30 UTC+2, Sjonnie D a écrit :
> > 4) FileSpec + Filespec:Rename()ofs:
> > FileSpec Works ( FileSpec:filename gives "1DXT684 - MAZDA MX-5 - LA 
> > ROCCA Marc - Ethias 2015020361 021 - Autopia #14016?"  with a "?" coming 
> > from no where...)
>
> Jean-Philippe,
> When an email is dropped from a mailclient, the file name is created from 
> the email subject. A subject can contain characters that are not allowed 
> in filenames. The "?" is probably a hidden unicode character.
>
> Before renaming the file to its destination, we always make a copy to a 
> file with a valid filename. This means we replace all unwanted characters 
> with a "_" and limit the length to 64:
>
> cNewName := ""
> For i := 1 to Min(Slen(cFileName),64)  // cFileName without path or 
> extention, max 64 characters.
>    cChar := substr(cFileName,i,1)
>    if IsAlpha(String2Psz(cChar)) .or. IsDigit(String2Psz(cChar)) .or 
> cChar=="."
>       cNewName += cChar
>    else
>       cNewName += "c"
>    endif
> next i
>
> After the fcopy to cNewName, we can rename it anyway you want.
>
> Best Regards,
> John

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web