FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Saving a photo with extension
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Saving a photo with extension
Posted: Wed Sep 18, 2024 04:02 PM
I need to save a file in the archive with the extension ( I not Know wich is the extension of the file) ,
the user selects the file i.e. a photo,
the procedure must rename the photo with the student's matriculation number (nMatricola)

I made :
Code (fw): Select all Collapse
            nMatricola:= oAlunno:matricola      // student's matriculation number

           cExt := ltrim(Right(cfotografia,4))  // the extension of file 

           cRelativePath:= RelativePath(cfotografia)    // give the folder of file loaded 

           cFileNew:=cRelativePath+alltrim(nMatricola)+cExt     //save the new name file with extension
to rename the file cfotografia into new file cFileNew I made
Code (fw): Select all Collapse
           while FRename( cfotografia, cFileNew ) != 0
              SysWait()
           end
to save I use the copyfile function (found in fwh sample)
Code (fw): Select all Collapse
AaDd(aSource,(cFileNew) )
          AaDD(aTarget,cImgPath+UrlImage(cFileNew))
          CopyFiles(aSource,aTarget,)
it happens that sometimes it works and sometimes it saves the file in the cImgPath folder without extension but only with the file name i.e. with the student's matriculation number (nmatricola) and then saves it in the oAlunno:foto field
Code (fw): Select all Collapse
 oAlunno:foto:= UrlImage(cFileNew)
          oAlunno:Save()



the function RelativePath() - it gives me the name of the folder without the file
the function UrlImage() - it gives me the file name without the folder name


How I can resolve it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Saving a photo with extension
Posted: Wed Sep 18, 2024 09:04 PM
Silvio, although you can currently only ask 4.5 questions per day on o1, I will give up one for myself and test with your question.
Please post whether the result was correct.
Best regards,
Otto


ChatGPT preview o1
The issue you're encountering stems from the method used to extract the file extension. By using Right(cfotografia,4), you're assuming that the file extension is always three characters long (e.g., .jpg, .png), which may not be the case. Some file extensions are longer (like .jpeg, .tiff) or shorter. This incorrect assumption can lead to the extension being improperly extracted, resulting in files being saved without an extension.


Code (fw): Select all Collapse
// Student's matriculation number
nMatricola := oAlunno:matricola

// Find the last dot in the file name to get the extension
nDotPos := RAT(".", cfotografia)
IF nDotPos > 0
   cExt := SUBSTR(cfotografia, nDotPos)  // Extract extension
ELSE
   cExt := ""  // No extension found
ENDIF

// Get the folder path
cRelativePath := RelativePath(cfotografia)

// Construct the new file name
cFileNew := cRelativePath + ALLTRIM(nMatricola) + cExt

// Rename the original file
WHILE FRename(cfotografia, cFileNew) != 0
   SysWait()
END

// Prepare for copying
AaDd(aSource, cFileNew)
AaDD(aTarget, cImgPath + UrlImage(cFileNew))

// Copy the file
CopyFiles(aSource, aTarget)

// Update the student's record
oAlunno:foto := UrlImage(cFileNew)
oAlunno:Save()
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Saving a photo with extension
Posted: Thu Sep 19, 2024 09:07 AM

nice!

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Saving a photo with extension
Posted: Thu Sep 19, 2024 09:31 AM

Does it work?

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Saving a photo with extension
Posted: Thu Sep 19, 2024 10:52 AM
Otto wrote:Does it work?
it seems ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving a photo with extension
Posted: Sat Sep 21, 2024 03:08 AM
Code (fw): Select all Collapse
cFileNew := StrTran( cfotografia, cFileNoExt( cfotografia ), AllTrim( oAlunno:matricola ) )
if FRename( cfotografia, cFileNew ) == 0
   oAlunno:foto := cFileNoPath(cFileNew)
   oAlunno:Save()
endif
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Saving a photo with extension
Posted: Sun Sep 22, 2024 10:13 AM
nageswaragunupudi wrote:
Code (fw): Select all Collapse
cFileNew := StrTran( cfotografia, cFileNoExt( cfotografia ), AllTrim( oAlunno:matricola ) )
if FRename( cfotografia, cFileNew ) == 0
   oAlunno:foto := cFileNoPath(cFileNew)
   oAlunno:Save()
endif

thanks
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Saving a photo with extension
Posted: Sun Sep 22, 2024 05:12 PM

btw where is this function UrlImage() ?

Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Saving a photo with extension
Posted: Sun Sep 22, 2024 08:16 PM
nageswaragunupudi wrote:btw where is this function UrlImage() ?
see you email
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion