Move files from one folder to another

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 12 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
operez
Posts: 14
Last visit: Fri Mar 08, 2013 5:56 am

Move files from one folder to another

Post by operez »


I need to move files from one folder to another, but I want to check to see if the file already exist in the new folder and if it does, I want to rename the file before I move it, so that I have all copies of that file.
I plan on moving each file to a folder name based on the file's extension.

All PDFs into a folder named PDF, all DOCs into a folder named DOC, etc.

I already have a vbscript to list all of the files in a folder and all its subfolders, just need to create a function to move the files and create the subfolder if it doesn't already exist.
Can someone please help me or direct me to an example?
User avatar
operez
Posts: 14
Last visit: Fri Mar 08, 2013 5:56 am

Move files from one folder to another

Post by operez »


I need to move files from one folder to another, but I want to check to see if the file already exist in the new folder and if it does, I want to rename the file before I move it, so that I have all copies of that file.
I plan on moving each file to a folder name based on the file's extension.

All PDFs into a folder named PDF, all DOCs into a folder named DOC, etc.

I already have a vbscript to list all of the files in a folder and all its subfolders, just need to create a function to move the files and create the subfolder if it doesn't already exist.
Can someone please help me or direct me to an example?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Move files from one folder to another

Post by jvierra »

Look into the Scripting.FileSystemObject. It can get you all of the pieces you need to determine the extension of teh file name and the exitence of files and folders.
http://msdn.microsoft.com/en-us/library ... s.71).aspx

Consider using PowerShell as it is better at doing this.



jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Move files from one folder to another

Post by jvierra »

To rename a file withthe FSO use the MoveFIle method or the Move method of the file object.

User avatar
operez
Posts: 14
Last visit: Fri Mar 08, 2013 5:56 am

Move files from one folder to another

Post by operez »

Thanks jvierra, I have the FileExist and Move down, it's the logic to check if I already have a renamed file in the Target folder and figuring out the version number so that I can increment the file number.

Example, if FileName(4).ext already exit, rename the next one FileName(5).ext

Hope someone can help me out.
This topic is 12 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked