Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
Script Writing
LillyVanilli
Hi, I need help creating a script file to move files from one folder to another.
Basically i have a folder with 100000 docs in it, Folder 1, and I have a list of 50000 of those that need to be moved to different folder, Folder 2. I havent a clue how to write scripts so any help would be really appreciated.
Thanks
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
FruitLover
OS?
Language?
Differentiating criteria?
Help us to help you.
LillyVanilli
Oh sorry, see I told you I didnt have a clue. Windows 2003 server. I was hoping to run it from a command prompt is that possible? The differentiating criteria are the names of the files, does that make sense?
carveone
Is your list of files in text format? Like one file name per line? There are multiple different ways to do what you are asking - in vbscript, in shell batch or hell even in awk (if you download a version for windows). The reason I ask is that if the text file is complex - like CSV format (Excel) - then you'll have to take a bit more care in processing it before acting on the results.
LillyVanilli
I have the file in two formats, .txt & .csv. One file name per line
carveone
Easier than you think then.
for /F %i in (filelist.txt) do move "%i" "folder2"
Um. There might be issues with filenames with spaces in them so I'll go off now and try it out and get back to you!
LillyVanilli
No spaces so that should be fine, Ill try it now. Thanks a million
carveone
Oh yeah! There are definately issues with spaces!!
Ahem. Try again:
for /F "delims=:" %i in (filelist.txt) do move "%i" "folder2"
That sets the token delimiter from a space/tab to a colon, which cannot appear in any valid filename. Solves the problem. Use the quoting I've shown to make sure that the move command doesn't get confused with spaced filenames. If you've any doubts, put the command "
@echo"
; in between the do and the move to see what command would be executed...
for /F "delims=:" %i in (filelist.txt) do
@echo
move "%i" "folder2"
Hell you could then redirect this to a batch file like this
for /F "delims=:" %i in (filelist.txt) do
@echo
move "%i" "folder2" > go.bat
and then type
go
to process the whole list....
Edit: Oh yeah, of course all this is at a cmd prompt (Start/Run/cmd.exe) and in the right directory!
LillyVanilli
Yeah ive no spaces in the file names so it works perfectly.
Thanks a million, much quicker than trying to move thousands of files manually.
Cheers