• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 81
  • Last Modified:

Expanding a file size only descriptively

We need to create a series of files with over 1gb size for a project we  have.  We use fsutil and it works; the problem is that it affect the "free space" when querying the disk size.  Is there a waye to do this?
0
rayluvs
Asked:
rayluvs
  • 3
  • 3
2 Solutions
 
Bill PrewCommented:
No, I don't believe there is any way to "define" a file in the Windows file system without allocating the associate size of space.  Certainly not without hacking the NTFS file system catalog, and I wouldn't recommend that, too easy for bad side effects to occur.

Depending on what your need is - I'm assuming you aren't going to write to these fake files - you might be able to allocate one real file and then use symbolic links for the other files to reference the same space as the first file.


»bp
2
 
rayluvsAuthor Commented:
Understood.  So what is the next best thing in order to create a file without actually creating it's content?
0
 
Bill PrewCommented:
I had created a small C language utility back when dinosaurs roamed the earth, but the original EXE doesn't work on Windows 64-bit.  It was lightening fast at allocating a large file on disk (and reserving the space) without writing real data to the file.  If you have a C compiler you can compile it.  Or if you want I'm happy to compile it here and get you  the EXE, but I didn't want to lead with that as people can be leery of EXE's from unknown sources, as they should be.

It might be possible to duplicate the approach here in Powershell using .Net System.IO.FileStream but I haven't played around with that.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
 
main(int argc, char *argv[])
{
  FILE *fp;
  long i;
  
  i = atol (argv[2]);
  i--;
 
  if (argc < 3)
  {
    printf("USAGE:  ALLOCATE filename size");
    exit(1);
  }
 
  if ((fp = fopen (argv[1], "wb")) == NULL)
    {
    perror ("Error opening output file!");
    exit (1);
    }

  if (fseek (fp, i, SEEK_SET))
    {
    perror ("Error positioning output file!");
    exit (1);
    }

  if (fputc (NULL, fp) == EOF)
    {
    perror ("Error writing to output file!");
    exit (1);
    }

  if (fclose (fp) == EOF)
    {
    perror ("Error closing output file!");
    exit (1);
    }

  exit (0);
}

Open in new window


»bp
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rayluvsAuthor Commented:
Hi!

Thank you very much!

Did find a solution: FUTILS

Super fast no matter the size, but it stills allocate.

FYI:
      Format:
      fsutil    file    createnew    FileName    FIleSizeWanted


Thank you for your support!
0
 
Bill PrewCommented:
Ah yes, good point, I had found that a while ago when needing something like this, and forgotten.


»bp
0
 
rayluvsAuthor Commented:
Thank you very much for your assistance.

We chose our entry since it solved the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now