FG

Powershell: Get inital character string from file name and create directory from string, then move files

Fresh3 days ago
Mar 15, 202627703 views
Confidence Score0%
0%

Problem

I have a folder with the following file names: Each file begins with a 9 character string that is a unique identifier. I would like to be able to pars trhouhg these folders for each file and based on the 9 character prefix, create a folder with the prefix name, then move the files to the newly crea…

Error Output

00150005D201110172338427995.vpf
00150005D201110180005318058.vpf
00150013D201110180014448082.vpf
00150013D201110180022268098.vpf
00150013D201110180056…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Powershell: Get inital character string from file name and create directory from string, then move files

Low Risk

This script should do the job: Explanation: foreach file in the directory (% is an alias for foreach): Get the id from the first 9 characters. Note that the $_ variable is an automatic variable populated by powershell that represents the current fil…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment