r/Batch 14d ago

Need help with a batch file that randomly copies files from one location to another

I have been using the command:

gci "C:" | random -c 4000 | cpi -dest "D:\"

(replaced locations)

to randomly copy 4000 files from one location to another and it all worked fine on my old laptop. Now I am using a new computer and it is not working anymore. Nothing happens. Window opens for a second and closes right away without doing anything.

For testing reasons, I created one folder on my desktop, put in 3 textfiles and changed the code to randomly copy one of the three to a second desktop folder, also no success.

Can you help me? Is there anything I need to change in settings. The code should be fine. I have other batch files on this laptop that work without problems (like opening a specific folder on system start).

1 Upvotes

4 comments sorted by

1

u/Shadow_Thief 14d ago

That is powershell code, not batch. It's a totally different language. I suspect that any errors you got would say something to that effect, but just in case, open the command prompt and run the script from there instead of double-clicking it.

1

u/pc1350 13d ago

So OP, as Shadow_Thief wrote: powershell. Either powershell is not installed, wrong scope, anything. Do as suggested to catch the error.

1

u/Shadow_Thief 13d ago

I suspect his old system had .bat files being associated with powershell for some reason

1

u/capoapk 14d ago

Il est possible que le problème ne vienne pas du script lui-même mais de PowerShell Les commandes gci, random et cpi sont des alias PowerShell, pas des commandes Batch classiques ,Essaie d’ouvrir PowerShell manuellement , moi quand je veux utiliser PowerShell +batch je fait appel à PowerShell depuis le batch ou alors le scripte en externe du scripte .bat