Jump to content

Script to Copy files into into individual folders?


Recommended Posts

Posted

I have 400+ PC's that all have some log files i need to move off..

 

I want to make a script/Batch file that will do the following when the user logs in:

 

Creates a Folder on a network share with the individual users name

Moves the Log files from the Local PC to the create User folder

Deletes the Local Files after the move

 

Sounds simple enough..

 

Its the Creating a folder with the user name i cant figure out..

 

Im hoping its something simple.. Im trying to do this all with a batch file ATM..

 

THanks

Posted (edited)

If you are using Windows batch commands then it will be something like;

 

MD "\\servername\sharename\folder\%username%"

 

This should work as long as the username does not contain any characters that are invalid in folder names.

 

Without any error checking, the script will look something like;

 

MD "\\servername\sharename\folder\%username%"
COPY "Path to log file" "\\servername\sharename\folder\%username%"
DEL "Path to log file"

Edited by ajbritton
Posted
MD "\\servername\sharename\folder\%username%"

COPY /Y "Path to log file" "\\servername\sharename\folder\%username%"

DEL /Q "Path to log file"

 

will possibly overwrite log from previous login if the name is the same the user would need to have write permissions to the share and sub folders of course! which if they knew they could potentially access and delete

Posted
will possibly overwrite log from previous login if the name is the same the user would need to have write permissions to the share and sub folders of course!

 

You could set the permissions to allow creation only and no deletion which would mitigate this slightly.

 

To avoid overwriting log files, you could always tag the date onto the end of them -

 

copy C:\blah\blah\log.txt \\server\blah\logs\%username%%date:/=-%.txt

 

or if you wanted to get clever with it,

 

copy C:\blah\blah\log.txt \\server\blah\logs\server\%date:~6,4%-%date:~3,2%-%date:~0,2%-%username%.txt

 

which will give you the date at the start of the filename in a nice sortable order (YYYY-MM-DD)

 

which if they knew they could potentially access and delete

 

There's an awful lot of shares like that on the network which can't be avoided though - things like the Promissor exam software etc which demand a shared folder with full permissions. :(

Posted
There's an awful lot of shares like that on the network which can't be avoided though - things like the Promissor exam software etc which demand a shared folder with full permissions. :(

 

I really HATE it when suppliers/support staff ask you to set up Full Control when they obviously don't even understand what it means or implies. I have never seen any justification for Full Control for any application.

 

Sorry. It's a pet peeve !!

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...