AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

a little FileSelectFolder problem

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
patchie



Joined: 22 Feb 2008
Posts: 24

PostPosted: Tue Feb 09, 2010 1:00 pm    Post subject: a little FileSelectFolder problem Reply with quote

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
View user's profile Send private message
Murx
Guest





PostPosted: Tue Feb 09, 2010 1:25 pm    Post subject: Reply with quote

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

PostPosted: Tue Feb 09, 2010 1:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Tue Feb 09, 2010 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Tue Feb 09, 2010 6:13 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Feb 10, 2010 7:38 am    Post subject: Reply with quote

Hy Oceanmachine,
yes, youre right. Ifinstring does the opposite than I wrote. Im sorry for this mistake.
Back to top
View user's profile Send private message
patchie



Joined: 22 Feb 2008
Posts: 24

PostPosted: Wed Feb 10, 2010 9:19 am    Post subject: Reply with quote

ohh..your great Very Happy

OceanMachine: Thats exactly what i needed.

aaffe & Murx: I wanna thank you too for responding Smile
_________________
..:: Patchie ::..
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Feb 10, 2010 11:40 am    Post subject: Reply with quote

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
View user's profile Send private message
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Wed Feb 10, 2010 12:17 pm    Post subject: Reply with quote

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 Laughing
Back to top
View user's profile Send private message
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Feb 10, 2010 12:27 pm    Post subject: Reply with quote

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 Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group