Here’s my tip to start the financial year off with some organisation. If you save your important files in a folder structure per financial year, then you will be ready to create that new folder for the new tax year. To save time and keep your filing structure consistent you can quickly copy the entire structure (including all subfolders) with the following technique. Using this technique, only the folder structure is copied (not the actual files). So you will be up and going with your new folder structure for the tax year and continue filing.
Here’s a simplified version of what my filing structure looks like:
Now simply create your new folder (under which you want to duplicate the folder structure)
Now open a Windows command window and run the following command. It’s the /T option that copies just the folder structure not the files. You can also use the /E option to include empty folders in the copy (by default empty folders will not be copied).
xcopy “c:\users\cdwyer\documents\2012-2013” “c:\users\cdwyer\documents\2013-2014” /T /E
Job done, you should now see your copied folder structure ready to start filing into for the new year.
Thanks Cameron for the info! Do you know if this method will work for folders stored in Office 365 SharePoint 2013? If not, do you have any suggestions for copying a folder structure without the files in SharePoint 2013? Thanks!
LikeLike
This post will only work with local folders not SharePoint or Office 365 directly. What you could do though is sync a SharePoint or Office 365 library locally using OneDrive for Business then the xcopy method will work since you are just playing with local folder structure and OneDrive will take care of syncing the new folder structure back up to SharePoint/Office 365.
LikeLike
Hi , I’ve actually found a way to do this for Sharepoint
1) Map the Sharepoint Folder as a Mapped drive locally on your machine ( https://pariswells.com/blog/random/how-to-map-sharepoint-document-library-as-network-drive-letter )
2) Per Cameron Article perform a clone to your local machine ( xcopy to sharepoint does not work ) e.g.
xcopy “X:\1718ClientFinances\*” “C:\Temp\FY\*” /T /E
Now use Explorer to copy the folders from here to the new Directory
LikeLike
Nice feedback, thanks for the tip.
LikeLike
Wow! Great, this worked like a cham, duplicate the 2017 folders for 2018!
LikeLiked by 1 person
Regally, Great work.. Thanks a lot
LikeLiked by 1 person
hello.. can anyone tell me why I am getting the invalid parameter error message?
xcopy “T:\2 – FORECAST\2018\June Forecast” “T:\2 – FORECAST\2018\September Forecast” /T
LikeLike
Kinda late but it may be useful to someone…
Most likely it’s because of the special caracter “–” in the folders’s names.
It could be solved either by temporarily removing the problematic character (or replacing it with a regular “-” character), or by putting a “chcp” command (change codepage) before the xcopy command (or robocopy – see my message posted on 2019-07-15). I always use “chcp 1252” in my robocopy scripts, to deal with accentuated characters in french, but I’m not sure if it includes this particular character, which may be available in Unicode only.
** I just tested : a xcopy command or a robocopy command actually works with this folder name without changing the codepage (default is 850 which is “latin multilangue I” according to WinHex), so I’m not sure what went wrong in this case. Perhaps you actually used the special “” quotation marks (93 and 94 in hexadecimal – I copy pasted from your message to WinHex to verify) instead or the regular ” quotation marks (22 in hexadecimal) ? I tried with those special quotation marks and I get : “Nombre de paramètres non valide”.
Gabriel, France
LikeLiked by 1 person
Thanks for this info Gabriel, and for providing a solutions I’m sure it will help others 🙂
LikeLike
xcopy f\folder\*.* g:\folder\*.* /t /e
For me, this is also copying the files. 😦
LikeLike
Hi maybe a different variant of xcopy that we are using. The windows version I use has case insensitive parameters so the lowercase /t /e should work but it is defined as uppercase in the documentation for xcopy https://commandwindows.com/xcopy.htm
LikeLike
Worked great! Thanks!
LikeLike
Thanks Cameron! If ever you wondered if anyone ever finds posts like this useful, then wonder no more – we do! Cheers
LikeLiked by 1 person
Haha thanks. I do often wonder!
LikeLike
This did not work for shared folders
LikeLike
Works also with :
robocopy /E /DCOPY:T /XF *
/XF * excludes all files, while /DCOPY:T preserves directories’ timestamps (and /E processes subdirectories as well, including empty ones).
LikeLiked by 1 person
How to copy all the files without copying an entire folder name and structure? I mean if I want to copy only files inside various directories without the directory structure, could I do with xcopy option, or do I have to perform one by one?
LikeLiked by 1 person
I haven’t tried it, but several people seem to have been successful just using copy and a for loop https://stackoverflow.com/questions/585091/using-xcopy-to-copy-files-from-several-directories-to-one-directory let me know how you go.
LikeLiked by 1 person
Thank you for your kindness. I am not an expert, however, I tired “xcopy e:\*.* f:\ALLinONE /s” . It could not be fully satisfied, but makes me happier than copy each by each. This technique will maintain the original folder structure(i.e. e:\) as it copies the files(into the f:\ALLinONE).
LikeLiked by 1 person
Anyway, finally I tried xxcopy freeware program, and use command “xxcopy e:*.* f:\ALLinONE /SL” then I got more happier result. But this xxcopy option of /SL(Flattens subdirectories, add-name-Left) results 700 files in each 700 directories and sub-directories into one( f:\ALLinONE) directories without the directory structure, however the file name changed. All files have their previous located directory_sub-directory names on their new names.
LikeLiked by 1 person
Thanks for replying with your solution ☺
LikeLike
Will this work using a drobox folder? I tried using the path but it did not work. Thank you
LikeLike
For anyone else beating their head against the wall to get this to work you must leave out the quotes and you have to be in the root directory if you’re source and destination string contains the root. The image showing the example in the DOS screen will not work as you see it there.
LikeLiked by 1 person
You saved my life for months. I forgot to comment. Thank you! 🙂
I am sure you are expert, can you help me for this?
“After moving my files to another drive my folder’s modified date is updated. Is there way to change folder’s modified date based on the last modified file’s date in the folder? So i can keep my folders like old times.”
LikeLiked by 1 person
“After moving my files to another drive my folder’s modified date is updated. Is there way to change folder’s modified date based on the last modified file’s date in the folder? So i can keep my folders like old times.”
Not sure about xcopy, but as I replied here on 2019/07/15, folders’ timestamps can be left unchanged with Robocopy.
robocopy [source] [destination] /E /DCOPY:T /XF *
This copies an empty directory (folder) tree, preserving all files’ timestamps (which is the default behaviour) and all folders’ timestamps (with the /DCOPY:T switch). To also copy the files, simply remove the /XF * switch.
The only other Windows tools I know which allow to preserve all timestamps (including folders’ creation and modification timestamps) when copying a folder and its subfolders are :
– FastCopy, a GUI program which may be based on Robocopy (not sure but it has a similar behaviour, and the same bug in a very rare situation where there’s a conflict between the actual name of a file A being the same as the so-called “short name” of a file B — details here : http://sysadmin1138.net/mt/blog/2011/04/robocopy-limitations.shtml)
– Synchronize It, a GUI program which I’ve been using for years for transfer / synchronization purposes, streamlined and efficient, and contrary to robocopy or FastCopy or xcopy it allows to unselect specific files or folders before the copy, while still preserving the parent folders’ “modified” timestamps, although (since this is the main subject of this article) it doesn’t allow to copy an entire folder structure without copying at least one file per folder — I mean, it does copy empty folders, but when unselecting all files from a non-empty folder then the whole folder is ignored (it also has a bug which I discovered back in 2015 and reported to the author : the latest officiel release, version 3.5, corrupts so-called “sparse” files, a relatively little known NTFS feature which reduces the allocated size of files having many empty sectors, and which is often activated by various downloading programs unbeknownst to the user ; the author provided me with a corrected beta version, which I’ve been using ever since with no issue, but still hasn’t integrated that fix into a new official release, as he was working on new features, and had less time to do so in recent years — that’s what he explained to me just a few days ago, when we had a brief chat early in the morning as he was making breakfast for his children :^p ; still, that beta version is available here on his website, although it’s not explicitly referenced in the download section : grigsoft.com/wndsyncbu.zip ; so I would recommand installing Synchronize It with the current v. 3.5 installer, then replacing the wndsync.exe file [modified 2009/12/05] with the one from the beta update ZIP archive [modified 2015/10/04] – and perhaps donating a few bucks if you like it and can afford it, to encourage the guy to finally release an official 3.6 update !).
It should also be noted that although Robocopy preserves all the attributes pertaining only to metadata (“hidden”, “archive”, “system”…), it does not preserve the “compressed” attribute which involves a different way of writing the file’s contents ; not sure about the “sparse” attribute, I’ve had inconsistent experiences. Synchronize It does preserve NTFS compression (and v. 3.6 beta mentioned above preserves the “sparse” nature of “sparse” files).
Since I mentioned “sparse” files, as a now very tangential remark : the only tool I know which can turn a non-sparse file into a sparse file and actually de-allocate its empty clusters is a CLI program called SparseTest.exe, which I could only get through web.archive.org as the original website is now defunct. So it’s quite old, but works flawlessly. The native multi-purpose Windows tool fsutil can set the “sparse” attribute (fsutil sparse setflag [filename]), but it doesn’t re-write it, it only affects (I presume), future writings. Strangely, I couldn’t find a single tool to remove the “sparse” status of a file “in-place” once it’s set, the only way is to copy it with a tool which doesn’t preserve “sparse-ness” (like the basic Windows Explorer copy-paste, or the “copy” command in cmd.exe).
Hope it helps someone, somewhere, someday !
LikeLiked by 1 person
Thanks for taking the time to leave such a detailed response Gabriel.
LikeLike
Hi, I know absolutely nothing about running commands, etc, but I followed your instructions, and I was able to do this easily without ruining my laptop. Thanks so much for this. I truly appreciate it.
LikeLiked by 1 person
Thanks. It worked.
LikeLiked by 1 person
Thank you. It worked fine. It helped me a lot.
LikeLiked by 1 person
This was awesome. I used it for file on my local C drive but if you need to use it for one drive I would set it up on C and then copy across. I cant thank you enough.
LikeLiked by 1 person
Thanks for the comments and kind feedback 🙏
LikeLiked by 1 person
Another tax year, another folder-duplication headache averted. The gift that keeps on giving – thanks Cameron!
LikeLiked by 1 person
Thanks for the annual comments Greg 😂
LikeLike
Hello!
Thanks for sharing the trick.
But this copies subfolder structure also. I want to copy only the main folder structure. How to do?
Thanks.
LikeLike
This is Amazing. Really helped. Thank you very much.
LikeLiked by 1 person
Hi,
I am looking to copy a folder structure to all subfolders in a folder, not just to the one folder, can you assist?
LikeLike
Hi Ryan, can you give example of the folder structure, both source and destination and I might be able to help?
LikeLike
I come back to this article at the end of every fiscal year. It’s amazing and saves so much time. Thank you so much!
LikeLiked by 1 person
Thanks for leaving the comment Mike 🙂
LikeLike
C:\Users\Tricia>xcopy c:\users\Tricia\Documents\My Documents\PARKER ET AL\DP\2021 C:\Users\Tricia\Documents\My Documents\PARKER ET AL\DP\2022 /T
Invalid number of parameters
LikeLiked by 1 person
Hi Tricia – commands have trouble with the file path if it contains spaces. Here’s an article that explains it in detail (essentially you need to surround your file paths with double quotes) > https://www.howtogeek.com/694949/how-to-escape-spaces-in-file-paths-on-the-windows-command-line/#:~:text=Command-line%20environments%20like%20the%20Windows%20Command%20Prompt%20and,%E2%80%9Cescape%E2%80%9D%20it.%20%E2%80%9CEscaping%E2%80%9D%20a%20character%20changes%20its%20meaning.
Give this a try
xcopy “c:\users\Tricia\Documents\My Documents\PARKER ET AL\DP\2021” “C:\Users\Tricia\Documents\My Documents\PARKER ET AL\DP\2022” /T
LikeLike
Organizing folders for next year and this was an amazing help.
Thank you so much. 🙂
LikeLiked by 1 person
C:\Users\secondengineer>xcopy “I:\Engineering” “C:\Users\secondengineer\Desktop\Desk Directory” /T /E
Insufficient memory
But I have 380gb free space, does it mean insufficient RAM ?
LikeLiked by 1 person
I’d say it’s referring to RAM but I haven’t hit this limit before. How big is the folder structure and how much RAM do you have? Simple solution to try first would be do a reboot to free up as much RAM as you can and try again straight after a reboot.
LikeLike
Thanks a lot for so simple solution, Now no need to take back up of full folder everytime
LikeLiked by 1 person
worked for me as well. thanks
LikeLiked by 1 person