| View previous topic :: View next topic |
| Author |
Message |
patchie
Joined: 22 Feb 2008 Posts: 24
|
Posted: Tue Feb 09, 2010 1:00 pm Post subject: a little FileSelectFolder problem |
|
|
I am trying to make a program where the user must choose a folder.
The folder will be inside Z:\Backup
Like Z:\Backup\computer-3d5 or Z:\Backup\computer-gp8
But i want it to report error if the user has choose'n a folder inside one of those computer folders like: Z:\Backup\computer-3d5\test.txt
| Code: |
;sjekk at z: er mappet
FileGetSize, OutputVar, Z:\Backup
;sjekke at en mappe med samme serienr er laget fra før...eventuellt slette den gamle
VelgFil:
FileSelectFolder, WhichFolder, Z:\Backup, 0, Velg GAMMELT serienr (Dette serienr vil bli endret til det som denne pc'en har) ; Ask the user to pick a folder.
if ErrorLevel ; i.e. it's not blank or zero.
{
MsgBox, Error: Det har skjedd en feil. Du har ikke valgt mappe.
return
}
;Hvis brukern har valgt Z:\Backup
if WhichFolder = Z:\Backup
{
MsgBox, You selected wrong folder.
Goto, VelgFil
}
;Hvis brukern har valgt Z:\Backup\*\
if WhichFolder = Z:\Backup\*\*
{
MsgBox, You selected wrong folder.
Goto, VelgFil
}
MsgBox, You selected folder "%WhichFolder%".
|
_________________ ..:: Patchie ::.. |
|
| Back to top |
|
 |
Murx Guest
|
Posted: Tue Feb 09, 2010 1:25 pm Post subject: |
|
|
| Quote: | | But i want it to report error if the user has choose'n a folder inside one of those computer folders like: Z:\Backup\computer-3d5\test.txt | If he/she selects a folder without having an access permission for it? So the user should get restricted to his/her individual folder?? |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 780 Location: England
|
Posted: Tue Feb 09, 2010 1:49 pm Post subject: |
|
|
Not the most elegant solution - but is this the kind of thing you mean?
| Code: | BaseFolder := "Z:\Backup"
;sjekk at z: er mappet
FileGetSize, OutputVar, %BaseFolder%
;sjekke at en mappe med samme serienr er laget fra før...eventuellt slette den gamle
VelgFil:
FileSelectFolder, WhichFolder, %BaseFolder%, 0, Velg GAMMELT serienr (Dette serienr vil bli endret til det som denne pc'en har) ; Ask the user to pick a folder.
if ErrorLevel ; i.e. it's not blank or zero.
{
MsgBox, Error: Det har skjedd en feil. Du har ikke valgt mappe.
return
}
StringReplace, SubFolder, WhichFolder, %BaseFolder%, ""
Loop, Parse, SubFolder, \
{
WrongFolder := false
If A_Index = 1
{
WrongFolder := true
Continue
}
Else If A_Index > 2
{
WrongFolder := true
Break
}
}
If WrongFolder
{
MsgBox, You selected wrong folder.
Goto, VelgFil
}
MsgBox, You selected folder "%WhichFolder%". |
|
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Tue Feb 09, 2010 2:14 pm Post subject: |
|
|
Just replace this:
| Code: | ;Hvis brukern har valgt Z:\Backup
if WhichFolder = Z:\Backup
{
MsgBox, You selected wrong folder.
Goto, VelgFil
}
;Hvis brukern har valgt Z:\Backup\*\
if WhichFolder = Z:\Backup\*\*
{
MsgBox, You selected wrong folder.
Goto, VelgFil
} |
With:
| Code: | IfInstring,Whichfolder,Z:\Backup
{
MsgBox, You selected wrong folder.
Goto, VelgFil
}
|
|
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 780 Location: England
|
Posted: Tue Feb 09, 2010 6:13 pm Post subject: |
|
|
I may be wrong, but I think the OP wants the user to select a folder of the 1st level deeper than "Z:\Backup", but no deeper than that.
So:
1) The user cannot choose "Z:\Backup" as the folder - they must choose a folder within this)
2) The user may not choose a folder equal to or greater than 2 levels deeper than "Z:\Backup"
"Z:\Backup" - Not allowed
"Z:\Backup\Folder1" - OK
"Z:\Backup\Folder1\Folder2" - Not allowed
"Z:\Backup\Folder3" - OK
This is how I read the request anyway.
@patchie - Is the above what you meant? Please let us know if any of the answers given are what you were requesting.
@affe - surely your code will *always* show an error? If the user chooses "Z:\Backup\computer-3d5" (as per the original post), then this will fail with your example replacement, won't it?
Maybe it's just me misunderstanding what is required  |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Wed Feb 10, 2010 7:38 am Post subject: |
|
|
Hy Oceanmachine,
yes, youre right. Ifinstring does the opposite than I wrote. Im sorry for this mistake. |
|
| Back to top |
|
 |
patchie
Joined: 22 Feb 2008 Posts: 24
|
Posted: Wed Feb 10, 2010 9:19 am Post subject: |
|
|
ohh..your great
OceanMachine: Thats exactly what i needed.
aaffe & Murx: I wanna thank you too for responding  _________________ ..:: Patchie ::.. |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Wed Feb 10, 2010 11:40 am Post subject: |
|
|
| So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder. |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 780 Location: England
|
Posted: Wed Feb 10, 2010 12:17 pm Post subject: |
|
|
| aaffe wrote: | | So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder. |
That's what the code I posted does  |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 1002 Location: Germany - Deutschland
|
Posted: Wed Feb 10, 2010 12:27 pm Post subject: |
|
|
Sorry, didnt read your post.
| OceanMachine wrote: | | aaffe wrote: | | So you could check if Z:\Backup is in the var for the folder. If so, you could count the \`s. If there are two, ok. If less or more than two, msgbox wrong folder. |
That's what the code I posted does  |
|
|
| Back to top |
|
 |
|