FSO For function not looping

August 6, 2015 at 08:40:55
Specs: Windows 64
I used this very helpful script and made some minor changes but now it processes only one file and stops. Any idea what's going on? Here's the new code:

Option Explicit
Dim objFSO,srcRoot,objFolder,File,dstRoot,theName,dst,dstFile,savelen
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder=objFSO.GetFolder(srcRoot)
For Each File In objFolder.Files
If objFSO.GetExtensionName(File) = "mp4" Then
savelen = Len(File.Name)
theName= Left(File.Name,savelen - 4)
dst=dstRoot & "\" & theName
dstFile=dst & "\" & File.Name
If Not objFSO.FolderExists(dst) Then
End If
objFSO.MoveFile File, dstFile
End If

See More: FSO For function not looping

Report •

August 6, 2015 at 23:30:43
I tried this on my win-XP 32-bit and it worked fine. Trust NOTHING on 64-bit unless it is advertised as such, but that may not be the problem. As an alternative, here's a batch script that also worked ok:
::------------ begin batchscript
@echo off & setlocal
set dest=z:\somewhere
set src=c:\nowhere
pushd %src%
for %%a in (*.mp4) do (
md %dest%\%%~na 2>nul
move %%a %dest%\%%~na

::===== end script
the only other thing is if the "Move" is corrupting the directory in real-time. If that is the case, try using "Copy" or "Copyfile" instead, then at the end of the script, issue a blanket deletion of all mp4 files at the source location.

Report •

August 8, 2015 at 11:22:14
Must be the 64 bit Windows 10. Almost appears to be a timing issue. I tried changing my script to use copy instead of move but no dice. Then i moved the folder to the same drive so the files wouldn't have to move across my network. Most moved fine while others had to be done manually... I tried your script but it seemed to freak out because of long file names with spaces and created a bunch of empty folders in the source directory. This is just so weird. I never remember having problems like this in the past doing such simple file tasks.

Report •

Related Solutions

Ask Question