topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 12:35 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: MoveAllTo C:\olddata  (Read 8191 times)

moongoon

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
IDEA: MoveAllTo C:\olddata
« on: February 12, 2007, 12:05 PM »
Seems simple but I've never seen a good solution to this.

Before reinstalling XP I like to *move* the contents of C to C:\OldData.  This greatly aids in installing a fresh, clean copy of Windows.  I'd use this in a WinPE environment so no worries about NTFS or locked files.

Can be a Win32 console application.  Doesn't really need a GUI.  Something like:

Name of Tool    NAME OF TARGET FOLDER (Create if not Present)
MOVEALLTO     C:\OLDDATA

I've heard ROBOCOPY can do this but my mind reels at learning all the syntax :p

Thanks in advance for your consideration!
« Last Edit: February 14, 2007, 05:54 AM by brotherS »

chedabob

  • Participant
  • Joined in 2006
  • *
  • Posts: 34
  • C# Master (if only!!!)
    • View Profile
    • Donate to Member
Re: MOVEALLTO C:\OLDDATA
« Reply #1 on: February 13, 2007, 05:57 AM »
done  ;D

http://chedabob.com/moveall.bat

youd be surprised how simple it was :P

before you run it, be aware, i cannot be held responsible if it goes nuts up. I shouldnt see why it would, but please, test it on some files that aren't critcal. It successfully moves c:\ati to c:\bleh on my machine, but I dont have enough space to test it on my machine

edit1: just tested it on my other drive. It worked fine.
« Last Edit: February 13, 2007, 06:02 AM by chedabob »

moongoon

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: MOVEALLTO C:\OLDDATA
« Reply #2 on: February 13, 2007, 07:05 AM »
Thanks for the attempt!

However I get a:
Cannot move multiple files to a single file error.

The batch file doesn't create the OLDDATA folder.  Nor does it copy system files. It also does not move the subdirectories over.  Shell commands can also be much slower than direct access to Win32API.

I too had forgotten the limitations of the MOVE command.  It was a good thought though!  Thanks again for trying :)

P.S.  I noticed a mention of C# in your member details.  Maybe this code snack would be a good way to beef up your coding skills?  Try looking at this link for help on dealing with files and folders under C#
http://www.codeguru....s/article.php/c5861/
« Last Edit: February 13, 2007, 07:39 AM by moongoon »

cthorpe

  • Discount Coordinator
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 738
  • c++thorpe
    • View Profile
    • Donate to Member
Re: MOVEALLTO C:\OLDDATA
« Reply #3 on: February 13, 2007, 09:36 AM »
Could it be as easy as:

robocopy .\ c:\OldData\ /E /MOVE

 run from the root of C:\

C
« Last Edit: February 13, 2007, 10:09 AM by cthorpe »

moongoon

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: MOVEALLTO C:\OLDDATA
« Reply #4 on: February 13, 2007, 11:23 AM »
Thanks for the input cthorpe!

That gets me closer to using ROBOCOPY.  However, it still balks at some system files or files with weird permissions.  It goes into a loop of Access is Denied.  Waiting 30 seconds..  I guess that means using the /ZB switch eh?

The reason why I think this would be better implemented as a program is that Windows Explorer can create an OLDDATA folder and move all the other folders and files into it in an instant.  Explorer must be using some shortcut to expedite the process and bypass those permission issues.  Maybe it directly accesses the MFT table (I'm no expert).  Maybe it uses standard calls *shrugs*

Thanks again for lending your brains :)

@cthorpe:  Doomo Arigato for the tip.  I did not know XXCOPY could do that!  Will try it out..
« Last Edit: February 14, 2007, 07:58 AM by moongoon »

cthorpe

  • Discount Coordinator
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 738
  • c++thorpe
    • View Profile
    • Donate to Member
Re: MOVEALLTO C:\OLDDATA
« Reply #5 on: February 13, 2007, 12:01 PM »
What about XXcopy http://www.xxcopy.com/index.htm?
There is a free for personal use version.



XXCOPY  C:\  C:\OldData\   /CCY /H /S

That is, copy everything from C:\ to C:\OldData\ and deal with the cyclical issue that could arise (/CCY) and copy hidden/system files.

You could add

/RCY /S
to the end to remove all copied files and subdirectories if you wanted.

moongoon

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: IDEA: MoveAllTo C:\olddata
« Reply #6 on: February 22, 2007, 01:46 PM »
Thanks to everyone for the responses.  However, no pre-made utility has worked adequately.  In an attempt to fire up the coding spirit I've attempted to make an AutoIt3 script to do the job.  It doesn't work but my hope is someone with actual programming skill will notice what is wrong.  It creates the C:\OldData folder, moves the root files to C:\OldData but none of the folders.  Take a look if you can :)

DirCreate("C:\OldData")
FileMove("C:\*.*", "C:\OldData",8)

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile("C:\*.*") 

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
If $file = "OldData" then $file = FileFindNextFile($search)
    If @error Then ExitLoop
DirMove( chr(34) & "C:\" & $file & chr(34), chr(34) & "C:\OldData\" & $file & chr(34), 1)
WEnd

; Close the search handle
FileClose($search)

mmdoogie

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 14
    • View Profile
    • My Projects
    • Donate to Member
Re: IDEA: MoveAllTo C:\olddata
« Reply #7 on: February 23, 2007, 08:34 PM »
When you physically move a folder from one location to another on the same partition,
there is a very simple operation that can be performed by Windows to effect the move,
and this is what Windows Explorer uses to make the quick change.

Making a copy, or moving to a different drive or partition causes Windows to have to physically access every file,
making it a long process, and giving it many more problems.

So, your problem definitely needs to be attacked in the Move domain to get similar results.
There is an AutoIt3 command for DirMove which moves a directory, similar to how a file is moved,
so I think you will have to get a list of the directories in C:\ and move them one by one.

My guess then would be do do a loop like the one you use to do the verification, but instead get a list of all the items in C:\
Then, run both DirMove and FileMove on each item -- one of them will return failure, but that should be ok, as the other will succeed.

--matthew
« Last Edit: February 23, 2007, 08:43 PM by mmdoogie »