Archive: File save


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 :)


Use IfFileExists.


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 :D?


You can find the syntax of this command in the users manual.


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 :)


IfFileExists "$INSTDIR\myfile.exe" 0 notexist

;Backup the file here

notexist:

For example:

IfFileExists "$INSTDIR\logo.bmp" 0 notexist

"$INSTDIR\SavesMdl\logo.bmp"

notexist:

I am not sure that "$INSTDIR\SavesMdl\logo.bmp" is good...


That looks like a valid path.


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?


>> "$INSTDIR\SavesMdl\logo.bmp"

this is only parameter, where is the function ???


Use CopyFiles for the backup.


So:


IfFileExists "$INSTDIR\logo.bmp" 0 notexist
[/SILENT] [/FILESONLY] "logo.bmp" "$INSTDIR\SavesMdl\logo.bmp" [100]
notexist:
?

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"

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

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"

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 :D


If you want to do the same thing for many files, create a macro or function.


Sorry but I don't see what do you want to say...


Please read the manual for information about function and macros. This forum is not a script writing service.


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?


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"

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


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


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


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


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


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


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