Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   General Business Knowledge (http://www.greenguysboard.com/board/forumdisplay.php?f=10)
-   -   Help! Creating Folders & Moving Files (http://www.greenguysboard.com/board/showthread.php?t=70242)

Greenguy 2019-01-09 10:55 AM

Help! Creating Folders & Moving Files
 
I've got roughly 1800 movie files in a folder on the server named like this:
2BTB_061209_Cindy.mp4
2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah.mp4

What I need to do is put them in a folder named the same as their filename, so I'll have:
2BTB_061209_Cindy/2BTB_061209_Cindy.mp4
2BTB_061211_Mia/2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah/2BTB_061219_Aaliyah.mp4

So I copy the file name, create a new folder & name it after the file, then drag the file into the new folder.

I can't think of a faster way to do this, but maybe one of you can...

Useless 2019-01-09 12:43 PM

Try the free version of FiletoFolder. https://www.thecodeline.com/products...-feature-list/

Install it, then close it. Then, when your right click on a file, the context menu should have the FiletoFolder option. It will automatically create a folder of the same name and place the file inside.

Greenguy 2019-01-09 03:37 PM

Quote:

Originally Posted by Useless Warrior (Post 554963)
Try the free version of FiletoFolder. https://www.thecodeline.com/products...-feature-list/

Install it, then close it. Then, when your right click on a file, the context menu should have the FiletoFolder option. It will automatically create a folder of the same name and place the file inside.

That does look handy, but these are on the server so I'm doing everything via FTP.

Useless 2019-01-09 04:16 PM

Shit. I missed that part. It can be done in PHP, but I don't have those sort of skills. (I'm almost strictly a database interaction guy) CD34 could have created a script in 3 and half minutes while eating Arby's.

HowlingWulf 2019-01-10 05:44 PM

Here is a PHP script to automate it:

Code:

$path = ".";
$extensions = array( "mp4" );

$files = array_diff(scandir($path), array('.', '..'));

foreach ( $files as $file ) {
        if ( ! is_file ( $file ) ) continue;
        $file_parts = pathinfo( $file );
        if ( ! in_array( $file_parts['extension'], $extensions ) ) continue;

        if ( ! file_exists( $file_parts['filename'] ) && ! mkdir( $file_parts['filename'] ) ) { echo "Oops! Could
not create directory {$file_parts['filename']}\n"; continue; }

        $new_loc = $file_parts['filename'] . "/" . $file;
        if ( ! file_exists( $new_loc ) && ! rename( $file, $new_loc ) ) { echo "Oops! Could not move {$file} to {$
new_loc}\n"; continue; }

        echo $file . " moved to {$new_loc} successfully.\n";
}


Before:
Quote:

-bash-4.1$ ll
total 4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:50 2BTB_061209_Cindy.mp4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:51 2BTB_061211_Mia.mp4
-rw-rw-r-- 1 admin www-data 0 Jan 10 17:51 2BTB_061219_Aaliyah.mp4
-rw-rw-r-- 1 admin www-data 662 Jan 10 17:49 greenguy_help.php

After:
Quote:

-bash-4.1$ php greenguy_help.php
2BTB_061209_Cindy.mp4 moved to 2BTB_061209_Cindy/2BTB_061209_Cindy.mp4 successfully.
2BTB_061211_Mia.mp4 moved to 2BTB_061211_Mia/2BTB_061211_Mia.mp4 successfully.
2BTB_061219_Aaliyah.mp4 moved to 2BTB_061219_Aaliyah/2BTB_061219_Aaliyah.mp4 successfully.
-bash-4.1$ ll
total 16
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061209_Cindy
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061211_Mia
drwxrwsr-x+ 2 admin www-data 4096 Jan 10 17:51 2BTB_061219_Aaliyah
-rw-rw-r-- 1 admin www-data 662 Jan 10 17:49 greenguy_help.php

Greenguy 2019-01-11 07:23 AM

OMFG!!!

OK, so I save the code* as greenguy_help.php then upload it to the server and then how do I run it? (I'm not tech savvy lol) Just go to it in a browser? "Execute" it via FTP?

*Is there supposed to be a ?> at the end of the code?

PS - If this works, Ramster will need your Paypal :D

Ramster 2019-01-11 08:10 AM

Quote:

Originally Posted by Greenguy (Post 554991)
OMFG!!!

OK, so I save the code* as greenguy_help.php then upload it to the server and then how do I run it? (I'm not tech savvy lol) Just go to it in a browser? "Execute" it via FTP?

*Is there supposed to be a ?> at the end of the code?

PS - If this works, Ramster will need your Paypal :D

I wouldn't run anything on my servers, or clients. I would just ask the hosting company, NationalNet to do this as they are paid to do it lol

Talk on Skype, if Skype actually updates you |lol|

Greenguy 2019-01-11 08:29 AM

Quote:

Originally Posted by Ramster (Post 554998)
I wouldn't run anything on my servers, or clients. I would just ask the hosting company, NationalNet to do this as they are paid to do it lol

I'd run shit on your servers no problem |couch|

HowlingWulf 2019-01-11 08:47 AM

Quote:

Originally Posted by Greenguy (Post 554991)
OMFG!!!

OK, so I save the code* as greenguy_help.php then upload it to the server and then how do I run it? (I'm not tech savvy lol) Just go to it in a browser? "Execute" it via FTP?

Upload it to the directory your MP4s are in. If you have shell access, run it from the command line. If not you can run it from your browser, though the output messages will be all on one line.

Quote:

Originally Posted by Greenguy (Post 554991)
*Is there supposed to be a ?> at the end of the code?

It's optional.

Useless 2019-01-11 08:58 AM

I just tested it and works smoothly.

Vbulletin put two line breaks in when Howling pasted the code into the code thing. Note that the extension part is case sensitive.
------------------------------------------------------------------

$path = ".";
$extensions = array( "mp4" );

$files = array_diff(scandir($path), array('.', '..'));

foreach ( $files as $file ) {
if ( ! is_file ( $file ) ) continue;
$file_parts = pathinfo( $file );
if ( ! in_array( $file_parts['extension'], $extensions ) ) continue;

if ( ! file_exists( $file_parts['filename'] ) && ! mkdir( $file_parts['filename'] ) ) { echo "Oops! Could not create directory {$file_parts['filename']}\n"; continue; }

$new_loc = $file_parts['filename'] . "/" . $file;
if ( ! file_exists( $new_loc ) && ! rename( $file, $new_loc ) ) { echo "Oops! Could not move {$file} to {$new_loc}\n"; continue; }

echo $file . " moved to {$new_loc} successfully.\n";
}
?>
-----------------------

Useless 2019-01-11 09:00 AM

If you're scared, change the "mp4" to "jpg" in a folder of test images on your server, then go to the address of this php file in your browser. It won't hurt anything.

Quote:

HCP032001.JPG moved to HCP032001/HCP032001.JPG successfully. HCP032002.JPG moved to HCP032002/HCP032002.JPG successfully. HCP032003.JPG moved to HCP032003/HCP032003.JPG successfully.
In that example, I changed the extension to "JPG" because it is case sensitive.

Greenguy 2019-01-11 09:09 AM

YOU GUYS ROCK!!! |party2

If it was on mine or Ramster's server, I'd run it myself, but like Ramster said, it's a client's server, so we'll have the host do it.

Useless 2019-01-11 09:41 AM

#pussy :D

Greenguy 2019-01-12 03:43 PM

1 - Worked PERFECTLY! |thumb

2 - Is it by any chance easy to go from this:
2BTB_061209_Cindy.mp4
2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah.mp4

To this:
2BTB_061209_Cindy/source/2BTB_061209_Cindy.mp4
2BTB_061211_Mia/source/2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah/source/2BTB_061219_Aaliyah.mp4

HowlingWulf 2019-01-12 05:47 PM

Quote:

Originally Posted by Greenguy (Post 555038)
1 - Worked PERFECTLY! |thumb

2 - Is it by any chance easy to go from this:
2BTB_061209_Cindy.mp4
2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah.mp4

To this:
2BTB_061209_Cindy/source/2BTB_061209_Cindy.mp4
2BTB_061211_Mia/source/2BTB_061211_Mia.mp4
2BTB_061219_Aaliyah/source/2BTB_061219_Aaliyah.mp4

Sure. Try this:

PHP Code:

<?php
$path 
".";
$extensions = array( "mp4" );

$files array_diff(scandir($path), array('.''..'));

foreach ( 
$files as $file ) {
        if ( ! 
is_file $file ) ) continue;
        
$file_parts pathinfo$file );
        if ( ! 
in_array$file_parts['extension'], $extensions ) ) continue;

        if ( ! 
file_exists$file_parts['filename'] ) && ! mkdir$file_parts['filename'] ) ) { echo "Oops! Could 
not create directory 
{$file_parts['filename']}\n"; continue; }

        if ( ! 
file_exists$file_parts['filename'] . "/source" ) && ! mkdir$file_parts['filename'] . "/source" 
) ) { echo "Oops! Could not create directory {$file_parts['filename']}/source\n"; continue; }

        
$new_loc $file_parts['filename'] . "/source/" $file;
        if ( ! 
rename$file$new_loc ) ) { echo "Oops! Could not move {$file} to {$new_loc}\n"; continue; }

        echo 
$file " moved to {$new_loc} successfully.\n";
}

echo 
"Done\n";


Greenguy 2019-01-13 08:33 AM

Ramster & I |bow| to you!


All times are GMT -4. The time now is 04:20 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc