Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:42:08+00:00 2026-06-17T16:42:08+00:00

Needs to be a simple script anyone with XP/Vista/7 can run (no PE or

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:42:09+00:00Added an answer on June 17, 2026 at 4:42 pm

    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:

    setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
    

    Then (and I didn’t rewrite the old code, but the 2 new lines at the end should be what you need):

    FOR %F IN (C:\temp\source\*.*) DO IF !SrcCount! LSS %SrcMax% (
        SET /A SrcCount += 1
        ECHO !SrcCount! COPY %F C:\temp\output
        COPY %F C:\temp\output
    
        rem ** Here are the new lines **
    
        SET FNAME=%%~nF
        XCOPY /s "C:\game\store\0.1.2\sky\stuff\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
    )
    

    Update 1

    rem @ECHO OFF
    setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
    SET SrcCount=0
    SET SrcMax=15
    
    IF NOT EXIST C:\game\mod\0.1.2\map\data md C:\game\mod\0.1.2\map\data
    IF NOT EXIST C:\game\mod\0.1.2\sky\stuff md C:\game\mod\0.1.2\sky\stuff
    
    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
      ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
      XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
    )
    

    Here’s my file system before:

    C:\game>dir /s /b
    C:\game\mod
    C:\game\mod\store
    C:\game\mod\store\models
    C:\game\mod\store\XMLs
    C:\game\mod\store\models\01_aaa
    C:\game\mod\store\models\01_aaa\test.txt
    C:\game\mod\store\XMLs\Map01_aaa.xml
    

    Here it is after:

    C:\game>dir /s /b
    C:\game\mod
    C:\game\mod\0.1.2
    C:\game\mod\store
    C:\game\mod\0.1.2\map
    C:\game\mod\0.1.2\sky
    C:\game\mod\0.1.2\map\data
    C:\game\mod\0.1.2\map\data\Map01_aaa.xml
    C:\game\mod\0.1.2\sky\stuff
    C:\game\mod\0.1.2\sky\stuff\01_aaa
    C:\game\mod\0.1.2\sky\stuff\01_aaa\test.txt
    C:\game\mod\store\models
    C:\game\mod\store\XMLs
    C:\game\mod\store\models\01_aaa
    C:\game\mod\store\models\01_aaa\test.txt
    C:\game\mod\store\XMLs\Map01_aaa.xml
    

    And here’s the output:

    D:\bat>docopy.bat
    
    D:\bat>rem @ECHO OFF
    D:\bat>setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
    D:\bat>SET SrcCount=0
    D:\bat>SET SrcMax=15
    D:\bat>IF NOT EXIST C:\game\mod\0.1.2\map\data md C:\game\mod\0.1.2\map\data
    D:\bat>IF NOT EXIST C:\game\mod\0.1.2\sky\stuff md C:\game\mod\0.1.2\sky\stuff
    
    D:\bat>FOR %F IN (C:\game\mod\store\XMLs\*.*) DO IF !SrcCount! LSS 15 (
    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
     ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
     XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
    )
    
    D:\bat>IF !SrcCount! LSS 15 (
    SET /A SrcCount += 1
     ECHO !SrcCount! COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
     COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
     SET FNAME=Map01_aaa
     ECHO XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
     XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
    )
    
    1 COPY C:\game\mod\store\XMLs\Map01_aaa.xml C:\game\mod\0.1.2\map\data\
            1 file(s) copied.
    XCOPY /s "C:\game\mod\store\models\01_aaa"  "C:\game\mod\0.1.2\sky\stuff\01_aaa\"
    C:\game\mod\store\models\01_aaa\test.txt
    1 File(s) copied
    
    D:\bat>c:
    
    C:\game>dir /s /b
    

    The code is working on my machine. I don’t know how I can be of more help.

    Update 2

    What does !FNAME:~3! mean, particularly, ~3?

    It’s a substring operation, it drops the first three characters.

    We start out with something like Map01_aaa.xml in %%F:

    SET FNAME=%%~nF
    

    Pulls out just the file name, Map01_aaa. Then:

    !FNAME:~3!
    

    Drops the first 3 characters for 01_aaa, which you indicated was the needed directory name.

    C:\>set test=abcdef
    c:\>echo !test:~3!
    def
    
    set /?
    
    May also specify substrings for an expansion.
    
    %PATH:~10,5%
    
    would expand the PATH environment variable, and then use only the 5
    characters that begin at the 11th (offset 10) character of the expanded
    result.
    

    Update 3

    And my bad, the folder name is actually 01_aaa_map and so on.

    Then change:

    XCOPY /s "C:\game\mod\store\models\!FNAME:~3!"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!\"
    

    To:

    XCOPY /s "C:\game\mod\store\models\!FNAME:~3!_map"  "C:\game\mod\0.1.2\sky\stuff\!FNAME:~3!_map\"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a simple script to run in Windows that searches large xml files
I need a simple proxy PHP function/script that can download a file from a
I need to run a simple script after the modules and programs have been
I need the most simple auction script you can imagine. I dont need categories,
I need a very basic, simple and lightweight AJAX script. Does anyone have a
Pretty simple: I need a script that reads the element ij of TWO images
I have simple table creating script in Postgres 9.1. I need it to create
I'm writing a simple EC2 snapshot script and need to determine if there is
Our application needs a simple scheduling mechanism - we can schedule only one visit
I need to develop a very simple class developed as a Windows Script Component

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.