Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Move and rename a lot of files

$
0
0

I need to do a daily sweep of a folder to see if any file(s) have been put into it.  If there is a file I need to move it to another location and add the current date and time to the original file name.

 

I know how to use ..

 

get-ChildItem E:\DATADUMP –Recurse

 

To pull the file names and directories to a text file (or variable)

I know how to move an item while at the same time changing its name

 

$RUN = "NEW_FILE_NAME_"

$MONTH = Get-Date -format MMMM

$YEAR = Get-Date -format yyyy

$DAY = Get-Date -format dd

$D = "_"

$DMY = "$RUN$MONTH$D$DAY$D$YEAR"

Copy-Item E:\DATADUMP E:\DIFFRENT_LOCATION\$DMY.txt

 

[Returns a file called [NEW_FILE_NAME_January_25_2014.txt]

 

The problem is that this changes the extension to “.txt” and fully renames the file.  I will be getting files of all types and I simply need to move them to a different folder and add the date and time to them while keeping the rest of the original file name and extension.

For example if I got the file

Test001.doc

I would want it be moved from the original folder to the different folder and be called

January_25_2014_102am_Test001.doc

(The original Test001.doc file would no longer be in the E:\DATADUMP folder)

 

There may or may not be a file extension and if there is not a file extension there may or may not be a period are the end of the file name.  Also there may or may not be any file in the E:\DATADUMP folder at any given running of the script or there may be a lot of files. 

 

Any help would be huge, I feel like I keep going down rabbit holes and it is time to ask for help.

 

Thank you, -Dan

 

 

 

 


Viewing all articles
Browse latest Browse all 8583

Latest Images

Trending Articles



Latest Images