Skip to content
⌘ NSIS Forum Archive

File save

28 posts

Anduriel#

File save

I would like to know how we can make to look if the files which we want to extract are already present in a file. And if yes, then it is copied and stuck in a file back up.

Thank you 🙂
Anduriel#
I'am sorry but I don't know any syntax... I'am a noob and I must learn with examples 🙂 lol. Can you say me just the syntax? Thanks you





P.S Is my English good 😁?
Anduriel#edited
I found:

file_to_check_for jump_if_present [jump_otherwise]

and I read the explication but it don't better help me... I replace that: file_to_check_for jump_if_present by my file's name? but what is it [jump_otherwise] ?

edit: I found too:
[/SILENT] [/FILESONLY] filespec_on_destsys destination_path [size_of_files_in_kb]
and
path_to_create

I don't know where I must put it and what Replace...
Thank ou 🙂
Anduriel#
For example:

IfFileExists "$INSTDIR\logo.bmp" 0 notexist

"$INSTDIR\SavesMdl\logo.bmp"

notexist:

I am not sure that "$INSTDIR\SavesMdl\logo.bmp" is good...
Anduriel#
Sorry but I don't understand... :/ Can you write me an example? That looks like a valid path and you don't know what I have to do?
Anduriel#
So:


IfFileExists "$INSTDIR\logo.bmp" 0 notexist
[/SILENT] [/FILESONLY] "logo.bmp" "$INSTDIR\SavesMdl\logo.bmp" [100]
notexist:
?
Joost Verburg#
No, you should use the CopyFiles command with the syntax as described in the manual, not copy the syntax description.
CopyFiles /SILENT "$INSTDIR\SavesMdl\logo.bmp" "$INSTDIR\SavesMdl\logo-backup.bmp"
Anduriel#
Ok thx I begin to understand 🙂 But for what I replace that: filespec_on_destsys? I saw, you had twice the same thing and I don't understand that. And what is /FILEONLY then?
My new code:

SetOutPath "$INSTDIR"
SetOverwrite on
File "logo.bmp"
IfFileExists "$INSTDIR\logo.bmp" 0 notexist
CreateDirectory "$INSTDIR\SavesMdl\"
CopyFiles /SILENT "$INSTDIR\SavesMdl\logo.bmp" "$INSTDIR\SavesMdl\logo-backup.bmp"
notexist:
But even if the file exists not it created a save, moreover which does not work. It is written during the install "Copy failed "... What is the problem?
thx
Joost Verburg#
filespec_on_destsys is the source for the file copy. /FILEONLY is a flag that is useful if you want to copy a whole folder but not the folders inside that folder.

You didn't say that it was the backup directory for the file. Try:

SetOutPath "$INSTDIR"

IfFileExists "$INSTDIR\logo.bmp" 0 notexist

CreateDirectory "$INSTDIR\SavesMdl"
CopyFiles /SILENT "$INSTDIR\logo.bmp" "$INSTDIR\SavesMdl\logo.bmp"

notexist:

File "logo.bmp"
Anduriel#
Thank you very much that works! But I would like to know if it is possible actually an IfFileExists generally, not file by file, simply " if A file exists to copy IT... "
Thank you very much 😁
Joost Verburg#
Please read the manual for information about function and macros. This forum is not a script writing service.
Anduriel#
yes lol I know but I think a look not on the good page... I read here: http://nsis.sourceforge.net/Docs/
That's good?
Joost Verburg#edited
That is indeed the users manual. A macro can be used to insert certain commands multiple times, with different parameters.

Example:
!macro FILEWITHBACKUP FILE

IfFileExists "$INSTDIR\${FILE}" 0 notexist

CreateDirectory "$INSTDIR\SavesMdl"
CopyFiles /SILENT "$INSTDIR\${FILE}" "$INSTDIR\SavesMdl\${FILE}"

notexist:

File "${FILE}"

!macroend
!insertmacro FILEWITHBACKUP "logo.bmp"
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx
Anduriel#
Thx I tested that but I have a very big problem, I need three different roads for the same file: the problem during the compilation:


IfFileExists: $"INSTDIR\maps\cs_deagle5.bsp? 0: CopyFiles notexist: silent ) $"INSTDIR\maps\cs_deagle5.bsp - > " $INSTDIR\CS-Combo\save_map\maps\cs_deagle5.bsp ", size=0KB File: "maps\cs_deagle5.bsp" - > no File found.


Here it looks if the file exists, that it is good.
Here is where it going to copy it, but it resumes the same road, what distorts everything!
Here it is the file which is not found because it is not situated! I simple used !insertmacro FILEWITHBACKUP " map\cs_deagle.bsp...

Thx