Dealing with Folders

13 posts / 0 new
Last post
chdarc
Offline
Joined: 06/13/2016 - 14:53
Dealing with Folders

I've been trying to figure out a way to deal with user created folders. 
Its very common for users in my organization to work with a set of databases in IDEA and then create a folder to organize them within the current directory. They will create a folder and then move the databases over. The problem though is many of the scripts that I have been written can not find those databases moved into those folders. The scripts will pull all the databases in the current directory unless they are within a folder. 
Is there anyway to have it look into those folders and give the user the option to select those? 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Chris,

Sorry for not getting back to you sooner.  There are probably several different ways you can tackle this problem.  Can you give me an example of what the users are doing and exactly what you want.

Some of the things you can do is:

  • Have the user select the folder that they stored the info in and then either change the project folder to that folder or move the files.
  • Have IDEA go searching for those files in other folders and then copy them over.
  • Probably something else based on what you want.

Thanks

Brian

chdarc
Offline
Joined: 06/13/2016 - 14:53

So basically within the project folder the user is create a new folder to store databases in. They are doing this just to keep their File Explorer organized. See the image attached. 
 
Basically, right now my script will go and get all the files within the Project and allow the user to select those for use in the script, but it does not find the files within these folders. I'm just looking for a way to include those and if possible the folder name they are located in. 

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Chris,

I guess the next question would be do the files have standardized naming?  If the user was to select the folder that they have stored the files into would that be enough for the script or do you also need the names of the file(s)?  If you need both probably the best option would be have the user select the folder and then load the imd files into a list dialog so that they can select them.

Thanks

Brian

chdarc
Offline
Joined: 06/13/2016 - 14:53

Hi Brian, 
Thanks for the response. Sorry for the slow response on my part. 
Nor the files or folders will have standardized naming. There would be too much variation by users to try and mandate a standardized name. On some aspects I could set a standard name, but there are no guarantees that the user wouldn't just rename based on their personal perference. 
I basically would need to see a list of the individual files within the folder. It would work if at first the user is listed with all the files not in folders and then the folders. Then if a file is one of those folders then the user selects the folder and then the files are listed for selection. 
Does that make sense? Is that doable?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Chris,

Here is something for you to try out.  The script will first ask the user for the folder (the folder must be under the project folder), it will then read the imd files within that folder and display them in a dialog so the user can select the files from them.  It then uses the project management function to copy the files to the project folder.  There is one problem with this and I think it is a bug in IDEAScript.  If the sub-folder is open within the project folder the script will think that the sub-folder is the project folder and try and copy the file over itself.  I plan on flagging this to IDEA as a possible bug in IDEAScript.

Thanks

Brian

Smiso
Offline
Joined: 03/07/2019 - 03:05

Hi Brian
 
I hope all is well.
 
Just a quick question on my side for my use case.
 
Will your script help me in my situation? So, basically I want to use folder to orginase my databases nicely, so that File Explorer is not flooded with lots of databases along with their extraction trees. So, using the above script, is it possible for me to perform an extraction from a database in Folder A and automatically save that extraction in Folder B, or would that require an entirely different script?
 
Because right now, if I want to extract data from a database in Folder A, I literally have to create a duplicate of the same database in Folder B and then extract what I need to continue working in Folder B. So, if I keep doing that, I end up having redundant databases in my IDEA project, which is not ideal.
 
Please see the attached screenshot for context.
 
Please let me know if you require more information.
 
Thank you.
Smiso

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Smiso,

Yes, you can use the code in the script and incorporate it in your script to move the files.  See the movefiles function in this script for the code.

Smiso
Offline
Joined: 03/07/2019 - 03:05

Hi Brian
 
Thank you very much.
 
I will check the script out.
 
Regards.
Smiso.

Gerard Usher
Offline
Joined: 10/26/2018 - 08:40

Hi Brian.  Did you have any success getting IDEA to flag this as a possible bug?  The problem gets worse when you create Sub-folders of the folders and moving files into it.  For Example: I create a folder within my Project called "2018 Annual Data" and a sub-folder called 2018 Week 01.  The IDEA File Explorer can only see the "2018 Annual Data" folder, even though if I right click on my files it lets me move them to the "2018 Annual Data/Week 01" folder.  The only way to rereieve them is to move the files back to the root directory or to the "2018 Annual Data" folder using WIndows Explorer and then refreshing the IDEA File Explorer.
It would seem that IDEA is “grabbing” the Windows File Explorer to move files and create new folders / subfolders but the CaseWare IDEA File Explorer cannot see them.  This is very frustrating because I want to keep my project name / path but tidy up my yearly / monthly files into neat containers.  Can you please pass this on and ask if the issue within the CaseWare File Explorer can be addressed?
 
FYI.  I was hoping that this would be "fixed" with the release of IDEA 10.4.1 but, unfortunately, it was not

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Gerard,

Unfortunately IDEA has decided not to fix this problem.  I did manage to get them to add this to their documentation but I don't see you will be seeing this fixed unless more people complain about it:

If the active database resides in a sub-folder of the current Desktop project, running a macro with Current=ClientWorkingDirectory() returns the sub-folder path instead of the current Desktop project.

IDEA can only see one level of sub-folders within the file explorer.  It sounds like you are creating a sub folder within a sub folder of the project, so the file explorer will not see the lower folder but only the first level.

I recommend that you send them an email requesting this change, you can send it to: support.cwa@caseware.com, the more people point this out the more likely it will be addressed and they already have my comments.

For obtaining the project folder I now get it directly from the registry as this doesn't change if you are in a sub-folder.


Sub Main
	sWorkingFolder = getWorkingDirectory()
	If sWorkingFolder = "" Then
		sWorkingFolder  = Client.WorkingDirectory
	End If
End Sub

Function getWorkingDirectory() As String
	Dim regLocation As String
	Dim myWS As Object
	regLocation = "HKEY_CURRENT_USER\Software\CaseWare IDEA\CaseWare IDEA\Config\Working directory"   
	On Error Resume Next
	'access Windows scripting
	Set myWS = CreateObject("WScript.Shell")
	'read key from registry
	getWorkingDirectory = myWS.RegRead(regLocation)
End Function

Pages