InterviewSolution
| 1. |
Solve : Move files to folders with same name in Windows? |
|
Answer» I use following command to copy files to folders with same name. Imagefiles - 2015 trips Filenames are in a format like these: Quote Imagefiles - 2015 trips - France - 01.jpg for /f %x in ('dir /ad /b') do move "%x*.*" "%x\" just cuts the first part of name of folder and says, "Cannot move MULTIPLE files to a single file" and syntax errors in some cases.do that dir /ad /b at a command prompt and you just get folders without anything else. where you have "%x*.*" that with would PARSE to "Imagefiles - 2015 trips*.*" and then you try to move it to "Imagefiles - 2015 trips\" still don't know what you are trying to achieve - do you want to move all your folder up one level? or into the same folders? the first move argument should probably be "%x\*.*" for starters. and is this done from within a .BAT file? The thread title says 'Move files to folders with same name" But the folder and file names you've provided are not the same- You want to move files that have names that begin with the same name as a folder into that folder. That's a seemingly minor detail that changes the solution a lot. Code: [Select]for /f %x in ('dir /ad /b') do move "%x*.*" "%x\" for /f uses space as a delimiter by default. As a result You'll only see the first part of the dir output line line up to the first space. basically you'll go through every folder- but the %x variable will only ever be "Imagefiles" for the set of folders you mentioned. you need to add "DELIMS=" to indicate that you don't want to split the text: Code: [Select]for /f "DELIMS=" %x in ('dir /ad /b') do move "%x*.*" "%x\" You can also get a simpler command by using for /D which will iterate over directories: Code: [Select]for /d %P in (*.*) do move "%P*.*" "%P" Thank you for your HELP and also for explanation! |
|