Parsing Folder with File Size?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Parsing Folder with File Size?

Post by ueberyak » Tue Jan 27, 2015 9:57 pm

I have the following code, which I can get to do one of two things:

Return network addresses all folders, subfolders and files within oDirectory.

OR

Return the file sizes for all folders, subfolders and files within oDirectory (See the two commented out lines in the Repeat section.)

What I want, though, is to have the network address AND the file size in a single line, e.g. "NetworkLocation - FileSize". Whenever I try this, it seems like files_%f% can only be used once, which is confusing.

Code: Select all

let>oDirectory=\\data\shares\Folder\

IfNotDirExists>C:\Users\%USER_NAME%\Documents\FileListing
    CreateDir>C:\Users\%USER_NAME%\Documents\FileListing\
EndIf

Length>%oDirectory%,LenDirectory

if>%LenDirectory%=0
    MDL>Process Cancelled
    Exit>
Endif

Year>YYYY
Month>MM
Day>DD
Hour>HH
Min>MM

StringReplace>%oDirectory%,\\,,oFileName
StringReplace>%oFileName%,\,_,oFileName
let>oFileName=%oFileName%_FileList_%YYYY%_%MM%_%DD%_%HH%_%MM%.txt

Let>RP_WINDOWMODE=2
Let>RP_WAIT=1
Run>cmd /c dir %oDirectory%* /s /b > %TEMP_DIR%~temp_dir_list~
ReadFile>%TEMP_DIR%~temp_dir_list~,dir_list


Separate>dir_list,CRLF,files
If>files_count>0
Let>f=0
Repeat>f
  Let>f=f+1
  //do something with this_file
  //FileSize>files_%f%,oFileSize
  //WriteLn>C:\Users\%USER_NAME%\Documents\FileListing\%oFileName%,,%oFileSize%
  WriteLn>C:\Users\%USER_NAME%\Documents\FileListing\%oFileName%,,files_%f%
Until>f=files_count
Thanks,
Josh

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Parsing Folder with File Size?

Post by JRL » Wed Jan 28, 2015 3:37 am

Most functions cannot accept a variable in the form Files_%f%. the Let> function will. So it is common practice to have a line of code in the loop where you use Let> to create a variable to pass to other functions.

Code: Select all

Let>f=0
Repeat>f
  Let>f=f+1
  Let>value=files_%f%
  //do something with this_file
  FileSize>value,oFileSize
  //WriteLn>C:\Users\%USER_NAME%\Documents\FileListing\%oFileName%,,%oFileSize%
  WriteLn>C:\Users\%USER_NAME%\Documents\FileListing\%oFileName%,,%value%  -  %oFileSize%
Until>f=files_count

ueberyak
Junior Coder
Posts: 31
Joined: Tue Sep 03, 2013 9:45 pm

Re: Parsing Folder with File Size?

Post by ueberyak » Wed Jan 28, 2015 4:34 pm

That did it! You're the best!
Thanks,
Josh

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts