selkov Posted September 10, 2008 Report Share Posted September 10, 2008 I would like a Macro to read thru the sub folders in a Folder, M:\Archive and look into each one. If that sub folder has only 1 item in it I would like the sub folder moved to [M:\1]. If it has more than one item then i would like that sub folder moved to M:\2. How can i do this? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 10, 2008 Report Share Posted September 10, 2008 I would use a Repeat With Folder to get all the sub-folders and in that loop I would do another repeat with folder. In that one I would simply increment an integer N1 to count how many there are. Next use a condition If N1 =1 move to \1, Else \2. Now in some cases I've found that strange things can arise when the the contents of the folder being repeated with are changing. Say for instance renaming in place. I don't think this will be an issue for you in this case but if you ever yo have a problem I recommend creating a list of folders first and saving it to a file then doing an Text File Process loop instead. Quote Link to comment Share on other sites More sharing options...
selkov Posted September 10, 2008 Author Report Share Posted September 10, 2008 "I would use a Repeat With Folder to get all the sub-folders and in that loop I would do another repeat with folder. In that one I would simply increment an integer N1 to count how many there are. Next use a condition If N1 =1 move to \1, Else \2." I fear this is currently beyond my knowledge. Does anyone have a macro close to this that i can use to learn from? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 10, 2008 Report Share Posted September 10, 2008 I am writing you a sample now. When you say you want it to count 'items' are 'items' files, folders or both? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 10, 2008 Report Share Posted September 10, 2008 <REP3:07:000007:000001:0001:0:01:m:\archive><REM2:Resets the item counter><IVAR2:01:01:0><REM2:Counts the numbers of folders><REP3:07:000007:000001:0002:0:01:%T1%><NMVAR:08:01:0:0000001:0:0000000><ENDREP><REM2:Adds to the count the number of files. ><REP3:07:000001:000001:0002:0:01:%T1%><NMVAR:08:01:0:0000001:0:0000000><ENDREP><REM2:If the count is 1 move to c:\1\ else move to c:\2\><IFVAR2:2:01:1:1><DOFILE:07:NN:m:\archive\%T1%\*.*>m:\1\%T1%\*.*><ELSE><DOFILE:07:NN:m:\archive\%T1%\*.*>m:\2\%T1%\*.*><ENDIF><ENDREP> You didn't specify if the items we were counting were files or folders so I wrote it to count both. Simply delete the appropriate repeat section if I got this wrong. I have not tested this but it should work. Also I was assuming that the \1 and \2 were at the same level as c:\Archive. If you want them as sub-folders of archive move them back afterwords or else it will mess with the Repeat With Folder commands by introducing a new folder. Quote Link to comment Share on other sites More sharing options...
selkov Posted September 10, 2008 Author Report Share Posted September 10, 2008 You are very kind. thanks. My problem is that i have roughly 1500 sub folders. In some folders there are multiple files. In others just one File. What i am looking to do is take all the folders that contain just one file and move them together into a new folder. The whole folder, not just the file. And then also group the others. If i can move either set the others are easy to cut and paste to the new location. Quote Link to comment Share on other sites More sharing options...
selkov Posted September 10, 2008 Author Report Share Posted September 10, 2008 just got your script. must have been posting at about the same time...lol I will try this later tonight and let you know how it works. Thanks Quote Link to comment Share on other sites More sharing options...
selkov Posted September 12, 2008 Author Report Share Posted September 12, 2008 Well, I have played with it a lot. I can not get it to work. Just do not understand this enough I guess. Here is where i ended up: <REP3:07:000005:000001:0001:0:01:M:\ARCHIVE><IVAR2:01:01:0><REP3:07:000001:000001:0002:0:01:%T1%><NMVAR:08:01:0:0000001:0:0000000><ENDREP><IFVAR2:2:01:1:1><DOFILE:02:NN:M:\1\%T1%>><DOFILE:07:NN:M:\ARCHIVE\%T1%>M:\1\%T1%><DOFILE:04:NN:M:\ARCHIVE\%T1%>><ELSE><DOFILE:02:NN:M:\2\%T1%>><DOFILE:07:NN:M:\ARCHIVE\%T1%>M:\2\%T1%><DOFILE:04:NN:M:\2\%T1%>><ENDIF><TBOX4:T:4:CenterCenter000600000100:000:T1%T1% ><TBOX4:T:4:CenterCenter000600000100:000:T2%T2% ><TBOX4:T:4:CenterCenter000600000100:000:N1%N1% ><ENDREP> I cant seem to move the files and I think it is because there is no destination folder. Quote Link to comment Share on other sites More sharing options...
selkov Posted September 13, 2008 Author Report Share Posted September 13, 2008 OK...I got it working. maybe i was to tired last night but this is doing the trick: <REP3:07:000007:000001:0001:0:01:M:\ARCHIVE><REP3:07:000001:000001:0002:0:01:M:\ARCHIVE\%T1%><NMVAR:08:01:0:0000001:0:0000000><ENDREP><TBOX4:T:4:000410000130000600000200:000:N1 %N1% T1 %T1% T2 %T2%><IFVAR2:2:01:1:1><DOFILE:07:NN:M:\ARCHIVE\%T1%>M:\1\%T1%><ELSE><DOFILE:07:NN:M:\ARCHIVE\%T1%>M:\2\%T1%><ENDIF><IVAR2:01:01:0><ENDREP> Thank you very much for your help..... Quote Link to comment Share on other sites More sharing options...
Cory Posted September 24, 2008 Report Share Posted September 24, 2008 NP, glad you got it to work without me, I had to tend to some large macro jobs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.