• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Macro to move files from folder|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Macro to move files from folder|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosMacro to move files from folder
sp_PrintTopic sp_TopicIcon
Macro to move files from folder
Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
1
October 22, 2020 - 12:33 pm
sp_Permalink sp_Print

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... 

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
October 22, 2020 - 2:30 pm
sp_Permalink sp_Print

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

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
3
October 22, 2020 - 3:41 pm
sp_Permalink sp_Print

Thanks Philip will attempt to use this command!

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
4
October 22, 2020 - 3:54 pm
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
5
October 22, 2020 - 4:40 pm
sp_Permalink sp_Print

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

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
6
October 22, 2020 - 5:07 pm
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
7
October 22, 2020 - 7:40 pm
sp_Permalink sp_Print

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

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
8
October 23, 2020 - 10:05 am
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
9
October 23, 2020 - 11:11 am
sp_Permalink sp_Print sp_EditHistory

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

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
10
October 23, 2020 - 12:59 pm
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
11
October 23, 2020 - 1:06 pm
sp_Permalink sp_Print

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

Avatar
David_Ng
Member
Members
Level 0
Forum Posts: 306
Member Since:
December 5, 2016
sp_UserOfflineSmall Offline
12
October 23, 2020 - 4:51 pm
sp_Permalink sp_Print

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

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1513
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
13
October 23, 2020 - 10:04 pm
sp_Permalink sp_Print

It certainly does.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Brian Pham, Chandler Davis, Valentyn Kristioglo
Guest(s) 8
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
drsven
Annie Witbrod
wahab tunde
Cong Le Duc
Faisal Bashir
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Forum Stats:
Groups: 3
Forums: 24
Topics: 6205
Posts: 27212

 

Member Stats:
Guest Posters: 49
Members: 31880
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.