Jump to content

Recommended Posts

Posted

Ok I've got a Folder in location 1, a folder in location 2 and i'm going to be using a rather large robocopy script to Move (not copy, move!) all files form all those directories on a set date....

 

Now either once the files are moved, or during the file move process I need the files to keep their current names but append 4 numbers with an underscore infront of the current file name so doc1.doc would look like 0123_doc1.doc

 

I should also mention that the 0123 number needs to be pulled from active directory, luckily @ChrisMiles created a fantastic little program for pulling out AD attributes for me so i've an application to do that (see this thread: http://www.edugeek.net/forums/windows-7/102433-environment-variables-gpp-2.html)

 

Any suggestions? :D

Posted
Not really helping but copy is a safer operation then deleting after the transfer has been verified. As to the passing of individual rename appends it may be easier to use something like VBS that grabs the variables then sends the commands to robocopy via a shell command. It depends on how you are generating the numbers, per file or per batch as to how efficient this will be.
Posted
Not really helping but copy is a safer operation then deleting after the transfer has been verified. As to the passing of individual rename appends it may be easier to use something like VBS that grabs the variables then sends the commands to robocopy via a shell command. It depends on how you are generating the numbers, per file or per batch as to how efficient this will be.

 

The reason for preferring the move over copying is that in 5 years time this system will be running for every single student in the school, if we're copying we're going to be duplicating the data in two places on the same drive. Whereas in case of any erroneous moves we will still have shadow copies and backups in place to recover should the worst happen. (will be rigorously tested before hand though i must add).

 

I have a rough idea of how to use the GetADAttributes.exe to parse the AD attribute containing the 4 digit number, but i think my idea could be very long winded and over the top.

 

Just as a more precise example:

Location 1 = folder within students home folder

Location 2 = folder within a share that students will be locked out of once the files are moved across

 

Each Student has an individual folder named "Bloggs, Joe" for example in location 2, within that folder is 4 folders called Unit 1, 2 ,3 ,4. Each individual student has their own specific 4 digit candidate number in AD + SIMS, every file copied for that particular student needs to have that 4 digit candidate number appended.

Posted

Good little utility that, though it still seems focused on doing things manually by selecting a folder etc. Using Add prefix 1234_ works fine manually but isn't an option in the long run.

 

I need to automate it for 100's of folders based on the information within a set field in AD. Unless this program has a command line utility I'm not seeing?

Posted

Just making a little test script and struggling, hopefully someone more experienced with this can fix my problem here:

for %%f in ("H:\Cambridge Nationals\Unit 1\") do chdir /D %%f
for /f %%g in ('C:\GetADAttributes.exe st') do for %%e in (*) do  rename "%%e" "%%g_%%e"  
for /f %%a in ('C:\GetADAttributes.exe givenName') do for /f %%b in ('C:\GetADAttributes.exe sn') do for /f %%c in ("H:\Cambridge Nationals\Unit 1\*") do for /f %%d in ("T:\ICT\OCR Coursework Repository\2012-2013\Year 10\%%b, %%a\Unit 1") do move "%%c" "%%d"

 

First line changes directory to a set folder within that users home folder

the second line renames every file within that users folder with the candidate ID from active directory

The third line: the first part gets the forename, secondly the surename, third the home path and fourth the path it needs moving to, then attempts to do a move command.... problem is as each section is executed on a separate line in a batch file it doesn't like the fact the paths have spaces in them and so once finally executed i end up with this as the final execution:

Move "H:\Cambridge" "T:\ICT\OCR"

1. How do i stop it from losing the full path?

2. This is currently only a test, I'm very happy with how the renaming from AD has gone but i need to be able to run this from an admin perspective whereas i currently have it setup to run per user (H:\ etc) and it doesn't appear to like UNC paths either! HELP!

Posted

If you're doing it with spaces you need a tokens variable, else it splits it up per space.

 

e.g.

 

for /f %%d in ("C:\test\AB C") do echo %%d

Won't work.

for /f "tokens=*" %%d in ("C:\test\AB C") do echo %%d

Will work.

 

Steve

  • Thanks 1
Posted (edited)

Thanks steve that worked a treat, so i've now got this:

chdir /D "H:\Cambridge Nationals\Unit 1\"
for /f %%g in ('C:\GetADAttributes.exe st') do for %%e in (*) do  rename "%%e" "%%g_%%e"  
for /f %%a in ('C:\GetADAttributes.exe givenName') do for /f %%b in ('C:\GetADAttributes.exe sn') do for /f "tokens=*" %%c in ("H:\Cambridge Nationals\Unit 1\*") do for /f "tokens=*" %%d in ("T:\ICT\OCR Coursework Repository\2012-2013\Year 10\%%b, %%a\Unit 1\") do move "%%c" "%%d"

 

And that tells me "cannot move multiple files to a single file" What's the syntax for the move command to make it move files from one folder to another rather than whatever it's currently trying to do?

 

I've also no idea how I'm going to make this executable yet, I guess i can't actually make this executable from an admin perspective as I'm pulling so many things out for the logged on user from AD...

Edited by mrbios
Posted

Are you trying to move directories or files though?

 

As an example:

 

for /d %%a in ("C:\test\test2\*") do move "%%~a" "C:\test\test3\"

 

Will move every folder (and files within) from test2 to test3

 

Steve

Posted

Ah I got it, used robocopy instead

chdir /D "H:\Cambridge Nationals\Unit 1\"
for /f %%g in ('C:\GetADAttributes.exe st') do for %%e in (*) do  rename "%%e" "%%g_%%e"  
for /f %%a in ('C:\GetADAttributes.exe givenName') do for /f %%b in ('C:\GetADAttributes.exe sn') do for /f "tokens=*" %%c in ("H:\Cambridge Nationals\Unit 1") do for /f "tokens=*" %%d in ("T:\ICT\OCR Coursework Repository\2012-2013\Year 10\%%b, %%a\Unit 1") do robocopy /move /e "%%c" "%%d"

 

So that works, renames the files within Unit 1, prefixes them with their candidate number from AD then moves the Unit 1 folder to their named folder within T:\

 

So....that works BUT now ideally i need to be able to do this as an admin, so @ChrisMiles any chance of modifying that GetADAttributes so that a domain admin can select a specific users attributes to call up? If it could be done by running say "C:\GetADAttributes.exe givenName bloggsjoe" or something like that it'd be incredible, I know I'm probably asking a hell of a lot there though, and will likely need to find another way of doing this

  • 2 weeks later...
Posted
Cheers will take a look at that, at the moment I've got an ex-6thformer who has been working as a software engineer for 2 years helping me out, we're making a purpose built application in C# to do everything i need, quite a fun little project overall :D He owes us for having gained an education and practically gained his job because of our department so luckily it's all free hehe :p

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...