Solved How to set a file size for all individual files at once?

April 22, 2014 at 18:10:53
Specs: Windows 7
Hello, is there a way to assign every file in a folder a variable based on the file's size with one command rather than using the below command and using it for every single file in the folder.:

FOR /F "usebackq" %%A IN ('%vare1%') DO set svare1=%%~zA


See More: How to set a file size for all individual files at once?

Report •

✔ Best Answer
May 3, 2014 at 17:41:46
for /f %%a in ('dir /b /s /a-d') do set v%%~pnxa1=%%~za

This will remove the drive letter (the colon messes up the variable).
Now your vars should look like: v\\s\s\b2.jpg1

Well, I still messed up my post. Edited to fix the above. Thanks and good luck.

message edited by nbrane



#1
April 22, 2014 at 22:57:44
for %%a in (.) do set %%a1=%%~za

?


Report •

#2
April 23, 2014 at 03:40:44
Why do you ignore YOUR OWN threads, miss any feedback and duplicate your questions? See the following:

http://www.computing.net/answers/wi...


Report •

#3
April 23, 2014 at 06:39:54
Better question: Why would you even want to do that? CMD variables are stored in the environment, and they're passed along to any child programs you spawn. I also can't imagine why you'd need all sizes at all times.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
April 23, 2014 at 17:39:20
Sorry my computer hard drive died so I had lost track of my files and what I was doing. I will keep track from now and remove any duplicates

Report •

#5
April 26, 2014 at 13:39:17
I was using that for comparing different files just like the comp.exe and fc.exe commands, but those 2 commands i think dont work with "if not" or findstr commands

Report •

#6
April 26, 2014 at 21:05:46
I'm still confused (as usual). Maybe if the problem were better defined? Like (f/e):
1) for every set of files having the same sizes, (?) (look for most recent date? spill the fc output? put all into a "working" subdir?)
2) unique (sized) files? what to do with these?
Generally speaking, I would sort the files by size into a text file, then go from there.
In short, what exactly are you trying to do? I'm sure someone here can help, but not without sufficient background briefing.

Report •

#7
April 27, 2014 at 10:53:12
Typing dir/s >a.txt will put the following contents into a.txt

Volume in Drive E:\ is comp
Volume Serial Number is CGDF- BSAD
Directory of E:\off


04/25/2014 3:16 pm <DIR>
03/26/2014 7:26 pm <DIR>
04/26/2014 7:26 pm 2,840,252 wed.docx
05/26/2013 2:46 pm 1,340,243 win.docx
04/26/2011 3:43 am 4,880,653 exc.doxc
02/26/2011 4:16 pm 2,280,752 cft.docx
03/26/2012 5:47 pm 2,670,353 asd.docx


Now all I want is a quick method to take row 3 in a txt which is the file size and put it in a seperate txt file so that i can set them as variables.

Using: FOR /F "usebackq" %%A IN ('%vare1%') DO set svare1=%%~zA
would solve this but it would take hrs if there are lots of files

Using for %%a in (.) do set %%a1=%%~za as Nbrane had suggested will result in the entire size of the folder

So, just looking for method like the 1st one but one that would do the job with just one command rather that entering that line for every single filename

In short, would it be possible to alter a.txt to just display only the 3rd row?


Report •

#8
April 27, 2014 at 12:53:36
ssnader: Now all I want is a quick method to take row 3 in a txt which is the file size and put it in a seperate txt file so that i can set them as variables.
This reeks of not properly planing out your workflow, so I'll ask again. Why would you want to do this? From a batch perspective, it earns you nothing.

How To Ask Questions The Smart Way


Report •

#9
April 27, 2014 at 20:08:42
I use this batch to record my file's stats (size, date, fullpath):
@echo off & setlocal
dir /a-d /b /s > allfilz
(for /f "tokens=*" %%a in (%out%filz) do echo %%~za*%%~ta %%a)>allfiles

sample output:
2733*04/01/2014 06:40 PM C:\test\data.txt

This gives me easy access to either of the three stats: the asterisk separates size from date, the date is three space-delim items, then everything else is fullpath and filename. When I sort this output, it gives me the files in order of size so I can group them for comparison. Any simple batch can re-configure this data for different analytical purposes. The following program lets me analyze my system for differences occuring in the files (files added, removed and/or size/date changed):
'DIF.BAS
'aaf is the sorted listing of the files at some earlier date, nnf is the 'sorted list of current files. I removed "content.ie5" (cache files) 'to make the output relevant.
OPEN "aaf" FOR INPUT AS #1
OPEN "nnf" FOR INPUT AS #2
OPEN "added" FOR OUTPUT AS #3
OPEN "removed" FOR OUTPUT AS #4
C = 0: M$ = "": K$ = ""
XX:
C = C + 1
IF M$ = K$ THEN
IF EOF(1) THEN PRINT "EOF AAF "; C
IF EOF(2) THEN PRINT "EOF NNF "; C
IF EOF(1) OR EOF(2) THEN CLOSE : STOP
LINE INPUT #1, K$
LINE INPUT #2, M$
GOTO XX
END IF
10
IF M$ < K$ THEN
PRINT #3, M$
IF EOF(2) THEN PRINT "EOF NNF "; C: CLOSE : STOP
LINE INPUT #2, M$
GOTO XX
END IF
IF EOF(1) THEN PRINT "EOF AAF "; C: CLOSE : STOP
PRINT #4,K$
LINE INPUT #1, K$
GOTO XX
'==== end DIF.BAS
I believe this could be converted to vbscript without difficulty.
ps: yeh, i messed up in my earlier post - neglected to test. The following would have worked:
for /f %%a in ('dir /b /a-d') do set v%%a1=%%~za

message edited by nbrane


Report •

#10
May 3, 2014 at 09:47:16
This is definetely what I was looking for. One last follow up question on the command:

for /f %%a in ('dir /b /a-d') do set v%%a1=%%~za
I got a folder with the contents:
c:\s\b1.jpg
c:\s\s\b2.jpg

When I run the batch command from the folder c:\s, b1.jpg does get set as a variable when i type: echo %vb1.jpg1%
but suppose I want to set the subfolder contents also as variables, i added a /s command to the batch such as :

for /f %%a in ('dir /b /s /a-d') do set v%%a1=%%~za

Doing this for some reason stops making the varible being set:
Typing echo %vb1.jpg1% now gives me an empty variable result such as:

echo
echo is off

And typing %vc:\s\s\b2.jpg1% doesnt give any result either for the subfolder contents.

How can this be fixed? Thanks

message edited by ssnader


Report •

#11
May 3, 2014 at 17:41:46
✔ Best Answer
for /f %%a in ('dir /b /s /a-d') do set v%%~pnxa1=%%~za

This will remove the drive letter (the colon messes up the variable).
Now your vars should look like: v\\s\s\b2.jpg1

Well, I still messed up my post. Edited to fix the above. Thanks and good luck.

message edited by nbrane


Report •

#12
May 3, 2014 at 18:45:40
Wow, it actually worked. Im finally finished wondering on how to solve this issue. Thank you so much, your knowledge on this topic is amazing.

Report •

Ask Question