Batch to Sort by Month, per folder, per user, then RAR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
billiehawkins
Posts: 3
Joined: 10 Oct 2011 14:26

Batch to Sort by Month, per folder, per user, then RAR

#1 Post by billiehawkins » 25 Jan 2012 12:41

I'm looking to create a batch that will take a set of files created in each month/year and rar them to an archive folder, labeling the rar by date and folder path.

Here's the situation - I have a server that has 12 years of ftp files, uploaded to three directories by each user. The user would upload the files every day to their own userdir\folder. Because they were never moved, each folder has thousands of files.

I would like to group and move the files by month and year, keeping them grouped in an Archive folder of the same structure, RAR'd for later retrieval if needed.

There are 3 variables to the structure, so I'm a bit over my head: <multiple directories>, <multiple destinations>, and <multiple months/years>.


Examples: <variables>

Source: \\networkserver\<User1>\<directory1>\<filenames.txt> (50 files Created between 01/01/01 and 01/31/01)
Dest: \\networkserver\<User1>\ARCHIVE\<directory1>\<User1>_<directory1>_01-2001.rar (containing all fifty files from that month).
Source: \\networkserver\<User1>\<directory2>\<filenames.txt> (50 files Created between 01/01/01 and 01/31/01)
Dest: \\networkserver\<User1>\ARCHIVE\<directory2>\<User1>_<directory2>_01-2001.rar (containing all fifty files from that month).


Source: \\networkserver\<User2>\<directory1>\<filenames.txt> (50 files Created between 01/01/01 and 01/31/01)
Dest: \\networkserver\<User2>\ARCHIVE\<directory1>\<User2>_<directory1>_01-2001.rar (containing all fifty files from that month).
Source: \\networkserver\<User2>\<directory2>\<filenames.txt> (50 files Created between 01/01/01 and 01/31/01)
Dest: \\networkserver\<User2>\ARCHIVE\<directory2>\<User2>_<directory2>_01-2001.rar (containing all fifty files from that month).

Real Example:

Source: \\uploader500gb\mary001\newpdfs\edit001.pdf (345 files created between 01/01/01 and 01/31/01)
Dest: \\uploader500gb\mary001\ARCHIVE\newpdfs\mary001_newpdfs_01-2001.rar (containing all 345 from that month and folder of that user).

Source: \\uploader500gb\mary001\reusedpdfs\reused001.pdf (95 files created between 01/01/01 and 01/31/01)
Dest: \\uploader500gb\mary001\ARCHIVE\reusedpdfs\mary001_resusedpdfs_01-2001.rar (containing all 95 from that month and folder of that user).

Source: \\uploader500gb\mary001\errors\pdffail001.pdf (11 files created between 01/01/01 and 01/31/01)
Dest: \\uploader500gb\mary001\ARCHIVE\errors\mary001_errors_01-2001.rar (containing all 11 files from that month and folder of that user).


The batch would group the files into folders named by month and year, then RAR them into archives of the <user>_<folder>_<Month>-<year>.rar, repeat for every <Month> of every <year> for every <directory> within every <USER> folder.

I spent the last 6 hours or so looking at how to chop up the date of a file to get DOS to recognize it; I've looked at winRar's command line structure to see how to grab files and format the naming convention.. But I'm an OS X guy - I understand bash, I get applescript. I know how to read DOS batch, and how to write the basics, but I've never been good at the FOR command and how to use it to grab only certain files, how to loop, how to apply variables to it, and how to recursively check the 3 sub folders of every user folder and sort the files by date.


I'm guessing that I would have to do this in a few steps:


1. Get the <user> folder as a variable
2. Get the <directory> folder as another variable
3. Get the <month> and <Year> as variables
4. Create the <user>\ARCHIVE\<directory>\
4a. Create a <user>_log.txt of archive creation for each folder structure: "Created rar <user>\<directory> for <month>-<year>"
5. Pass the variables to Win rar:
5a. Grab all files from <user>\<directory>\*.* in same <month> and <year>
5b. Create RAR of <user>\ARCHIVE\<directory>\<user>_<month>-<year>.rar
5c. Apply errorlevel logic to verify rar creation.
5d. Continue or repeat, based on success or failure
6. Upon success, Delete the files that were placed into the RAR, after completion, to avoid accidental deletion.
6a. Add to log: "Completed rar and deleted original files of <user>\<directory> for <month>-<year>"
7. Stop within 60 days of current date (leaving -60 days of files untouched in each directory)
8. Repeat with next <user> directory, and repeat inside that with each <directory> and each <month> and <year>


I'm not asking for a handout - I'd be more that willing to put the pieces together. I just don't know where to start with all this - beyond the outline. I am going to keep looking at how to build this, but I would welcome some pointers on this, and maybe I can get a skeleton of it working?

I'll keep posting my code as I get the pieces in place, but I could really use some help. Thanks in advance!

Post Reply