![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Move file to folder depending on last two characters of filename I need to write a script that looks through a folder and finds the last two characters of every filename in that folder , and then moves them over to a folder structure which corresponds to those last two digits. For example I could have two files called abcdefg23 qwerty56 I would then run the script and the two files would be placed in the relevant folders IE abcdefg23 would be placed in a folder called 23 and qwerty56 would be placed in a folder called 56 There is no need to create the folders 23 and 56 as these would already exist in a folder structure. Anyone have any ideas of how I can script this rather than have to do this manually as there are 100's of files I need to do this for. Any help would be much appreciated. Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Move file to folder depending on last two characters of filename "Oli M" <OliM@xxxxxx> wrote in message news:0FE663F5-9729-46E8-9E81-6FA7ED31B2B5@xxxxxx Quote: >I need to write a script that looks through a folder and finds the last two > characters of every filename in that folder , and then moves them over to > a > folder structure which corresponds to those last two digits. For example > > I could have two files called > abcdefg23 > qwerty56 > > I would then run the script and the two files would be placed in the > relevant folders > > IE abcdefg23 would be placed in a folder called 23 and > qwerty56 would be placed in a folder called 56 > > There is no need to create the folders 23 and 56 as these would already > exist in a folder structure. > > Anyone have any ideas of how I can script this rather than have to do this > manually as there are 100's of files I need to do this for. > > Any help would be much appreciated. > > Thanks When you write that you have two files called abcdefg23 qwerty56 then you probably mean something like this instead: abcdefg23.mp3 qwerty56.mp3 I think it would be a useful exercise for you to adapt the code below so that it can cope with the actual file names you have instead of the original task specification that you posted. sSource = "d:\Mon\" sTarget = "d:\Tue\" Set oFSO = CreateObject("Scripting.FileSystemObject") Set oSource = oFSO.GetFolder(sSource) For Each oFile In oSource.Files sSuffix = Right(oFile.Name, 2) & "\" oFSO.MoveFile oFile.Path, sTarget & sSuffix & oFile.Name MsgBox "Moved " & oFile.Path & " to " & sTarget & sSuffix Next To test the code, do this: 1. Run the program. 2. Examine the message box that pops up. 3. Check if the program did what you expected. 4. Click OK. 5. Repeat Steps 2 to 4 a few times. 6. When you're satisified that everything is as it should be, remove the MsgBox line from the code, then save the code and run it again. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Move file to folder depending on last two characters of filena This code appears to error at line 7 character 1 path not found. Not too sure about the syntax that is being used so unable to find out how to resolve |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Move file to folder depending on last two characters of filename "Oli M" <OliM@xxxxxx> wrote in message news:CEE4FE8A-F845-44F3-BF5E-042084B566F4@xxxxxx Quote: > This code appears to error at line 7 character 1 path not found. > > Not too sure about the syntax that is being used so unable to find out how > to resolve the code do not exist, perhaps because of the file extension problem I pointed out in my first reply. You must make sure that all names in the code agree with the names that exist on the disk. The pop-up box I included gives you the actual names - check them carefully! |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| I want to move my Offline File Folder | Vista file management | |||
| VBScript to move file in one folder to many folder | VB Script | |||
| Capture a string of characters and use as filename. | PowerShell | |||
| Create New folder, move file, delete file. Explorer Freeze | General Discussion | |||
| Creating folder based on filename of a file | PowerShell | |||