Forum Moderators: phranque

Message Too Old, No Replies

Batch moving files in subfolder to one folder

         

ntbgl

1:18 am on Jul 30, 2009 (gmt 0)

10+ Year Member



In one folder, I have tens of thousands of files spread over a couple of hundred sub-folders that I need to move to one central folder. No files have duplicate names.

/files/1/1a.ext
/files/1/1z.ext
/files/2/2a.ext
/files/2/2z.ext
/files/999/999a.ext
/files/999/999z.ext

I need them all to go to the files directory.

/files/1a.ext
/files/1z.ext
/files/2a.ext
/files/2z.ext
/files/999a.ext
/files/999z.ext

Is there a command I can use at the command prompt to move all these files?

jdMorgan

2:43 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you doing this to re-arrange the filesystem, or is your goal to change the URL?

If you simply want to move the files and are unconcerned with the URL, then this is a *nix operating system question, and I'll pass on it with the hope that you'll get a better answer from a better/more-confident command line guru (getting the command wrong might be disastrous). I will comment, however, that I would recommend that you copy the files instead of moving them, so as to leave you with more options should you have a typo in the command...

If the goal here is centered on simplifying URLs, remember that a URL and a filepath are not the same thing, and changing one does not necessarily mean you need to change the other. Modules like mod_rewrite, which act in the URL-to-filename translation phase of the Apache API, can be used to map old URLs to new filepaths, or vice-versa.

Changing the URLs will -at least temporarily- likely set back your URLs' search rankings - for anywhere from a few weeks to a year. Changing the filepaths -specifically moving thousands of files into a single directory- will likely affect your server performance, and is more often avoided than done intentionally.

For example, many large sites use a system where the first letter of the 'page name' is used as the directory, which means that under 'files' you'd have 26 subdirectories named 'a' through 'z', with mod_rewrite used to make these subdirectories invisible in the URL. The 'pages' would be stored in those subdirectories so that the 'files' directory would contain far fewer files (only 26 directories), and each subdirectory --on average-- could contain 26 times more files before filesystem performance problems arise. If some files have numeric names, there's also the option to add ten more subdirectories -- using numbers as well as letters.

Jim