Needs to be a simple script anyone with XP/Vista/7 can run (no PE or Powershell).
I need to move a random amount of files (eg. 1-15), and also similarly named folders (which are in a different location), to their own folder at the same time. 30 files and 30 folders to choose from:
C:\game\store\XMLs -> C:\game\mod\0.1.2\map\data
map01_aaa.xml
map02_bbb.xml
map03_ccc.xml
...
map60_zzz.xml
C:\game\store\models -> C:\game\mod\0.1.2\sky\stuff
01_aaa_map
02_bbb_map
03_ccc_map
...
60_zzz_map
Hope that makes sense if not I’ll go to sleep and try again tomorrow. I read about a dozen questions related to moving random files thoroughly (such as this one), few hours of google, and reading robvanderwoude.com, I’m not very experienced. If anyone has any suggestions of what to do, what to read, or can give an example I can work off of to accomplish this, I’d appreciate it.
Edit: Here is the code I have so far, updated with the answer from jimhark:
@ECHO OFF & setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
SET SrcCount=0
SET SrcMax=15
FOR %%F IN (C:\game\mod\store\XMLs\*.*) DO IF !SrcCount! LSS %SrcMax% (
SET /A SrcCount += 1
ECHO !SrcCount! COPY %F C:\game\mod\0.1.2\map\data\
COPY %%F C:\game\mod\0.1.2\map\data\
SET FNAME=%%~nF
XCOPY /s "C:\game\mod\store\models\!FNAME:~3!" "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
)
It’s not randomly selecting files though, even with %RANDOM%%%15, it always moves the first 8 files for example. Also the code to move the folders doesn’t work, it will only move the files.
It would really help if you posted the .bat code you have working. Without that all I can say, based on the code you linked to, is you probably need to add something like:
First add this near the top:
Then (and I didn’t rewrite the old code, but the 2 new lines at the end should be what you need):
Update 1
Here’s my file system before:
Here it is after:
And here’s the output:
The code is working on my machine. I don’t know how I can be of more help.
Update 2
It’s a substring operation, it drops the first three characters.
We start out with something like
Map01_aaa.xmlin %%F:Pulls out just the file name,
Map01_aaa. Then:Drops the first 3 characters for
01_aaa, which you indicated was the needed directory name.Update 3
Then change:
To: