Detect if a folder is selected?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 154
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Detect if a folder is selected?

Post by RNIB » Thu Apr 26, 2018 11:10 am

If you select a folder in Windows is it's state changed in some way that MS could detect?

Every few weeks I have to backup certain projects from our server which involves manually selecting folders on one drive and copying to a backup drive. This is then repeated for 3 other drives (4 in total). As each drive involves copying a few hundred gig of data at a time it takes a number of hours to complete. If during that time someone uses the computer the selected files gets deselected and then I have to repeat the process after the data has been copied to then delete the data off the server. Tedious to say the least.

What I'd like to do is to be able to save the list of selected folders in some way so that I can then recall that selection later on and then delete the folders.

I can't see a way in MS of being able to read the state of a folder i.e. if it's selected or not other than perhaps image recognition to detect the background colour but then as soon as you need to get the folder name I think you'd loose the selection.

Unfortunately I probably need to continue making the initial selection of folders manually as it's a case of knowing if that project has finished or not which isn't recorded anywhere in the folder name.

I suspect this isn't possible but just wondering if there was some magic function in MS that could do this that I've missed in the manuals.

User avatar
Marcus Tettmar
Site Admin
Posts: 7029
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Detect if a folder is selected?

Post by Marcus Tettmar » Thu Apr 26, 2018 1:56 pm

I'm not clear on what you mean by "selecting" a folder, and why a user using the computer would affect what folders Macro Scheduler can copy. Could you clarify?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

RNIB
Macro Veteran
Posts: 154
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Detect if a folder is selected?

Post by RNIB » Thu Apr 26, 2018 2:06 pm

To clarify:

Using say Windows Explorer I navigate to a drive and then ctrl click (left mouse) on any folder I want to copy. On that drive there may be 200-300 folders but I've 'selected' say 50 of them. Once I've selected all the folders I want, I drag and drop them onto another drive to copy them.

If I then were to browse to a different drive or click with the mouse elsewhere within Windows Explorer the 'selection' is lost.

As a work around, not ideal but it might be workable, I was thinking of using MS to select all folders modified the month before or earlier, copy these to another drive and when complete to delete the folders from the source drive.

i.e. the current month is April, any folders on drive x with a modified date of February or earlier are copied and then deleted. The only caveat to that is that I'd need to be able to add a second criteria that being all folders beginning with the number 5 with a modified date of February or earlier are selected.

It's not ideal as the occasional project might not have been worked on for a month but still isn't complete and so would be backed up too soon but I could probably get it to stop before it deleted anything and ask me to confirm deletion to avoid this.

User avatar
Marcus Tettmar
Site Admin
Posts: 7029
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Detect if a folder is selected?

Post by Marcus Tettmar » Thu Apr 26, 2018 2:09 pm

Ok maybe what is confusing me is why you are automating the copying of files/folders by automating clicks in Windows Explorer. I would use CopyFile. Use GetFileList if needed first and loop through. Or define a list of folders you want to copy in an Ini file or dialog or something. Then it doesn't matter what someone does in Windows Explorer.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

RNIB
Macro Veteran
Posts: 154
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Detect if a folder is selected?

Post by RNIB » Thu Apr 26, 2018 2:16 pm

Completely understand what you are saying Marcus. The only reason I'm manually selecting folders with a mouse at the moment is because there is no way of sorting/selecting the folders I want on mass. Each folder name is a title of a project and I just have to read it and know whether that project is complete or not. So it might be a case of selecting the 1st, 3rd, 22nd, 27th, 35th folders etc (when sorted alphabetically).

I have been trying to define a list of folders but as mentioned the only option I can think of is by using the modified date of the folders. It's not fool proof but has potential. I can't find a way though of getting the modified dates of folders, I can of files but not of folders.

User avatar
Marcus Tettmar
Site Admin
Posts: 7029
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Detect if a folder is selected?

Post by Marcus Tettmar » Thu Apr 26, 2018 2:50 pm

Erm, I must be missing something. Load the folder listing into a list box on a custom dialog which is set to multi-select. Then you can select them from your dialog. No need to use Windows Explorer.

Try this. It's quick and dirty but you can make it look nicer and add the modified date if you want. This version is just looking at the Windows folder. Multi-select using Shift+Click or Ctrl+Click and then hit Go and then it loops through the selected items. Here you can copy.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 1285
  Top = 537
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 617
  ClientWidth = 536
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -28
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 240
  TextHeight = 32
  object Label1: TLabel
    Left = 56
    Top = 24
    Width = 264
    Height = 32
    Caption = 'Select folders to copy:'
  end
  object MSListBox1: tMSListBox
    Left = 47
    Top = 68
    Width = 434
    Height = 388
    IntegralHeight = True
    ItemHeight = 32
    MultiSelect = True
    TabOrder = 0
    SelectedIndex = -1
  end
  object MSButton1: tMSButton
    Left = 50
    Top = 495
    Width = 150
    Height = 50
    Caption = 'Go'
    ModalResult = 2
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

//Root path
Let>path=c:\windows\
Let>GFL_TYPE=1

GetFileList>%path%*.*,SubFolders,CRLF

SetDialogProperty>Dialog1,msListBox1,Text,SubFolders


Show>Dialog1,r

//Get selected items
GetDialogProperty>Dialog1,msListBox1,SelectedItems,theList

**BREAKPOINT**
//explode the list and loop through
Separate>theList,CRLF,files
If>files_count>0
  Let>k=0
  Repeat>k
    Let>k=k+1
    Let>this_folder=files_%k%
    
    //Copy it
    //CopyFolder>this_folder,wherever ....
    
  Until>k=files_count
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

RNIB
Macro Veteran
Posts: 154
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Detect if a folder is selected?

Post by RNIB » Thu Apr 26, 2018 3:13 pm

Oh that's what you meant! :oops: :oops: I had completely the wrong end of the stick.
Okay, I'm with you now...at least I think so. If I've understood the code I don't really need the modified date and I can recall each folder name that was copied later so that it can be deleted. In fact this approach has given me ideas to expand this further for other items. Far more elegant than the lump hammer approach I was taking :wink:

Cheers Marcus

User avatar
Marcus Tettmar
Site Admin
Posts: 7029
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Detect if a folder is selected?

Post by Marcus Tettmar » Thu Apr 26, 2018 3:28 pm

No problem. Glad it helped.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply