{"id":15903,"date":"2009-11-26T07:00:00","date_gmt":"2009-11-26T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/11\/26\/when-you-want-to-copy-a-file-into-a-folder-make-sure-you-have-a-folder\/"},"modified":"2009-11-26T07:00:00","modified_gmt":"2009-11-26T07:00:00","slug":"when-you-want-to-copy-a-file-into-a-folder-make-sure-you-have-a-folder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20091126-00\/?p=15903","title":{"rendered":"When you want to copy a file into a folder, make sure you have a folder"},"content":{"rendered":"<p>\nThis story is inspired by an actual customer problem.\n<\/p>\n<p>\nThe program <code>LitWare.exe<\/code> is used for TPS management,\nand when you want to create a new TPS report,\nyou have to pick a\n<a HREF=\"http:\/\/www.chrisglass.com\/journal\/downloads\/TPSreport.pdf\">\ncover sheet<\/a>.\nThe program shows you the cover sheets that have been defined,\nwhich it loads from the <code>C:\\TPS Cover Sheets<\/code> directory.\n<\/p>\n<p>\nThe customer found that on one of the machines,\nthe cover sheets weren&#8217;t showing up,\neven though the standard system setup copies a sample\ncover sheet into the <code>C:\\TPS Cover Sheets<\/code> directory.\nThe error message they got was\n<i>Cannot load cover sheets. The directory name is invalid<\/i>.\n<\/p>\n<p>\nThe customer did some troubleshooting and determined that\n&#8220;The cover sheet directory is missing,\nand we have a file instead.&#8221;\n<\/p>\n<pre>\nC:\\&gt;dir\n Volume in drive C is INITECH\n Volume Serial Number is BAAD-F00D\n Directory of C:\\\n09\/18\/2006  02:43 PM                24 autoexec.bat\n09\/18\/2006  02:43 PM                10 config.sys\n03\/18\/2009  10:30 AM    &lt;DIR&gt;          Program Files\n11\/21\/2008  01:04 PM             1,677 TPS Cover Sheets\n02\/20\/2008  10:39 AM    &lt;DIR&gt;          Users\n05\/29\/2009  02:23 PM    &lt;DIR&gt;          Windows\n               2 File(s)          1,711 bytes\n               3 Dir(s)  229,031,751,680 bytes free\n<\/pre>\n<p>\nOne of my colleagues employed psychic powers to determine that\nat the time the customer tried to install the sample cover sheet\non the machine,\nthe <code>C:\\TPS Cover Sheets<\/code> directory <i>did not yet exist<\/i>,\nand that the batch file they used to set up a new computer\njust does a\n<code>copy \\\\server\\TPSConfig\\Sample.tps \"C:\\TPS Cover Sheets\"<\/code>,\nwhich results in a file being created with the name\n<code>C:\\TPS Cover Sheets<\/code>.\n<\/p>\n<p>\nThe customer was surprised by this conclusion.\n&#8220;I would think that copy will fail if the\n<code>C:\\TPS Cover Sheets<\/code> directory doesn&#8217;t exist,\nbut this might be our problem.\nWe&#8217;ll look into it.&#8221;\n(I guess this customer never used the copy command to copy a file\nto a new name.)\n<\/p>\n<p>\nIf the destination of a <code>copy<\/code> command exists and is a\ndirectory, then the source files are copied into that directory.\nIf the destination of a <code>copy<\/code> command does not exists\nor if it exists and is a file,\nthen the destination is treated as a file name for the destination.\n(If there is more than one source file, then they are concatenated\nas if they were text files.)\n<\/p>\n<p>\nThe customer went back and checked the scripts,\nand the line they used was almost exactly what my colleague\npredicted:\n<\/p>\n<pre>\ncopy \"\\\\INITECH\\Defaults\\Sample cover sheet.tps\" \"C:\\TPS Cover Sheets\" \/Y\n<\/pre>\n<p>\nIf the <code>C:\\TPS Cover Sheets<\/code> directory hasn&#8217;t been created\nyet, then that would explain the behavior they&#8217;re seeing:\nThe <code>copy<\/code> command sees that the destination doesn&#8217;t exist\nand assumes you are doing a file-to-file copy\n(as opposed to a file-to-directory copy).\nIn this case, the problem was that copying a sample cover sheet was\na step they added to their setup scripts, but they added it before\nthe step that creates the cover sheet directory.\nReordering the two steps fixed the problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This story is inspired by an actual customer problem. The program LitWare.exe is used for TPS management, and when you want to create a new TPS report, you have to pick a cover sheet. The program shows you the cover sheets that have been defined, which it loads from the C:\\TPS Cover Sheets directory. The [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-15903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>This story is inspired by an actual customer problem. The program LitWare.exe is used for TPS management, and when you want to create a new TPS report, you have to pick a cover sheet. The program shows you the cover sheets that have been defined, which it loads from the C:\\TPS Cover Sheets directory. The [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=15903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=15903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=15903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=15903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}