Forum

Macro to move files...
 
Notifications
Clear all

Macro to move files from folder

13 Posts
2 Users
0 Reactions
112 Views
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

In our root directory for example D: We have numerous Folders which store Excel Files by category. How to write a macro to search each folder from the root directory, move or copy the Excel files to an external hard disc or an USB drive without using the manually move or copy and paste process.

I think macro can ensure completeness in the excel files move and copy process... 

 
Posted : 22/10/2020 10:33 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi David,

Use xcopy from the Command Prompt - much easier as it already exists.

I assume you are using Windows.  Click on the Start/Windows button in the bottom left of the screen.  Type cmd and the Command Prompt app should be shown.  Click on it to open a Command Prompt window.

Type xcopy /? to see the help info for xcopy.

To copy files from D: and all subfolders, to the U: drive,  you'll want to use a command like this

xcopy d:*.xls* u: /s /c /i /r /y

Double check the command switches to make sure they do what you want.

Regards

Phil

 
Posted : 23/10/2020 12:30 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks Philip will attempt to use this command!

 
Posted : 23/10/2020 1:41 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Can we use delete command permanent delete all after files copy to external hard disk?

 
Posted : 23/10/2020 1:54 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

It depends on what files you want to delete.  If it is ALL files of a certain type or name you can use del *.XLS* /s but that will delete ALL files that end in .xls* 

Be careful to understand what you are doing before running the del command.

Phil

 
Posted : 23/10/2020 2:40 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks I already tried xcopy command and confirmed successful, thanks again all xls files or similar type  copy to the external hard disc.

 Now I can try the delete  command

BTW can you elaborate what is /s/c/i/r/y meaning in the command  

 

for /s  - I guess subfolder

 
Posted : 23/10/2020 3:07 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi David,

If you type xcopy /? in the Command Prompt you get all the help info for xcopy that tells you what the switches do.

/s Copy directories and sub-directories except empty ones

/c Continue copying if an error occurs

/i If the destination does not exist and copying more than one file, assume the destination is a directory

/r Overwrite read only files

/y Do not prompt to confirm overwriting of an existing fie in the destination.

Cheers

Phil

 
Posted : 23/10/2020 5:40 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Got it all , Philip, deep thanks again the guidance and useful remind of the DOS command skills.

 
Posted : 23/10/2020 8:05 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

No worries David.  I remember reading a manual on the DOS Prompt from cover to cover.  I used to write a lot of batch files for things like remote installations of Windows.  The commands are still very useful.

Phil

 
Posted : 23/10/2020 9:11 pm
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Do really appreciate if you can share the Batch files with us, despite it departs a bit from this Forum...

 
Posted : 23/10/2020 10:59 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

It was 20+ years ago.  I don't have them any more

 
Posted : 23/10/2020 11:06 pm
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Wow, time flies, thanks for sharing your precious experience!

 
Posted : 24/10/2020 2:51 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

It certainly does.

 
Posted : 24/10/2020 8:04 am
Share: